@myclaw163/clawclaw-cli 0.10.3 → 0.10.5
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 +2 -0
- package/docs/custom-modules/perception.md +2 -0
- package/docs/custom-modules/skill.md +8 -0
- package/docs/user-guide/desktop-auth.md +45 -0
- package/docs/user-guide/perception.md +2 -0
- package/docs/user-guide/skill.md +8 -0
- package/package.json +1 -1
- package/skills/clawclaw/SKILL.md +8 -3
- package/skills/clawclaw/references/COMMANDS.md +2 -2
- package/skills/clawclaw/references/GAME-MECHANICS.md +34 -49
- package/src/cli.ts +2 -0
- package/src/commands/account.ts +12 -3
- package/src/commands/auth.ts +133 -0
- package/src/commands/behavior.ts +2 -1
- package/src/commands/capability.ts +4 -1
- package/src/commands/communication.ts +2 -1
- package/src/commands/data.ts +2 -1
- package/src/commands/events.ts +2 -1
- package/src/commands/load.ts +8 -3
- package/src/commands/memory.ts +2 -1
- package/src/commands/module-runtime-control.ts +2 -1
- package/src/commands/perception.ts +2 -1
- package/src/commands/persona.ts +2 -1
- package/src/lib/account-guidance.ts +5 -0
- package/src/lib/agent-workspace-skills.ts +93 -10
- package/src/lib/auth.ts +8 -1
- package/src/lib/capability-cloud-refresh.ts +3 -0
- package/src/lib/capability-cloud-sync.ts +7 -1
- package/src/lib/capability-selection.ts +8 -0
- package/src/lib/desktop-auth.ts +40 -0
- package/src/lib/desktop-mode.ts +9 -0
- package/src/lib/game-client.ts +2 -1
- package/src/lib/hub-client.ts +2 -1
- package/src/lib/load-context.ts +2 -1
- package/src/lib/persona.ts +2 -1
- package/src/lib/skill-host.ts +10 -0
- package/src/lib/skill-name-conflicts.ts +110 -0
- package/src/pipeline/event-format.ts +6 -0
- package/src/runtime/clawclaw/agent-event-policy.ts +1 -0
- package/src/runtime/clawclaw/behavior-start-control.ts +79 -0
- package/src/runtime/clawclaw/owner-lock.ts +5 -1
- package/src/runtime/clawclaw/owner.ts +8 -21
- package/src/runtime/clawclaw/plugins/system-perception/sabotage-availability-rule.ts +53 -0
- package/src/runtime/clawclaw/plugins/system-perception/system-perceptions.ts +2 -1
- package/src/runtime/clawclaw-event-catalog.ts +1 -0
package/src/commands/load.ts
CHANGED
|
@@ -42,7 +42,8 @@ import {
|
|
|
42
42
|
type AgentWorkspaceSyncResult,
|
|
43
43
|
type LocalAgentWorkspaceSnapshot,
|
|
44
44
|
} from '../lib/agent-workspace-sync.js';
|
|
45
|
-
import { syncAgentWorkspaceSkills } from '../lib/agent-workspace-skills.js';
|
|
45
|
+
import { inspectSkillNameConflicts, syncAgentWorkspaceSkills } from '../lib/agent-workspace-skills.js';
|
|
46
|
+
import { skillConflictNames, skillNameKey } from '../lib/skill-name-conflicts.js';
|
|
46
47
|
import {
|
|
47
48
|
listAgentWorkspaceBehaviorSources,
|
|
48
49
|
listAgentWorkspacePerceptionSources,
|
|
@@ -210,7 +211,7 @@ function compactCapabilityWarning(warning: CapabilityLoadWarning): Record<string
|
|
|
210
211
|
}
|
|
211
212
|
|
|
212
213
|
function compactSkillChanges(changes: ReturnType<typeof syncAgentWorkspaceSkills>) {
|
|
213
|
-
const keys = ['added', 'updated', 'removed', 'preservedModified', 'failed', 'skipped'] as const;
|
|
214
|
+
const keys = ['added', 'updated', 'removed', 'preservedModified', 'failed', 'skipped', 'conflicts'] as const;
|
|
214
215
|
const value = Object.fromEntries(keys.flatMap((key) => (
|
|
215
216
|
!changes[key]?.length ? [] : [[key, changes[key]]]
|
|
216
217
|
)));
|
|
@@ -717,6 +718,7 @@ export function createLoadCommand(dependencies: LoadCommandDependencies = {}): C
|
|
|
717
718
|
: {
|
|
718
719
|
added: [], updated: [], removed: [], unchanged: [], failed: [],
|
|
719
720
|
preservedModified: [],
|
|
721
|
+
conflicts: inspectSkillNameConflicts(workspaceDir, profile),
|
|
720
722
|
requiresUserConfirmation: false,
|
|
721
723
|
};
|
|
722
724
|
const hubPersonaItem = activeWorkspace?.items.persona[0];
|
|
@@ -916,10 +918,13 @@ export function createLoadCommand(dependencies: LoadCommandDependencies = {}): C
|
|
|
916
918
|
unchanged: cloudChanges?.unchanged ?? [],
|
|
917
919
|
} : undefined;
|
|
918
920
|
const selectionRequired = pendingCapabilitySelections(workspaceDir, profile);
|
|
921
|
+
const blockedSkillNames = skillConflictNames(skillChanges.conflicts ?? []);
|
|
919
922
|
const skills = [...new Set(Object.values(readCapabilityWorkspaceRegistry(workspaceDir, profile).entries)
|
|
920
923
|
.filter((entry) => entry.type === 'skill' && entry.selection === 'equipped'
|
|
924
|
+
&& !blockedSkillNames.has(skillNameKey(entry.runtimeId))
|
|
921
925
|
&& !entry.hub?.cloudStatus && !isPackageManagedSkill(entry.runtimeId))
|
|
922
|
-
.map((entry) => entry.runtimeId)
|
|
926
|
+
.map((entry) => entry.runtimeId).concat((skillChanges.conflicts ?? [])
|
|
927
|
+
.flatMap(item => item.active ? [item.active.id ?? item.active.name] : [])))].sort();
|
|
923
928
|
console.log(JSON.stringify({
|
|
924
929
|
schema: LOAD_SCHEMA,
|
|
925
930
|
context: {
|
package/src/commands/memory.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { accountRequiredMessage } from '../lib/desktop-mode.js';
|
|
1
2
|
import { existsSync, writeFileSync } from 'fs';
|
|
2
3
|
import { Command } from 'commander';
|
|
3
4
|
import { AuthStore } from '../lib/auth.js';
|
|
@@ -6,7 +7,7 @@ import { loadMemorySnapshot } from '../lib/load-context.js';
|
|
|
6
7
|
|
|
7
8
|
function getMemoryFile(): string {
|
|
8
9
|
const profile = new AuthStore().getActive();
|
|
9
|
-
if (!profile) throw new Error('Not logged in.');
|
|
10
|
+
if (!profile) throw new Error(accountRequiredMessage('Not logged in.'));
|
|
10
11
|
return getProfileMemoryFile(profile);
|
|
11
12
|
}
|
|
12
13
|
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { accountRequiredMessage } from '../lib/desktop-mode.js';
|
|
1
2
|
import { AuthStore, type AuthProfile } from '../lib/auth.js';
|
|
2
3
|
import { InvalidArgumentError } from 'commander';
|
|
3
4
|
import { sendProfileOwnerControlRequest, type OwnerControlResponse, type OwnerControlType } from '../runtime/owner-control.js';
|
|
@@ -62,7 +63,7 @@ export async function runOwnerCommand(
|
|
|
62
63
|
source: 'local',
|
|
63
64
|
error: {
|
|
64
65
|
code: 'NO_ACTIVE_ACCOUNT',
|
|
65
|
-
message: 'No active account. Run `ccl account register` or switch accounts first.',
|
|
66
|
+
message: accountRequiredMessage('No active account. Run `ccl account register` or switch accounts first.'),
|
|
66
67
|
},
|
|
67
68
|
};
|
|
68
69
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { accountRequiredMessage } from '../lib/desktop-mode.js';
|
|
1
2
|
import { BUILTIN_PERCEPTION_NAMES } from '../runtime/clawclaw/plugins/system-perception/system-perceptions.js';
|
|
2
3
|
import { BUILTIN_PERCEPTION_PREFIX } from '../runtime/clawclaw/notification-policy.js';
|
|
3
4
|
import { runOwnerCommand, parseModuleInput, type ModuleRuntimeCommandDependencies } from './module-runtime-control.js';
|
|
@@ -30,7 +31,7 @@ export interface PerceptionCommandDependencies extends ModuleRuntimeCommandDepen
|
|
|
30
31
|
|
|
31
32
|
function activeProfile(dependencies: PerceptionCommandDependencies): AuthProfile {
|
|
32
33
|
const profile = (dependencies.activeProfile ?? (() => new AuthStore().getActive()))();
|
|
33
|
-
if (!profile) throw new Error('No active account. Run `ccl account register` or switch accounts first.');
|
|
34
|
+
if (!profile) throw new Error(accountRequiredMessage('No active account. Run `ccl account register` or switch accounts first.'));
|
|
34
35
|
return profile;
|
|
35
36
|
}
|
|
36
37
|
|
package/src/commands/persona.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { accountRequiredMessage } from '../lib/desktop-mode.js';
|
|
1
2
|
import { Command } from 'commander';
|
|
2
3
|
import { existsSync } from 'node:fs';
|
|
3
4
|
import { AuthStore } from '../lib/auth.js';
|
|
@@ -24,7 +25,7 @@ import { renameCapabilityOperationWhenIdle } from '../lib/capability-operation-r
|
|
|
24
25
|
|
|
25
26
|
function context() {
|
|
26
27
|
const profile = new AuthStore().getActive();
|
|
27
|
-
if (!profile) throw new Error('Not logged in.');
|
|
28
|
+
if (!profile) throw new Error(accountRequiredMessage('Not logged in.'));
|
|
28
29
|
const workspaceDir = getWorkspaceDir();
|
|
29
30
|
ensureAccountUserDataLayout(workspaceDir, profile);
|
|
30
31
|
return {
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { DESKTOP_LOGIN_MESSAGE, isDesktopMode } from './desktop-mode.js';
|
|
2
|
+
|
|
1
3
|
export const OFFICIAL_URL = 'https://myclaw.163.com/';
|
|
2
4
|
export const REGISTER_COMMAND = 'ccl account register [--name <name>] [--invite-code <code>]';
|
|
3
5
|
export const REGISTRATION_CHECK_COMMAND = 'ccl account register --check';
|
|
@@ -69,6 +71,7 @@ export function missingInviteCodeMessage(): string {
|
|
|
69
71
|
}
|
|
70
72
|
|
|
71
73
|
export function noAccountMessage(action: NoAccountAction): string {
|
|
74
|
+
if (isDesktopMode()) return DESKTOP_LOGIN_MESSAGE;
|
|
72
75
|
const firstLine = action === 'gameStart'
|
|
73
76
|
? 'Cannot start matchmaking: no local ClawClaw account is configured.'
|
|
74
77
|
: action === 'accountInfo'
|
|
@@ -82,6 +85,7 @@ export function noAccountMessage(action: NoAccountAction): string {
|
|
|
82
85
|
}
|
|
83
86
|
|
|
84
87
|
export function invalidAccountMessage(): string {
|
|
88
|
+
if (isDesktopMode()) return DESKTOP_LOGIN_MESSAGE;
|
|
85
89
|
return [
|
|
86
90
|
'Account not found or API key expired.',
|
|
87
91
|
REGISTRATION_PROMPT,
|
|
@@ -90,6 +94,7 @@ export function invalidAccountMessage(): string {
|
|
|
90
94
|
}
|
|
91
95
|
|
|
92
96
|
export function malformedApiKeyMessage(): string {
|
|
97
|
+
if (isDesktopMode()) return DESKTOP_LOGIN_MESSAGE;
|
|
93
98
|
return [
|
|
94
99
|
'API key is missing or malformed.',
|
|
95
100
|
REGISTRATION_PROMPT,
|
|
@@ -4,12 +4,13 @@ import {
|
|
|
4
4
|
lstatSync,
|
|
5
5
|
mkdirSync,
|
|
6
6
|
readFileSync,
|
|
7
|
+
realpathSync,
|
|
7
8
|
readdirSync,
|
|
8
9
|
renameSync,
|
|
9
10
|
writeFileSync,
|
|
10
11
|
} from 'node:fs';
|
|
11
12
|
import { dirname, join, relative, resolve } from 'node:path';
|
|
12
|
-
import { randomUUID } from 'node:crypto';
|
|
13
|
+
import { createHash, randomUUID } from 'node:crypto';
|
|
13
14
|
import type { AuthProfile } from './auth.js';
|
|
14
15
|
import { tryAcquireWorkspaceRuntimeLock } from './workspace-runtime-lock.js';
|
|
15
16
|
import {
|
|
@@ -40,6 +41,8 @@ import {
|
|
|
40
41
|
type SkillHostMutationResult,
|
|
41
42
|
} from './skill-host.js';
|
|
42
43
|
import { zipContentDigest } from './zip-store.js';
|
|
44
|
+
import { selectedSkillNameConflicts, skillConflictNames, skillNameKey, sameSkill,
|
|
45
|
+
type SkillNameConflict } from './skill-name-conflicts.js';
|
|
43
46
|
|
|
44
47
|
interface ActiveSkillEntry {
|
|
45
48
|
name: string;
|
|
@@ -71,6 +74,7 @@ export interface AgentWorkspaceSkillChanges {
|
|
|
71
74
|
unchanged: string[];
|
|
72
75
|
preservedModified: string[];
|
|
73
76
|
failed: Array<{ name: string; action: 'add' | 'update' | 'remove'; error: string }>;
|
|
77
|
+
conflicts?: SkillNameConflict[];
|
|
74
78
|
skipped?: SkillHostSkip[];
|
|
75
79
|
requiresUserConfirmation: boolean;
|
|
76
80
|
prompt?: string;
|
|
@@ -155,6 +159,63 @@ function unique(values: Array<string | undefined>): string[] {
|
|
|
155
159
|
return [...new Set(values.filter((value): value is string => !!value))];
|
|
156
160
|
}
|
|
157
161
|
|
|
162
|
+
function hubSkillWorkingCopyPath(
|
|
163
|
+
workspaceDir: string,
|
|
164
|
+
profile: Pick<AuthProfile, 'apiKey'>,
|
|
165
|
+
name: string,
|
|
166
|
+
resourceId: string,
|
|
167
|
+
): string {
|
|
168
|
+
const registered = capabilityEntryForHubResource(workspaceDir, profile, 'skill', resourceId);
|
|
169
|
+
if (registered) return capabilityWorkspacePath(workspaceDir, profile, registered);
|
|
170
|
+
const root = getUserDataAccountSkillsDir(workspaceDir, profile);
|
|
171
|
+
const preferred = join(root, name);
|
|
172
|
+
const pathKey = (path: string) => process.platform === 'win32' ? resolve(path).toLowerCase() : resolve(path);
|
|
173
|
+
const occupied = Object.values(readCapabilityWorkspaceRegistry(workspaceDir, profile).entries)
|
|
174
|
+
.some(entry => entry.type === 'skill'
|
|
175
|
+
&& pathKey(capabilityWorkspacePath(workspaceDir, profile, entry)) === pathKey(preferred));
|
|
176
|
+
// The previous resource may be unequipped but its source must survive a
|
|
177
|
+
// same-name replacement. Only the private directory differs, never SKILL.md.
|
|
178
|
+
return occupied ? join(root, `${name}-${createHash('sha256').update(resourceId).digest('hex')}`) : preferred;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/** Report collisions without displacing the resource already exposed to hosts. */
|
|
182
|
+
export function inspectSkillNameConflicts(
|
|
183
|
+
workspaceDir: string,
|
|
184
|
+
profile: Pick<AuthProfile, 'apiKey'>,
|
|
185
|
+
snapshot?: LocalAgentWorkspaceSnapshot,
|
|
186
|
+
targets: (name: string) => readonly string[] = agentSkillTargets,
|
|
187
|
+
): SkillNameConflict[] {
|
|
188
|
+
const manifest = readManifest(workspaceDir, profile);
|
|
189
|
+
const samePath = (left: string, right: string): boolean => {
|
|
190
|
+
try { return realpathSync(left) === realpathSync(right); } catch { return false; }
|
|
191
|
+
};
|
|
192
|
+
return selectedSkillNameConflicts(workspaceDir, profile, snapshot).map(conflict => {
|
|
193
|
+
const paths = [...new Set(conflict.candidates.flatMap(candidate =>
|
|
194
|
+
[...new Set([candidate.name, ...(candidate.id ? [candidate.id] : [])])].flatMap(name => [...targets(name)])))];
|
|
195
|
+
const linked = paths.flatMap(target => {
|
|
196
|
+
try {
|
|
197
|
+
if (!lstatSync(target).isSymbolicLink()) return [];
|
|
198
|
+
const candidate = conflict.candidates.find(item => samePath(target, item.working_copy_path)
|
|
199
|
+
|| Object.values(manifest.entries).some(entry => (
|
|
200
|
+
item.resource_id ? entry.resourceId === item.resource_id
|
|
201
|
+
: !entry.resourceId && samePath(entry.canonicalPath, item.working_copy_path)
|
|
202
|
+
) && samePath(target, entry.canonicalPath)));
|
|
203
|
+
return [candidate];
|
|
204
|
+
} catch { return []; }
|
|
205
|
+
});
|
|
206
|
+
const first = linked[0];
|
|
207
|
+
const active = first && linked.every(item => item && sameSkill(first, item)) ? first : undefined;
|
|
208
|
+
return {
|
|
209
|
+
...conflict, blocking: false,
|
|
210
|
+
...(active ? { active } : {}),
|
|
211
|
+
unavailable: conflict.candidates.filter(item => !active || !sameSkill(active, item)),
|
|
212
|
+
hint: active
|
|
213
|
+
? 'The already linked Skill remains usable. Other same-name resources are unavailable; existing files and links are preserved. Continue using the active Skill. Unequip it before explicitly switching to another resource.'
|
|
214
|
+
: 'No single active Skill could be confirmed for this name. These resources are unavailable; existing files and links are preserved. Other capabilities remain usable. Choose one resource before using this Skill.',
|
|
215
|
+
};
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
|
|
158
219
|
function accountManagedSkillSources(
|
|
159
220
|
workspaceDir: string,
|
|
160
221
|
profile: Pick<AuthProfile, 'apiKey'>,
|
|
@@ -162,12 +223,17 @@ function accountManagedSkillSources(
|
|
|
162
223
|
): Map<string, string> {
|
|
163
224
|
const skillsRoot = getUserDataAccountSkillsDir(workspaceDir, profile);
|
|
164
225
|
const sources = new Map<string, string>();
|
|
165
|
-
|
|
226
|
+
const conflicts = includeInactive ? [] : selectedSkillNameConflicts(workspaceDir, profile);
|
|
227
|
+
const conflictingNames = skillConflictNames(conflicts);
|
|
228
|
+
for (const [name, manifestEntry] of Object.entries(readManifest(workspaceDir, profile).entries)) {
|
|
166
229
|
if (isPackageManagedSkill(name)) continue;
|
|
167
230
|
const entry = Object.values(readCapabilityWorkspaceRegistry(workspaceDir, profile).entries)
|
|
168
|
-
.find(entry => entry.type === 'skill' &&
|
|
231
|
+
.find(entry => entry.type === 'skill' && (manifestEntry.resourceId
|
|
232
|
+
? entry.hub?.resourceId === manifestEntry.resourceId
|
|
233
|
+
: capabilityWorkspacePath(workspaceDir, profile, entry) === manifestEntry.canonicalPath));
|
|
234
|
+
if (conflictingNames.has(skillNameKey(name)) && entry?.selection !== 'equipped') continue;
|
|
169
235
|
if (!includeInactive && entry && (entry.selection !== 'equipped' || entry.hub?.cloudStatus)) continue;
|
|
170
|
-
sources.set(name, join(skillsRoot, name));
|
|
236
|
+
sources.set(name, manifestEntry.canonicalPath ?? join(skillsRoot, name));
|
|
171
237
|
}
|
|
172
238
|
for (const entry of Object.values(readCapabilityWorkspaceRegistry(workspaceDir, profile).entries)) {
|
|
173
239
|
if (
|
|
@@ -175,6 +241,7 @@ function accountManagedSkillSources(
|
|
|
175
241
|
|| isPackageManagedSkill(entry.runtimeId)
|
|
176
242
|
|| entry.origin !== 'local'
|
|
177
243
|
|| entry.selection !== 'equipped'
|
|
244
|
+
|| conflictingNames.has(skillNameKey(entry.runtimeId))
|
|
178
245
|
) continue;
|
|
179
246
|
sources.set(entry.runtimeId, capabilityWorkspacePath(workspaceDir, profile, entry));
|
|
180
247
|
}
|
|
@@ -188,10 +255,10 @@ function accountManagedSkillSources(
|
|
|
188
255
|
export function switchActiveAccountSkillLinks(
|
|
189
256
|
workspaceDir: string,
|
|
190
257
|
previousProfile: Pick<AuthProfile, 'apiKey'> | null,
|
|
191
|
-
nextProfile: Pick<AuthProfile, 'apiKey'
|
|
258
|
+
nextProfile: Pick<AuthProfile, 'apiKey'> | null,
|
|
192
259
|
dependencies: Pick<AgentWorkspaceSkillDependencies, 'targets' | 'linkTarget' | 'unlinkTarget'> = {},
|
|
193
260
|
): AccountSkillLinkSwitchResult {
|
|
194
|
-
if (previousProfile?.apiKey === nextProfile
|
|
261
|
+
if (previousProfile?.apiKey === nextProfile?.apiKey) return { removed: [], linked: [] };
|
|
195
262
|
const guard = tryAcquireWorkspaceRuntimeLock(workspaceDir);
|
|
196
263
|
if (!guard) throw new Error('A ClawClaw runtime is running in this workspace. Stop it before switching accounts.');
|
|
197
264
|
guard.release();
|
|
@@ -201,7 +268,7 @@ export function switchActiveAccountSkillLinks(
|
|
|
201
268
|
const previous = previousProfile
|
|
202
269
|
? accountManagedSkillSources(workspaceDir, previousProfile, true)
|
|
203
270
|
: new Map<string, string>();
|
|
204
|
-
const next = accountManagedSkillSources(workspaceDir, nextProfile);
|
|
271
|
+
const next = nextProfile ? accountManagedSkillSources(workspaceDir, nextProfile) : new Map<string, string>();
|
|
205
272
|
|
|
206
273
|
for (const [name, source] of next) {
|
|
207
274
|
if (!existsSync(source) || readSkillName(source) !== name) {
|
|
@@ -256,6 +323,8 @@ export function syncAgentWorkspaceSkills(
|
|
|
256
323
|
const next: ActiveSkillManifest = { format: 2, entries: {} };
|
|
257
324
|
const failed: AgentWorkspaceSkillChanges['failed'] = [];
|
|
258
325
|
const skipped: SkillHostSkip[] = [];
|
|
326
|
+
const conflicts = inspectSkillNameConflicts(workspaceDir, profile, snapshot, dependencies.targets);
|
|
327
|
+
const blockedNames = skillConflictNames(conflicts);
|
|
259
328
|
const hashDirectory = dependencies.hashDirectory ?? hashAgentSkillDirectory;
|
|
260
329
|
const overwriteTarget = dependencies.overwriteTarget ?? overwriteAgentSkillTarget;
|
|
261
330
|
const linkTarget = dependencies.linkTarget ?? linkAgentSkillTarget;
|
|
@@ -280,6 +349,7 @@ export function syncAgentWorkspaceSkills(
|
|
|
280
349
|
if (!item.skillRootPath) continue;
|
|
281
350
|
const path = resolveLocalAgentWorkspacePath(workspaceDir, profile, snapshot, item.skillRootPath);
|
|
282
351
|
const name = readSkillName(path);
|
|
352
|
+
if (name && blockedNames.has(skillNameKey(name))) continue;
|
|
283
353
|
if (!name || !/^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/.test(name) || isPackageManagedSkill(name)) {
|
|
284
354
|
failed.push({
|
|
285
355
|
name: name ?? item.resourceId,
|
|
@@ -308,6 +378,11 @@ export function syncAgentWorkspaceSkills(
|
|
|
308
378
|
|
|
309
379
|
for (const entry of Object.values(readCapabilityWorkspaceRegistry(workspaceDir, profile).entries)) {
|
|
310
380
|
if (entry.type !== 'skill' || entry.origin !== 'local' || entry.selection !== 'equipped') continue;
|
|
381
|
+
if (entry.hub?.cloudStatus) continue;
|
|
382
|
+
if (entry.hub && !snapshot.items.skill.some(item => item.resourceId === entry.hub!.resourceId)) continue;
|
|
383
|
+
const path = capabilityWorkspacePath(workspaceDir, profile, entry);
|
|
384
|
+
const name = readSkillName(path) ?? entry.runtimeId;
|
|
385
|
+
if (blockedNames.has(skillNameKey(name))) continue;
|
|
311
386
|
if (isPackageManagedSkill(entry.runtimeId)) {
|
|
312
387
|
failed.push({
|
|
313
388
|
name: entry.runtimeId,
|
|
@@ -316,9 +391,8 @@ export function syncAgentWorkspaceSkills(
|
|
|
316
391
|
});
|
|
317
392
|
continue;
|
|
318
393
|
}
|
|
319
|
-
const path = capabilityWorkspacePath(workspaceDir, profile, entry);
|
|
320
394
|
if (desired.has(entry.runtimeId)) {
|
|
321
|
-
if (entry.hub?.resourceId === desired.get(entry.runtimeId)?.resourceId) continue;
|
|
395
|
+
if (entry.hub?.resourceId && entry.hub.resourceId === desired.get(entry.runtimeId)?.resourceId) continue;
|
|
322
396
|
failed.push({ name: entry.runtimeId, action: 'add', error: 'local and Hub Skill names conflict' });
|
|
323
397
|
continue;
|
|
324
398
|
}
|
|
@@ -332,7 +406,10 @@ export function syncAgentWorkspaceSkills(
|
|
|
332
406
|
const preservedModified: string[] = [];
|
|
333
407
|
|
|
334
408
|
for (const [name, item] of desired) {
|
|
335
|
-
|
|
409
|
+
// A local Skill already has its own working copy. Do not manufacture a
|
|
410
|
+
// second name-based copy/registry entry when the folder name differs.
|
|
411
|
+
const canonical = item.kind === 'local' ? item.sourcePath
|
|
412
|
+
: hubSkillWorkingCopyPath(workspaceDir, profile, name, item.resourceId!);
|
|
336
413
|
const previous = current.entries[name];
|
|
337
414
|
const sourceDigest = hashDirectory(item.sourcePath);
|
|
338
415
|
const sourceCloudDigest = item.remoteCloudDigest ?? cloudDigest(item.sourcePath);
|
|
@@ -489,6 +566,10 @@ export function syncAgentWorkspaceSkills(
|
|
|
489
566
|
}
|
|
490
567
|
|
|
491
568
|
for (const [name] of Object.entries(current.entries)) {
|
|
569
|
+
if (blockedNames.has(skillNameKey(name))) {
|
|
570
|
+
next.entries[name] = current.entries[name]!;
|
|
571
|
+
continue;
|
|
572
|
+
}
|
|
492
573
|
if (isPackageManagedSkill(name) || desired.has(name)) continue;
|
|
493
574
|
let failedRemoval = false;
|
|
494
575
|
const realTargets = realSkillTargets(targets(name));
|
|
@@ -509,6 +590,7 @@ export function syncAgentWorkspaceSkills(
|
|
|
509
590
|
// Keep reporting host-owned paths even in that case, without reopening selection.
|
|
510
591
|
for (const entry of Object.values(readCapabilityWorkspaceRegistry(workspaceDir, profile).entries)) {
|
|
511
592
|
if (entry.type !== 'skill' || isPackageManagedSkill(entry.runtimeId)
|
|
593
|
+
|| blockedNames.has(skillNameKey(entry.runtimeId))
|
|
512
594
|
|| desired.has(entry.runtimeId) || current.entries[entry.runtimeId]) continue;
|
|
513
595
|
const realTargets = realSkillTargets(targets(entry.runtimeId));
|
|
514
596
|
if (realTargets.length) skipped.push(skillHostSkip(entry.runtimeId, realTargets));
|
|
@@ -521,6 +603,7 @@ export function syncAgentWorkspaceSkills(
|
|
|
521
603
|
unchanged,
|
|
522
604
|
preservedModified,
|
|
523
605
|
failed,
|
|
606
|
+
...(conflicts.length ? { conflicts } : {}),
|
|
524
607
|
skipped,
|
|
525
608
|
requiresUserConfirmation: false,
|
|
526
609
|
};
|
package/src/lib/auth.ts
CHANGED
|
@@ -149,10 +149,11 @@ export class AuthStore {
|
|
|
149
149
|
if (changed) writeRuntimeAuthState(this.runtimeAuthStateFile, current);
|
|
150
150
|
}
|
|
151
151
|
|
|
152
|
-
addProfile(profile: AuthProfile): string {
|
|
152
|
+
addProfile(profile: AuthProfile, options: { replaceExisting?: boolean } = {}): string {
|
|
153
153
|
const data = this.load();
|
|
154
154
|
const key = profileKeyFor(data, profile);
|
|
155
155
|
const existing = data.profiles[key];
|
|
156
|
+
if (options.replaceExisting) data.profiles = {};
|
|
156
157
|
data.profiles[key] = {
|
|
157
158
|
...profile,
|
|
158
159
|
runtimeAccountId: RUNTIME_ACCOUNT_ID.test(profile.runtimeAccountId ?? '')
|
|
@@ -165,6 +166,12 @@ export class AuthStore {
|
|
|
165
166
|
return key;
|
|
166
167
|
}
|
|
167
168
|
|
|
169
|
+
/** Forget credentials and routing, without deleting account resources or memory. */
|
|
170
|
+
clear(): void {
|
|
171
|
+
this.save({ activeProfile: '', profiles: {} });
|
|
172
|
+
writeRuntimeAuthState(this.runtimeAuthStateFile, { profiles: {} });
|
|
173
|
+
}
|
|
174
|
+
|
|
168
175
|
removeProfile(name: string): void {
|
|
169
176
|
this.removeProfileByKey(name);
|
|
170
177
|
}
|
|
@@ -26,6 +26,7 @@ import { HubClient, type ResourceType } from './hub-client.js';
|
|
|
26
26
|
import { findSkillRoot, overwriteAgentSkillTarget } from './skill-host.js';
|
|
27
27
|
import { unzip } from './hub-unzip.js';
|
|
28
28
|
import { zipContentDigest } from './zip-store.js';
|
|
29
|
+
import { selectedSkillNameConflicts, skillNameCandidate, skillNameKey } from './skill-name-conflicts.js';
|
|
29
30
|
|
|
30
31
|
export interface CapabilityCloudDownload {
|
|
31
32
|
type: CapabilityWorkspaceType;
|
|
@@ -234,6 +235,7 @@ export async function refreshCapabilitiesFromCloud(
|
|
|
234
235
|
const client = dependencies.client ?? HubClient.fromProfile(profile);
|
|
235
236
|
const result: CapabilityCloudRefreshResult = { downloaded: [], conflicts: [], failed: [], unchanged: [] };
|
|
236
237
|
const active = activeResourceIds(activeWorkspace);
|
|
238
|
+
const blockedSkillNames = new Set(selectedSkillNameConflicts(workspaceDir, profile, activeWorkspace).map(item => item.name));
|
|
237
239
|
const unresolvedParents = new Set(Object.values(activeWorkspace?.items ?? {}).flat().flatMap(item =>
|
|
238
240
|
item.forkReconciliation?.status === 'unresolved' ? [item.forkReconciliation.parentResourceId] : []));
|
|
239
241
|
const entries = Object.values(readCapabilityWorkspaceRegistry(workspaceDir, profile).entries)
|
|
@@ -246,6 +248,7 @@ export async function refreshCapabilitiesFromCloud(
|
|
|
246
248
|
&& !unresolvedParents.has(entry.hub.resourceId)
|
|
247
249
|
));
|
|
248
250
|
for (const entry of entries) {
|
|
251
|
+
if (entry.type === 'skill' && blockedSkillNames.has(skillNameKey(skillNameCandidate(workspaceDir, profile, entry).name))) continue;
|
|
249
252
|
const hub = entry.hub!;
|
|
250
253
|
const type = resourceType(entry.type);
|
|
251
254
|
const path = capabilityWorkspacePath(workspaceDir, profile, entry);
|
|
@@ -28,6 +28,7 @@ import {
|
|
|
28
28
|
} from './hub-client.js';
|
|
29
29
|
import type { LocalAgentWorkspaceSnapshot } from './agent-workspace-sync.js';
|
|
30
30
|
import { readSkillName } from './skill-host.js';
|
|
31
|
+
import { selectedSkillNameConflicts, skillNameCandidate, skillNameKey } from './skill-name-conflicts.js';
|
|
31
32
|
import { createStoredZip, zipContentDigest, type ZipStoreEntry } from './zip-store.js';
|
|
32
33
|
import {
|
|
33
34
|
inspectClawclawBehaviorSource,
|
|
@@ -63,7 +64,7 @@ export interface CapabilityCloudSyncFailure extends Partial<HubErrorFields> {
|
|
|
63
64
|
export interface CapabilityCloudSyncSkip {
|
|
64
65
|
type: CapabilityWorkspaceType;
|
|
65
66
|
id: string;
|
|
66
|
-
reason: 'local_origin_unrecognized' | 'fork_relationship_unresolved';
|
|
67
|
+
reason: 'local_origin_unrecognized' | 'fork_relationship_unresolved' | 'skill_name_conflict';
|
|
67
68
|
}
|
|
68
69
|
|
|
69
70
|
export interface CapabilityCloudSyncResult {
|
|
@@ -244,6 +245,7 @@ export async function syncCapabilitiesToCloud(
|
|
|
244
245
|
unchanged: [],
|
|
245
246
|
};
|
|
246
247
|
const selectedKeys = dependencies.entryKeys ? new Set(dependencies.entryKeys) : undefined;
|
|
248
|
+
const blockedSkillNames = new Set(selectedSkillNameConflicts(workspaceDir, profile, snapshot).map(item => item.name));
|
|
247
249
|
const unresolvedForks = new Set(Object.values(snapshot.items).flat().flatMap(item =>
|
|
248
250
|
item.forkReconciliation?.status === 'unresolved'
|
|
249
251
|
? [item.resourceId, item.forkReconciliation.parentResourceId] : []));
|
|
@@ -254,6 +256,10 @@ export async function syncCapabilitiesToCloud(
|
|
|
254
256
|
&& (!selectedKeys || selectedKeys.has(entry.key))
|
|
255
257
|
));
|
|
256
258
|
for (const entry of entries) {
|
|
259
|
+
if (entry.type === 'skill' && blockedSkillNames.has(skillNameKey(skillNameCandidate(workspaceDir, profile, entry).name))) {
|
|
260
|
+
result.skipped.push({ type: entry.type, id: entry.runtimeId, reason: 'skill_name_conflict' });
|
|
261
|
+
continue;
|
|
262
|
+
}
|
|
257
263
|
if (entry.hub && (entry.hub.forkRelationshipUnresolved || unresolvedForks.has(entry.hub.resourceId))) {
|
|
258
264
|
result.skipped.push({ type: entry.type, id: entry.runtimeId, reason: 'fork_relationship_unresolved' });
|
|
259
265
|
continue;
|
|
@@ -4,6 +4,7 @@ import { assignCapabilityOperationName, capabilitySelectionRef,
|
|
|
4
4
|
readCapabilityWorkspaceRegistry, writeCapabilityWorkspaceRegistry,
|
|
5
5
|
type CapabilityWorkspaceType } from './capability-workspace.js';
|
|
6
6
|
import { updateGameplayConfig } from './gameplay-config.js';
|
|
7
|
+
import { skillNameCandidate, skillNameConflicts, throwSkillNameConflict } from './skill-name-conflicts.js';
|
|
7
8
|
|
|
8
9
|
export type EquipmentClient = Pick<HubClient,
|
|
9
10
|
'updateWorkspaceEquipment' | 'updateWorkspaceLoadout' | 'findWorkspaceItem'>;
|
|
@@ -25,6 +26,13 @@ export async function selectCapability(
|
|
|
25
26
|
));
|
|
26
27
|
if (matches.length !== 1) throw new Error(`capability_selection_${matches.length ? 'ambiguous' : 'not_found'}:${type}:${id}`);
|
|
27
28
|
const entry = matches[0]!;
|
|
29
|
+
if (type === 'skill' && equipped) {
|
|
30
|
+
const candidates = Object.values(registry.entries).filter(other => other.type === 'skill'
|
|
31
|
+
&& (other.key === entry.key || (other.selection === 'equipped' && !other.hub?.cloudStatus)));
|
|
32
|
+
const conflict = skillNameConflicts(candidates.map(other => skillNameCandidate(workspaceDir, profile, other)))
|
|
33
|
+
.find(item => item.candidates.some(candidate => candidate.selection_ref === capabilitySelectionRef(entry)));
|
|
34
|
+
if (conflict) throwSkillNameConflict(conflict);
|
|
35
|
+
}
|
|
28
36
|
if (entry.hub) {
|
|
29
37
|
const client = providedClient ?? HubClient.fromProfile(profile);
|
|
30
38
|
if (entry.hub.cloudStatus) throw new Error(`capability_workspace_removed:${type}/${id}`);
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { join } from 'node:path';
|
|
2
|
+
import { setTimeout as delay } from 'node:timers/promises';
|
|
3
|
+
import { getWorkspaceDir } from './init-command.js';
|
|
4
|
+
import { getRuntimeDir } from './user-data.js';
|
|
5
|
+
import { tryAcquireWorkspaceRuntimeLock } from './workspace-runtime-lock.js';
|
|
6
|
+
import { readWorkspaceOwnerRecord, workspaceOwnerIdentity } from '../runtime/clawclaw/owner-lock.js';
|
|
7
|
+
import { readGameStartRuntime, sendOwnerControlRequestTo } from '../runtime/owner-control.js';
|
|
8
|
+
|
|
9
|
+
/** Stop locally only: never leave the backend game or claim its control again. */
|
|
10
|
+
export async function stopDesktopRuntime(timeoutMs = 10_000): Promise<void> {
|
|
11
|
+
const workspace = getWorkspaceDir();
|
|
12
|
+
const deadline = Date.now() + timeoutMs;
|
|
13
|
+
let target: string | undefined;
|
|
14
|
+
let stopSent = false;
|
|
15
|
+
do {
|
|
16
|
+
const guard = tryAcquireWorkspaceRuntimeLock(workspace);
|
|
17
|
+
if (guard) {
|
|
18
|
+
guard.release();
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
const owner = readWorkspaceOwnerRecord(workspace);
|
|
22
|
+
if (owner) {
|
|
23
|
+
if (owner.workspace_id !== workspaceOwnerIdentity(workspace)
|
|
24
|
+
|| (target !== undefined && target !== owner.instance_id)) {
|
|
25
|
+
throw new Error('Runtime changed while logging out. Retry from the client.');
|
|
26
|
+
}
|
|
27
|
+
target = owner.instance_id;
|
|
28
|
+
if (!stopSent) {
|
|
29
|
+
const pointer = readGameStartRuntime(join(getRuntimeDir(workspace), 'accounts', owner.runtime_account_id));
|
|
30
|
+
if (pointer?.instance_id === target && pointer.owner_pid === owner.pid) {
|
|
31
|
+
const response = await sendOwnerControlRequestTo(pointer, 'stop', { instance_id: target },
|
|
32
|
+
Math.max(1, Math.min(1_000, deadline - Date.now())));
|
|
33
|
+
stopSent = response?.ok === true;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
await delay(50);
|
|
38
|
+
} while (Date.now() < deadline);
|
|
39
|
+
throw new Error('Runtime did not stop in time. Login binding was retained; retry from the client.');
|
|
40
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export function isDesktopMode(env: NodeJS.ProcessEnv = process.env): boolean {
|
|
2
|
+
return env.CLAWCLAW_IS_DESKTOP === 'true';
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
export const DESKTOP_LOGIN_MESSAGE = '请在客户端登录游戏账号。CCL 的登录账号由客户端管理。';
|
|
6
|
+
|
|
7
|
+
export function accountRequiredMessage(standaloneMessage: string): string {
|
|
8
|
+
return isDesktopMode() ? DESKTOP_LOGIN_MESSAGE : standaloneMessage;
|
|
9
|
+
}
|
package/src/lib/game-client.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { accountRequiredMessage } from './desktop-mode.js';
|
|
1
2
|
// src/lib/game-client.ts
|
|
2
3
|
import { WsConnectionState } from '../sdk/types.js';
|
|
3
4
|
import { AuthStore } from './auth.js';
|
|
@@ -142,7 +143,7 @@ export class GameClient {
|
|
|
142
143
|
const profile = store.getActive();
|
|
143
144
|
|
|
144
145
|
if (!profile) {
|
|
145
|
-
throw new Error('No active auth profile. Run: clawclaw-cli account register');
|
|
146
|
+
throw new Error(accountRequiredMessage('No active auth profile. Run: clawclaw-cli account register'));
|
|
146
147
|
}
|
|
147
148
|
|
|
148
149
|
return new GameClient({
|
package/src/lib/hub-client.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { accountRequiredMessage } from './desktop-mode.js';
|
|
1
2
|
import { AuthStore } from './auth.js';
|
|
2
3
|
import { createHash } from 'node:crypto';
|
|
3
4
|
import { ServerRegistry } from './server-registry.js';
|
|
@@ -238,7 +239,7 @@ export class HubClient {
|
|
|
238
239
|
static fromAuth(opts?: { authStore?: AuthStore }): HubClient {
|
|
239
240
|
const store = opts?.authStore ?? new AuthStore();
|
|
240
241
|
const profile = store.getActive();
|
|
241
|
-
if (!profile) throw new Error('No active account. Run `ccl account register` or switch accounts first.');
|
|
242
|
+
if (!profile) throw new Error(accountRequiredMessage('No active account. Run `ccl account register` or switch accounts first.'));
|
|
242
243
|
return HubClient.fromProfile(profile);
|
|
243
244
|
}
|
|
244
245
|
|
package/src/lib/load-context.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { accountRequiredMessage } from './desktop-mode.js';
|
|
1
2
|
import { existsSync, readFileSync, writeFileSync } from 'fs';
|
|
2
3
|
import { AuthStore } from './auth.js';
|
|
3
4
|
import { getProfileMemoryFile } from './init-command.js';
|
|
@@ -44,7 +45,7 @@ export function loadPersonaSnapshot(authStore = new AuthStore()): LoadedFileSnap
|
|
|
44
45
|
|
|
45
46
|
export function loadMemorySnapshot(authStore = new AuthStore()): LoadedFileSnapshot {
|
|
46
47
|
const profile = authStore.getActive();
|
|
47
|
-
if (!profile) throw new Error('Not logged in.');
|
|
48
|
+
if (!profile) throw new Error(accountRequiredMessage('Not logged in.'));
|
|
48
49
|
const path = getProfileMemoryFile(profile);
|
|
49
50
|
ensureMemoryFile(path);
|
|
50
51
|
const exists = existsSync(path);
|
package/src/lib/persona.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { accountRequiredMessage } from './desktop-mode.js';
|
|
1
2
|
import { randomUUID } from 'node:crypto';
|
|
2
3
|
import { existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync, renameSync } from 'fs';
|
|
3
4
|
import { dirname, join, basename } from 'path';
|
|
@@ -155,7 +156,7 @@ function hubPersona(
|
|
|
155
156
|
|
|
156
157
|
export function resolveActivePersonaFile(authStore = new AuthStore()): ResolvedPersonaFile {
|
|
157
158
|
const profile = authStore.getActive();
|
|
158
|
-
if (!profile) throw new Error('Not logged in.');
|
|
159
|
+
if (!profile) throw new Error(accountRequiredMessage('Not logged in.'));
|
|
159
160
|
const workspaceDir = getWorkspaceDir();
|
|
160
161
|
ensureAccountUserDataLayout(workspaceDir, profile);
|
|
161
162
|
const snapshot = filterInactiveAgentWorkspaceSnapshot(
|
package/src/lib/skill-host.ts
CHANGED
|
@@ -218,6 +218,16 @@ export function unlinkAgentSkillTarget(targetPath: string): SkillHostMutationRes
|
|
|
218
218
|
}
|
|
219
219
|
}
|
|
220
220
|
|
|
221
|
+
/** An unequip must not remove another resource's link at the same Skill name. */
|
|
222
|
+
export function agentSkillLinkPointsTo(targetPath: string, sourcePath: string): boolean {
|
|
223
|
+
try {
|
|
224
|
+
return lstatSync(targetPath).isSymbolicLink()
|
|
225
|
+
&& realpathSync(targetPath) === realpathSync(sourcePath);
|
|
226
|
+
} catch {
|
|
227
|
+
return false;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
221
231
|
export function unregisterAgentSkill(name: string): SkillHostMutationResult {
|
|
222
232
|
return runSkillsCli(['remove', name, '-g', '-y']);
|
|
223
233
|
}
|