@myclaw163/clawclaw-cli 0.8.12 → 0.8.13
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 +11 -12
- package/docs/custom-modules/README.md +3 -3
- package/docs/custom-modules/behavior.md +1 -1
- package/docs/custom-modules/perception.md +1 -1
- package/docs/custom-modules/trigger.md +1 -1
- package/docs/runtime/official-perception-modules.md +1 -1
- package/package.json +1 -1
- package/scripts/check-skill-command-surface.mjs +1 -0
- package/scripts/sync-bundled-skill.mjs +89 -52
- package/skills/clawclaw/SKILL.md +7 -3
- package/skills/clawclaw/references/BEHAVIORS.md +2 -0
- package/skills/clawclaw/references/COMMANDS.md +9 -2
- package/skills/clawclaw/references/HUB.md +4 -2
- package/src/cli.ts +2 -0
- package/src/commands/behavior.ts +49 -8
- package/src/commands/capability.ts +345 -0
- package/src/commands/load.ts +195 -8
- package/src/commands/perception.ts +21 -7
- package/src/commands/persona.ts +6 -0
- package/src/commands/trigger.ts +8 -5
- package/src/lib/agent-workspace-skills.ts +167 -68
- package/src/lib/agent-workspace-sync.ts +20 -31
- package/src/lib/capability-cloud-refresh.ts +313 -0
- package/src/lib/capability-cloud-sync.ts +315 -0
- package/src/lib/capability-discovery.ts +94 -0
- package/src/lib/capability-workspace.ts +291 -0
- package/src/lib/hub-client.ts +131 -4
- package/src/lib/persona.ts +1 -24
- package/src/lib/skill-host.ts +63 -0
- package/src/lib/user-data.ts +47 -59
- package/src/lib/zip-store.ts +92 -0
- package/src/runtime/clawclaw/owner.ts +12 -12
|
@@ -15,9 +15,10 @@ import {
|
|
|
15
15
|
listAgentWorkspacePerceptionSources,
|
|
16
16
|
mergeAgentWorkspacePerceptionSources,
|
|
17
17
|
} from '../lib/agent-workspace-runtime.js';
|
|
18
|
-
import { listClawclawPerceptionSourcesInDirectory } from '../runtime/clawclaw/plugins/perception/perception-source.js';
|
|
19
18
|
import { PERCEPTION_PLUGIN_API_VERSION } from '../sdk/perception-plugin/index.js';
|
|
20
19
|
import { pluginApiVersionStatus } from '../runtime/clawclaw/plugins/plugin-api-version.js';
|
|
20
|
+
import { discoverLocalCapabilities } from '../lib/capability-discovery.js';
|
|
21
|
+
import { capabilityEntryForPath, setCapabilitySelection } from '../lib/capability-workspace.js';
|
|
21
22
|
|
|
22
23
|
export interface PerceptionCommandDependencies {
|
|
23
24
|
activeProfile?: () => AuthProfile | null;
|
|
@@ -40,11 +41,11 @@ export function createPerceptionCommand(dependencies: PerceptionCommandDependenc
|
|
|
40
41
|
const profile = (dependencies.activeProfile ?? (() => new AuthStore().getActive()))();
|
|
41
42
|
const directory = profile
|
|
42
43
|
? getUserDataAccountPerceptionsDir(getWorkspaceDir(), profile)
|
|
43
|
-
: '<active-account>/perceptions
|
|
44
|
+
: '<active-account>/capabilities/perceptions';
|
|
44
45
|
return `
|
|
45
46
|
Perception modules:
|
|
46
47
|
Place custom .ts or .js modules in ${directory}
|
|
47
|
-
Local modules
|
|
48
|
+
Local modules require one persisted ccl capability equip/unequip choice.
|
|
48
49
|
Hub module enablement is controlled by the Hub loadout.
|
|
49
50
|
`;
|
|
50
51
|
})
|
|
@@ -60,13 +61,15 @@ Perception modules:
|
|
|
60
61
|
? listAgentWorkspacePerceptionSources(workspaceDir, profile, snapshot)
|
|
61
62
|
: [];
|
|
62
63
|
const hubIds = new Set(hub.map(({ id }) => id));
|
|
63
|
-
const local =
|
|
64
|
-
|
|
65
|
-
);
|
|
64
|
+
const local = discoverLocalCapabilities(workspaceDir, profile).perceptions
|
|
65
|
+
.map(({ source }) => source);
|
|
66
66
|
if ((opts.disable && hubIds.has(opts.disable)) || (opts.enable && hubIds.has(opts.enable))) {
|
|
67
67
|
throw new Error(`Hub Perception '${opts.disable ?? opts.enable}' enablement is controlled by the Hub loadout.`);
|
|
68
68
|
}
|
|
69
69
|
if (opts.disable) {
|
|
70
|
+
const source = local.find(({ id }) => id === opts.disable);
|
|
71
|
+
if (!source) throw new Error(`Unknown local Perception '${opts.disable}'.`);
|
|
72
|
+
setCapabilitySelection(workspaceDir, profile, 'perception', opts.disable, false);
|
|
70
73
|
const updated = updateGameplayConfig((current) => {
|
|
71
74
|
current.disabled_perception_modules.push(opts.disable!);
|
|
72
75
|
}, workspaceDir, profile);
|
|
@@ -80,6 +83,9 @@ Perception modules:
|
|
|
80
83
|
return;
|
|
81
84
|
}
|
|
82
85
|
if (opts.enable) {
|
|
86
|
+
const source = local.find(({ id }) => id === opts.enable);
|
|
87
|
+
if (!source) throw new Error(`Unknown local Perception '${opts.enable}'.`);
|
|
88
|
+
setCapabilitySelection(workspaceDir, profile, 'perception', opts.enable, true);
|
|
83
89
|
const updated = updateGameplayConfig((current) => {
|
|
84
90
|
current.disabled_perception_modules = current.disabled_perception_modules
|
|
85
91
|
.filter((id) => id !== opts.enable);
|
|
@@ -106,7 +112,15 @@ Perception modules:
|
|
|
106
112
|
PERCEPTION_PLUGIN_API_VERSION,
|
|
107
113
|
source.apiVersion,
|
|
108
114
|
),
|
|
109
|
-
disabled: hubIds.has(source.id)
|
|
115
|
+
disabled: hubIds.has(source.id)
|
|
116
|
+
? false
|
|
117
|
+
: disabled.has(source.id)
|
|
118
|
+
|| capabilityEntryForPath(
|
|
119
|
+
workspaceDir,
|
|
120
|
+
profile,
|
|
121
|
+
'perception',
|
|
122
|
+
source.sourcePath,
|
|
123
|
+
)?.selection !== 'equipped',
|
|
110
124
|
}));
|
|
111
125
|
console.log(JSON.stringify({
|
|
112
126
|
perception_modules: installed,
|
package/src/commands/persona.ts
CHANGED
|
@@ -13,6 +13,8 @@ import {
|
|
|
13
13
|
getUserDataAccountPersonasDir,
|
|
14
14
|
} from '../lib/user-data.js';
|
|
15
15
|
import { loadPersonaSnapshot } from '../lib/load-context.js';
|
|
16
|
+
import { discoverLocalCapabilities } from '../lib/capability-discovery.js';
|
|
17
|
+
import { setCapabilitySelection } from '../lib/capability-workspace.js';
|
|
16
18
|
|
|
17
19
|
function context() {
|
|
18
20
|
const profile = new AuthStore().getActive();
|
|
@@ -61,6 +63,8 @@ export function createPersonaCommand(): Command {
|
|
|
61
63
|
.action((name: string) => {
|
|
62
64
|
const { directory, workspaceDir, profile } = context();
|
|
63
65
|
const created = createPersonaPreset(name, directory);
|
|
66
|
+
discoverLocalCapabilities(workspaceDir, profile);
|
|
67
|
+
setCapabilitySelection(workspaceDir, profile, 'persona', created.id, true);
|
|
64
68
|
writePersonaSelection(workspaceDir, profile, { source: 'local', id: created.id });
|
|
65
69
|
console.log(JSON.stringify({
|
|
66
70
|
path: created.path,
|
|
@@ -79,6 +83,8 @@ export function createPersonaCommand(): Command {
|
|
|
79
83
|
throw new Error(`Persona preset "${presetName}" not found. Available: ${available}`);
|
|
80
84
|
}
|
|
81
85
|
writePersonaSelection(workspaceDir, profile, { source: 'local', id: found.id });
|
|
86
|
+
discoverLocalCapabilities(workspaceDir, profile);
|
|
87
|
+
setCapabilitySelection(workspaceDir, profile, 'persona', found.id, true);
|
|
82
88
|
console.log(JSON.stringify({
|
|
83
89
|
path: found.path,
|
|
84
90
|
preset: { id: found.id, name: found.name, source: 'local' },
|
package/src/commands/trigger.ts
CHANGED
|
@@ -9,7 +9,6 @@ import {
|
|
|
9
9
|
} from '../lib/trigger-config.js';
|
|
10
10
|
import {
|
|
11
11
|
ensureAccountUserDataLayout,
|
|
12
|
-
getUserDataAccountBehaviorsDir,
|
|
13
12
|
getUserDataAccountGameplayConfigFile,
|
|
14
13
|
getUserDataAccountTriggersDir,
|
|
15
14
|
} from '../lib/user-data.js';
|
|
@@ -17,8 +16,8 @@ import { TRIGGER_PLUGIN_API_VERSION, MAX_TRIGGER_RUNTIME_MS } from '../sdk/trigg
|
|
|
17
16
|
import { BEHAVIOR_PLUGIN_API_VERSION } from '../sdk/behavior-plugin/index.js';
|
|
18
17
|
import {
|
|
19
18
|
behaviorSourceCompatibilityError,
|
|
20
|
-
listClawclawBehaviorSources,
|
|
21
19
|
} from '../runtime/clawclaw/plugins/behavior/behavior-source.js';
|
|
20
|
+
import { discoverLocalCapabilities } from '../lib/capability-discovery.js';
|
|
22
21
|
import { listClawclawTriggerSources } from '../runtime/clawclaw/plugins/trigger/trigger-source.js';
|
|
23
22
|
import { readLocalAgentWorkspaceSnapshot } from '../lib/agent-workspace-sync.js';
|
|
24
23
|
import {
|
|
@@ -133,13 +132,17 @@ function assertBehaviorBinding(
|
|
|
133
132
|
profile: Pick<AuthProfile, 'apiKey'>,
|
|
134
133
|
): void {
|
|
135
134
|
const gameplay = readGameplayConfig(workspaceDir, profile);
|
|
136
|
-
const
|
|
135
|
+
const discovered = discoverLocalCapabilities(workspaceDir, profile).behaviors;
|
|
136
|
+
const local = discovered.map(({ source }) => source);
|
|
137
|
+
const selectedLocal = discovered
|
|
138
|
+
.filter(({ entry }) => entry.selection === 'equipped')
|
|
139
|
+
.map(({ source }) => source);
|
|
137
140
|
const snapshot = readLocalAgentWorkspaceSnapshot(workspaceDir, profile);
|
|
138
141
|
const hub = snapshot
|
|
139
142
|
? listAgentWorkspaceBehaviorSources(workspaceDir, profile, snapshot)
|
|
140
143
|
: [];
|
|
141
144
|
const source = mergeAgentWorkspaceBehaviorSources(
|
|
142
|
-
|
|
145
|
+
selectedLocal.filter((candidate) => !gameplay.disabled_behaviors.includes(candidate.id)),
|
|
143
146
|
hub,
|
|
144
147
|
)
|
|
145
148
|
.find((candidate) => candidate.id === id);
|
|
@@ -226,7 +229,7 @@ export function createTriggerCommand(dependencies: TriggerCommandDependencies =
|
|
|
226
229
|
const profile = (dependencies.activeProfile ?? (() => new AuthStore().getActive()))();
|
|
227
230
|
const directory = profile
|
|
228
231
|
? getUserDataAccountTriggersDir(workspaceDir, profile)
|
|
229
|
-
: '<active-account>/triggers
|
|
232
|
+
: '<active-account>/capabilities/triggers';
|
|
230
233
|
return `\nTrigger modules:\n Place .ts or .js files in ${directory}\n Local Triggers are available by default unless listed in disabled_triggers; discovery never executes module code.\n`;
|
|
231
234
|
});
|
|
232
235
|
|
|
@@ -6,25 +6,40 @@ import {
|
|
|
6
6
|
resolveLocalAgentWorkspacePath,
|
|
7
7
|
type LocalAgentWorkspaceSnapshot,
|
|
8
8
|
} from './agent-workspace-sync.js';
|
|
9
|
-
import {
|
|
9
|
+
import {
|
|
10
|
+
capabilityWorkspacePath,
|
|
11
|
+
readCapabilityWorkspaceRegistry,
|
|
12
|
+
registerDiscoveredCapability,
|
|
13
|
+
} from './capability-workspace.js';
|
|
14
|
+
import {
|
|
15
|
+
getUserDataAccountCapabilitiesDir,
|
|
16
|
+
getUserDataAccountSkillsDir,
|
|
17
|
+
} from './user-data.js';
|
|
10
18
|
import {
|
|
11
19
|
agentSkillTargets,
|
|
12
20
|
hashAgentSkillDirectory,
|
|
21
|
+
linkAgentSkillTarget,
|
|
13
22
|
overwriteAgentSkillTarget,
|
|
14
23
|
readSkillName,
|
|
24
|
+
resolveBundledClawclawSkill,
|
|
25
|
+
unlinkAgentSkillTarget,
|
|
15
26
|
type SkillHostMutationResult,
|
|
16
27
|
} from './skill-host.js';
|
|
17
28
|
|
|
18
29
|
interface ActiveSkillEntry {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
30
|
+
name: string;
|
|
31
|
+
kind: 'official' | 'hub' | 'local';
|
|
32
|
+
canonicalPath: string;
|
|
33
|
+
sourceDigest?: string;
|
|
34
|
+
remoteDigest?: string;
|
|
35
|
+
resourceId?: string;
|
|
36
|
+
versionId?: string;
|
|
25
37
|
}
|
|
26
38
|
|
|
27
|
-
|
|
39
|
+
interface ActiveSkillManifest {
|
|
40
|
+
format: 2;
|
|
41
|
+
entries: Record<string, ActiveSkillEntry>;
|
|
42
|
+
}
|
|
28
43
|
|
|
29
44
|
export interface AgentWorkspaceSkillChanges {
|
|
30
45
|
added: string[];
|
|
@@ -41,27 +56,38 @@ export interface AgentWorkspaceSkillDependencies {
|
|
|
41
56
|
targets?: (name: string) => readonly string[];
|
|
42
57
|
hashDirectory?: (path: string) => string | undefined;
|
|
43
58
|
overwriteTarget?: (sourcePath: string, targetPath: string) => SkillHostMutationResult;
|
|
59
|
+
linkTarget?: (sourcePath: string, targetPath: string) => SkillHostMutationResult;
|
|
60
|
+
unlinkTarget?: (targetPath: string) => SkillHostMutationResult;
|
|
61
|
+
bundledSkill?: () => string;
|
|
44
62
|
}
|
|
45
63
|
|
|
46
|
-
function manifestPath(
|
|
47
|
-
|
|
64
|
+
function manifestPath(
|
|
65
|
+
workspaceDir: string,
|
|
66
|
+
profile: Pick<AuthProfile, 'apiKey'>,
|
|
67
|
+
): string {
|
|
68
|
+
return join(getUserDataAccountCapabilitiesDir(workspaceDir, profile), 'skill-links.json');
|
|
48
69
|
}
|
|
49
70
|
|
|
50
|
-
function readManifest(
|
|
51
|
-
|
|
52
|
-
|
|
71
|
+
function readManifest(
|
|
72
|
+
workspaceDir: string,
|
|
73
|
+
profile: Pick<AuthProfile, 'apiKey'>,
|
|
74
|
+
): ActiveSkillManifest {
|
|
75
|
+
const path = manifestPath(workspaceDir, profile);
|
|
76
|
+
if (!existsSync(path)) return { format: 2, entries: {} };
|
|
53
77
|
try {
|
|
54
|
-
const value = JSON.parse(readFileSync(path, 'utf8'));
|
|
55
|
-
return value &&
|
|
56
|
-
? value as ActiveSkillManifest
|
|
57
|
-
: {};
|
|
78
|
+
const value = JSON.parse(readFileSync(path, 'utf8')) as ActiveSkillManifest;
|
|
79
|
+
return value.format === 2 && value.entries ? value : { format: 2, entries: {} };
|
|
58
80
|
} catch {
|
|
59
|
-
return {};
|
|
81
|
+
return { format: 2, entries: {} };
|
|
60
82
|
}
|
|
61
83
|
}
|
|
62
84
|
|
|
63
|
-
function writeManifest(
|
|
64
|
-
|
|
85
|
+
function writeManifest(
|
|
86
|
+
workspaceDir: string,
|
|
87
|
+
profile: Pick<AuthProfile, 'apiKey'>,
|
|
88
|
+
value: ActiveSkillManifest,
|
|
89
|
+
): void {
|
|
90
|
+
const target = manifestPath(workspaceDir, profile);
|
|
65
91
|
mkdirSync(dirname(target), { recursive: true });
|
|
66
92
|
const temporary = `${target}.${randomUUID()}.tmp`;
|
|
67
93
|
writeFileSync(temporary, `${JSON.stringify(value, null, 2)}\n`, 'utf8');
|
|
@@ -78,10 +104,27 @@ export function syncAgentWorkspaceSkills(
|
|
|
78
104
|
snapshot: LocalAgentWorkspaceSnapshot,
|
|
79
105
|
dependencies: AgentWorkspaceSkillDependencies = {},
|
|
80
106
|
): AgentWorkspaceSkillChanges {
|
|
81
|
-
const current = readManifest(workspaceDir);
|
|
82
|
-
const
|
|
107
|
+
const current = readManifest(workspaceDir, profile);
|
|
108
|
+
const next: ActiveSkillManifest = { format: 2, entries: {} };
|
|
83
109
|
const failed: AgentWorkspaceSkillChanges['failed'] = [];
|
|
84
110
|
const hashDirectory = dependencies.hashDirectory ?? hashAgentSkillDirectory;
|
|
111
|
+
const overwriteTarget = dependencies.overwriteTarget ?? overwriteAgentSkillTarget;
|
|
112
|
+
const linkTarget = dependencies.linkTarget ?? linkAgentSkillTarget;
|
|
113
|
+
const unlinkTarget = dependencies.unlinkTarget ?? unlinkAgentSkillTarget;
|
|
114
|
+
const targets = dependencies.targets ?? agentSkillTargets;
|
|
115
|
+
const skillsRoot = getUserDataAccountSkillsDir(workspaceDir, profile);
|
|
116
|
+
mkdirSync(skillsRoot, { recursive: true });
|
|
117
|
+
|
|
118
|
+
const desired = new Map<string, {
|
|
119
|
+
kind: ActiveSkillEntry['kind'];
|
|
120
|
+
sourcePath: string;
|
|
121
|
+
resourceId?: string;
|
|
122
|
+
versionId?: string;
|
|
123
|
+
remoteDigest?: string;
|
|
124
|
+
publisher?: 'official' | 'self' | 'community';
|
|
125
|
+
}>();
|
|
126
|
+
const bundled = (dependencies.bundledSkill ?? resolveBundledClawclawSkill)();
|
|
127
|
+
desired.set('clawclaw', { kind: 'official', sourcePath: bundled });
|
|
85
128
|
|
|
86
129
|
for (const item of snapshot.items.skill) {
|
|
87
130
|
if (!item.skillRootPath) continue;
|
|
@@ -90,81 +133,137 @@ export function syncAgentWorkspaceSkills(
|
|
|
90
133
|
if (!name || !/^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/.test(name) || name === 'clawclaw') {
|
|
91
134
|
failed.push({
|
|
92
135
|
name: name ?? item.resourceId,
|
|
93
|
-
action: current[name ?? ''] ? 'update' : 'add',
|
|
136
|
+
action: current.entries[name ?? ''] ? 'update' : 'add',
|
|
94
137
|
error: name === 'clawclaw'
|
|
95
|
-
? '
|
|
138
|
+
? 'Hub resource cannot replace the official clawclaw Skill'
|
|
96
139
|
: 'SKILL.md name is missing or unsafe',
|
|
97
140
|
});
|
|
98
141
|
continue;
|
|
99
142
|
}
|
|
100
|
-
if (desired
|
|
143
|
+
if (desired.has(name)) {
|
|
101
144
|
failed.push({ name, action: 'add', error: 'duplicate selected skill name' });
|
|
102
145
|
continue;
|
|
103
146
|
}
|
|
104
|
-
desired
|
|
147
|
+
desired.set(name, {
|
|
148
|
+
kind: 'hub',
|
|
149
|
+
sourcePath: path,
|
|
105
150
|
resourceId: item.resourceId,
|
|
106
151
|
versionId: item.versionId,
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
152
|
+
remoteDigest: hashDirectory(path),
|
|
153
|
+
publisher: item.hub?.publisher ?? 'community',
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
for (const entry of Object.values(readCapabilityWorkspaceRegistry(workspaceDir, profile).entries)) {
|
|
158
|
+
if (entry.type !== 'skill' || entry.origin !== 'local' || entry.selection !== 'equipped') continue;
|
|
159
|
+
const path = capabilityWorkspacePath(workspaceDir, profile, entry);
|
|
160
|
+
if (desired.has(entry.runtimeId)) {
|
|
161
|
+
failed.push({ name: entry.runtimeId, action: 'add', error: 'local and Hub Skill names conflict' });
|
|
162
|
+
continue;
|
|
114
163
|
}
|
|
164
|
+
desired.set(entry.runtimeId, { kind: 'local', sourcePath: path });
|
|
115
165
|
}
|
|
116
166
|
|
|
117
|
-
const next: ActiveSkillManifest = { ...current };
|
|
118
167
|
const added: string[] = [];
|
|
119
168
|
const updated: string[] = [];
|
|
120
169
|
const removed: string[] = [];
|
|
121
170
|
const unchanged: string[] = [];
|
|
122
171
|
const preservedModified: string[] = [];
|
|
123
|
-
const targets = dependencies.targets ?? agentSkillTargets;
|
|
124
|
-
const overwriteTarget = dependencies.overwriteTarget ?? overwriteAgentSkillTarget;
|
|
125
172
|
|
|
126
|
-
for (const [name,
|
|
127
|
-
const
|
|
128
|
-
const
|
|
129
|
-
const
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
173
|
+
for (const [name, item] of desired) {
|
|
174
|
+
const canonical = join(skillsRoot, name);
|
|
175
|
+
const previous = current.entries[name];
|
|
176
|
+
const sourceDigest = hashDirectory(item.sourcePath);
|
|
177
|
+
if (!sourceDigest) {
|
|
178
|
+
failed.push({ name, action: previous ? 'update' : 'add', error: 'Skill source is unreadable' });
|
|
179
|
+
continue;
|
|
180
|
+
}
|
|
181
|
+
const canonicalDigest = hashDirectory(canonical);
|
|
182
|
+
let applied = false;
|
|
135
183
|
let preserved = false;
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
184
|
+
if (item.kind === 'local' && resolve(item.sourcePath) === resolve(canonical)) {
|
|
185
|
+
applied = true;
|
|
186
|
+
} else if (item.kind === 'official') {
|
|
187
|
+
if (canonicalDigest !== sourceDigest) {
|
|
188
|
+
const result = overwriteTarget(item.sourcePath, canonical);
|
|
189
|
+
if (!result.ok) {
|
|
190
|
+
failed.push({ name, action: previous ? 'update' : 'add', error: resultError(result) });
|
|
191
|
+
continue;
|
|
192
|
+
}
|
|
193
|
+
applied = true;
|
|
144
194
|
}
|
|
145
|
-
|
|
146
|
-
|
|
195
|
+
} else if (canonicalDigest === sourceDigest) {
|
|
196
|
+
applied = true;
|
|
197
|
+
} else if (canonicalDigest === undefined || canonicalDigest === previous?.sourceDigest) {
|
|
198
|
+
const result = overwriteTarget(item.sourcePath, canonical);
|
|
199
|
+
if (!result.ok) {
|
|
200
|
+
failed.push({ name, action: previous ? 'update' : 'add', error: resultError(result) });
|
|
147
201
|
continue;
|
|
148
202
|
}
|
|
149
|
-
|
|
203
|
+
applied = true;
|
|
204
|
+
} else {
|
|
205
|
+
preserved = true;
|
|
206
|
+
preservedModified.push(name);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
const effectiveDigest = hashDirectory(canonical);
|
|
210
|
+
if (!effectiveDigest) {
|
|
211
|
+
failed.push({ name, action: previous ? 'update' : 'add', error: 'Canonical Skill is unavailable' });
|
|
212
|
+
continue;
|
|
213
|
+
}
|
|
214
|
+
let linkFailed = false;
|
|
215
|
+
for (const target of targets(name)) {
|
|
216
|
+
const result = linkTarget(canonical, target);
|
|
150
217
|
if (!result.ok) {
|
|
151
|
-
|
|
152
|
-
|
|
218
|
+
linkFailed = true;
|
|
219
|
+
failed.push({ name, action: previous ? 'update' : 'add', error: resultError(result) });
|
|
153
220
|
}
|
|
154
|
-
targetBaselines[target] = entry.sourceDigest;
|
|
155
|
-
if (localDigest === undefined) installedTargets += 1;
|
|
156
|
-
else updatedTargets += 1;
|
|
157
221
|
}
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
222
|
+
if (linkFailed) continue;
|
|
223
|
+
registerDiscoveredCapability(workspaceDir, profile, {
|
|
224
|
+
type: 'skill',
|
|
225
|
+
path: canonical,
|
|
226
|
+
runtimeId: name,
|
|
227
|
+
title: name,
|
|
228
|
+
description: `Skill ${name}`,
|
|
229
|
+
selectedByHub: item.kind !== 'local',
|
|
230
|
+
...(item.kind === 'hub' && item.resourceId && item.versionId ? {
|
|
231
|
+
hub: {
|
|
232
|
+
resourceId: item.resourceId,
|
|
233
|
+
versionId: item.versionId,
|
|
234
|
+
publisher: item.publisher ?? 'community',
|
|
235
|
+
baseSha256: item.remoteDigest,
|
|
236
|
+
},
|
|
237
|
+
} : {}),
|
|
238
|
+
});
|
|
239
|
+
next.entries[name] = {
|
|
240
|
+
name,
|
|
241
|
+
kind: item.kind,
|
|
242
|
+
canonicalPath: canonical,
|
|
243
|
+
sourceDigest: preserved ? previous?.sourceDigest : sourceDigest,
|
|
244
|
+
remoteDigest: item.remoteDigest,
|
|
245
|
+
resourceId: item.resourceId,
|
|
246
|
+
versionId: item.versionId,
|
|
247
|
+
};
|
|
248
|
+
if (!previous) added.push(name);
|
|
249
|
+
else if (applied && previous.sourceDigest !== sourceDigest) updated.push(name);
|
|
250
|
+
else unchanged.push(name);
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
for (const [name] of Object.entries(current.entries)) {
|
|
254
|
+
if (desired.has(name)) continue;
|
|
255
|
+
let failedRemoval = false;
|
|
256
|
+
for (const target of targets(name)) {
|
|
257
|
+
const result = unlinkTarget(target);
|
|
258
|
+
if (!result.ok) {
|
|
259
|
+
failedRemoval = true;
|
|
260
|
+
failed.push({ name, action: 'remove', error: resultError(result) });
|
|
261
|
+
}
|
|
163
262
|
}
|
|
164
|
-
if (
|
|
263
|
+
if (!failedRemoval) removed.push(name);
|
|
165
264
|
}
|
|
166
265
|
|
|
167
|
-
writeManifest(workspaceDir, next);
|
|
266
|
+
writeManifest(workspaceDir, profile, next);
|
|
168
267
|
return {
|
|
169
268
|
added,
|
|
170
269
|
updated,
|
|
@@ -29,8 +29,11 @@ import {
|
|
|
29
29
|
getUserDataAccountHubBehaviorsDir,
|
|
30
30
|
getUserDataAccountHubPerceptionsDir,
|
|
31
31
|
getUserDataAccountHubPersonasDir,
|
|
32
|
-
getUserDataPersonaFile,
|
|
33
32
|
} from './user-data.js';
|
|
33
|
+
import {
|
|
34
|
+
capabilityEntryForHubResource,
|
|
35
|
+
capabilityWorkspacePath,
|
|
36
|
+
} from './capability-workspace.js';
|
|
34
37
|
|
|
35
38
|
const RESOURCE_TYPES: readonly ResourceType[] = ['skill', 'strategy', 'persona', 'perception'];
|
|
36
39
|
const SHA256 = /^[0-9a-f]{64}$/;
|
|
@@ -76,7 +79,7 @@ export interface LocalAgentWorkspaceItem {
|
|
|
76
79
|
|
|
77
80
|
export interface LocalAgentWorkspaceSnapshot {
|
|
78
81
|
metadataVersion?: 1;
|
|
79
|
-
layoutVersion?:
|
|
82
|
+
layoutVersion?: 3;
|
|
80
83
|
revision: number;
|
|
81
84
|
syncedAt: string;
|
|
82
85
|
relativeDir: string;
|
|
@@ -553,9 +556,7 @@ function inspectLocalSnapshot(
|
|
|
553
556
|
);
|
|
554
557
|
item.workingCopyPath = accountRelativePath(workspaceDir, profile, workingPath);
|
|
555
558
|
if (!existsSync(workingPath)) {
|
|
556
|
-
const legacyPath =
|
|
557
|
-
? getUserDataPersonaFile(workspaceDir, profile)
|
|
558
|
-
: projectionPath;
|
|
559
|
+
const legacyPath = projectionPath;
|
|
559
560
|
if (existsSync(legacyPath)) writeFileAtomically(workingPath, readFileSync(legacyPath));
|
|
560
561
|
}
|
|
561
562
|
}
|
|
@@ -672,7 +673,7 @@ export async function syncAgentWorkspaceConfig(
|
|
|
672
673
|
if (
|
|
673
674
|
previous?.revision === remote.revision
|
|
674
675
|
&& previous.metadataVersion === 1
|
|
675
|
-
&& previous.layoutVersion ===
|
|
676
|
+
&& previous.layoutVersion === 3
|
|
676
677
|
&& inspected?.projectionOutdated !== true
|
|
677
678
|
&& inspected?.workingMetadataMissing !== true
|
|
678
679
|
) {
|
|
@@ -708,13 +709,22 @@ export async function syncAgentWorkspaceConfig(
|
|
|
708
709
|
let workingPath: string | undefined;
|
|
709
710
|
let persistedWorkingMetadata: WorkingCopyMetadata | undefined;
|
|
710
711
|
if (type !== 'skill' && materialized.sourceFiles[0]) {
|
|
711
|
-
|
|
712
|
+
const workspaceType = type === 'strategy' ? 'behavior' : type;
|
|
713
|
+
const registered = capabilityEntryForHubResource(
|
|
712
714
|
workspaceDir,
|
|
713
715
|
profile,
|
|
714
|
-
|
|
716
|
+
workspaceType,
|
|
715
717
|
materialized.resourceId,
|
|
716
|
-
materialized.sourceFiles[0].relativePath,
|
|
717
718
|
);
|
|
719
|
+
workingPath = registered
|
|
720
|
+
? capabilityWorkspacePath(workspaceDir, profile, registered)
|
|
721
|
+
: hubWorkingCopyPath(
|
|
722
|
+
workspaceDir,
|
|
723
|
+
profile,
|
|
724
|
+
type,
|
|
725
|
+
materialized.resourceId,
|
|
726
|
+
materialized.sourceFiles[0].relativePath,
|
|
727
|
+
);
|
|
718
728
|
materialized.workingCopyPath = accountRelativePath(workspaceDir, profile, workingPath);
|
|
719
729
|
persistedWorkingMetadata = readWorkingCopyMetadata(
|
|
720
730
|
workingCopyMetadataPath(workspaceDir, profile, type, materialized.resourceId),
|
|
@@ -746,27 +756,6 @@ export async function syncAgentWorkspaceConfig(
|
|
|
746
756
|
};
|
|
747
757
|
}
|
|
748
758
|
}
|
|
749
|
-
if (
|
|
750
|
-
!override
|
|
751
|
-
&& !previous
|
|
752
|
-
&& type === 'persona'
|
|
753
|
-
&& existsSync(getUserDataPersonaFile(workspaceDir, profile))
|
|
754
|
-
&& materialized.sourceFiles[0]
|
|
755
|
-
) {
|
|
756
|
-
const personaBytes = readFileSync(getUserDataPersonaFile(workspaceDir, profile));
|
|
757
|
-
const personaSha = sha256(personaBytes);
|
|
758
|
-
if (personaBytes.toString('utf8').trim() && personaSha !== materialized.sourceFiles[0].sha256) {
|
|
759
|
-
override = {
|
|
760
|
-
bytes: personaBytes,
|
|
761
|
-
sha256: personaSha,
|
|
762
|
-
contentDigest: singleFileContentDigest(
|
|
763
|
-
materialized.sourceFiles[0].relativePath,
|
|
764
|
-
personaBytes,
|
|
765
|
-
),
|
|
766
|
-
modifiedAtMs: statSync(getUserDataPersonaFile(workspaceDir, profile)).mtimeMs,
|
|
767
|
-
};
|
|
768
|
-
}
|
|
769
|
-
}
|
|
770
759
|
let effectiveBytes: Buffer | undefined;
|
|
771
760
|
if (
|
|
772
761
|
override
|
|
@@ -830,7 +819,7 @@ export async function syncAgentWorkspaceConfig(
|
|
|
830
819
|
const relativeDir = `revision-${remote.revision}-${randomUUID()}`;
|
|
831
820
|
const snapshot: LocalAgentWorkspaceSnapshot = {
|
|
832
821
|
metadataVersion: 1,
|
|
833
|
-
layoutVersion:
|
|
822
|
+
layoutVersion: 3,
|
|
834
823
|
revision: remote.revision,
|
|
835
824
|
syncedAt: (dependencies.now ?? (() => new Date()))().toISOString(),
|
|
836
825
|
relativeDir,
|