@snap/valdi 1.0.8 → 1.1.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/.bootstrap/apps/cli_application/BUILD.bazel.template +7 -0
- package/.bootstrap/apps/cli_application/modules/{{MODULE_NAME}}/BUILD.bazel.template +11 -0
- package/.bootstrap/apps/cli_application/modules/{{MODULE_NAME}}/src/index.ts +1 -0
- package/.bootstrap/apps/ui_application/.eslint.rc +27 -0
- package/.bootstrap/apps/ui_application/BUILD.bazel.template +19 -0
- package/.bootstrap/apps/ui_application/modules/{{MODULE_NAME}}/BUILD.bazel.template +21 -0
- package/.bootstrap/apps/ui_application/modules/{{MODULE_NAME}}/res/valdi@3x.png +0 -0
- package/.bootstrap/apps/ui_application/modules/{{MODULE_NAME}}/src/App.tsx +133 -0
- package/.bootstrap/apps/ui_application/package.json +24 -0
- package/.bootstrap/modules/polyglot_bridge_module/BUILD.bazel.template +54 -0
- package/.bootstrap/modules/polyglot_bridge_module/android/CalculatorModuleFactory.kt.template +18 -0
- package/.bootstrap/modules/polyglot_bridge_module/ios/SCCCalculatorModuleFactory.m.template +31 -0
- package/.bootstrap/modules/polyglot_bridge_module/src/Calculator.d.ts +4 -0
- package/.bootstrap/modules/polyglot_bridge_module/web/Calculator.ts +11 -0
- package/.bootstrap/modules/polyglot_bridge_module/web/tsconfig.json +16 -0
- package/.bootstrap/modules/polyglot_view_module/BUILD.bazel.template +75 -0
- package/.bootstrap/modules/polyglot_view_module/android/PolyglotNativeView.kt.template +41 -0
- package/.bootstrap/modules/polyglot_view_module/android/PolyglotNativeViewAttributesBinder.kt.template +17 -0
- package/.bootstrap/modules/polyglot_view_module/ios/SCPolyglotView.h +8 -0
- package/.bootstrap/modules/polyglot_view_module/ios/SCPolyglotView.m +23 -0
- package/.bootstrap/modules/polyglot_view_module/macos/SCPolyglotView.h +8 -0
- package/.bootstrap/modules/polyglot_view_module/macos/SCPolyglotView.m +23 -0
- package/.bootstrap/modules/polyglot_view_module/src/PolyglotCustomView.tsx.template +23 -0
- package/.bootstrap/modules/polyglot_view_module/web/PolyglotWeb.ts.template +30 -0
- package/.bootstrap/modules/polyglot_view_module/web/tsconfig.json +16 -0
- package/.bootstrap/modules/ui_component/BUILD.bazel.template +34 -0
- package/.bootstrap/modules/ui_component/src/NewModuleComponent.tsx +45 -0
- package/.metadata/.bazelrc.template +92 -0
- package/.metadata/.bazelversion.template +1 -0
- package/.metadata/.editorconfig.template +37 -0
- package/.metadata/.eslintrc.js.template +27 -0
- package/.metadata/.gitignore.template +4 -0
- package/.metadata/.prettierrc.json.template +7 -0
- package/.metadata/.watchmanconfig.template +8 -0
- package/.metadata/AGENTS.md.template +16 -0
- package/.metadata/MODULE.bazel.template +62 -0
- package/.metadata/README.md.template +31 -0
- package/.metadata/config.yaml.template +1 -0
- package/.metadata/package.json.template +23 -0
- package/.metadata/skill-reference.tsx.template +8 -0
- package/.metadata/skill-tests-BUILD.bazel.template +21 -0
- package/.metadata/skill-tests-README.md.template +17 -0
- package/.metadata/skill.md.template +27 -0
- package/bundled-skills/registry.json +14 -2
- package/bundled-skills/skills/valdi-animations/skill.md +197 -0
- package/bundled-skills/skills/valdi-async/tests/src/reference.tsx +1 -1
- package/bundled-skills/skills/valdi-bazel/skill.md +21 -2
- package/bundled-skills/skills/valdi-component-dedup/skill.md +263 -0
- package/bundled-skills/skills/valdi-component-tests/tests/test/ProfileCardTest.spec.tsx +1 -1
- package/bundled-skills/skills/valdi-custom-view/skill.md +49 -5
- package/bundled-skills/skills/valdi-error-handling/skill.md +238 -0
- package/bundled-skills/skills/valdi-gestures/skill.md +198 -0
- package/bundled-skills/skills/valdi-inspect/skill.md +217 -0
- package/bundled-skills/skills/valdi-localization/skill.md +142 -0
- package/bundled-skills/skills/valdi-mock-breakdown/skill.md +327 -0
- package/bundled-skills/skills/valdi-mock-iterate/skill.md +216 -0
- package/bundled-skills/skills/valdi-mock-to-module/scripts/diff.py +392 -0
- package/bundled-skills/skills/valdi-mock-to-module/scripts/extract_colors.py +277 -0
- package/bundled-skills/skills/valdi-mock-to-module/scripts/find_icon.py +303 -0
- package/bundled-skills/skills/valdi-mock-to-module/scripts/snapshot-and-diff.sh +53 -0
- package/bundled-skills/skills/valdi-mock-to-module/scripts/test_diff.py +207 -0
- package/bundled-skills/skills/valdi-mock-to-module/scripts/test_extract_colors.py +167 -0
- package/bundled-skills/skills/valdi-mock-to-module/scripts/test_find_icon.py +188 -0
- package/bundled-skills/skills/valdi-mock-to-module/scripts/watch-and-diff.sh +181 -0
- package/bundled-skills/skills/valdi-mock-to-module/skill.md +451 -0
- package/bundled-skills/skills/valdi-navigation/skill.md +187 -0
- package/bundled-skills/skills/valdi-overview/skill.md +7 -4
- package/bundled-skills/skills/valdi-perf/skill.md +223 -0
- package/bundled-skills/skills/valdi-polyglot-module/skill.md +131 -12
- package/bundled-skills/skills/valdi-preview/skill.md +303 -0
- package/bundled-skills/skills/valdi-profile/skill.md +126 -0
- package/bundled-skills/skills/valdi-setup/skill.md +55 -5
- package/bundled-skills/skills/valdi-testing/skill.md +23 -7
- package/bundled-skills/skills/valdi-tsx/skill.md +69 -5
- package/bundled-skills/skills/valdi-tsx/tests/src/reference.tsx +29 -5
- package/dist/commands/agentCheck.js +184 -0
- package/dist/commands/analyze.js +16 -0
- package/dist/commands/analyze_commands/duplicates.js +134 -0
- package/dist/commands/bootstrap.js +57 -73
- package/dist/commands/doctor.js +40 -203
- package/dist/commands/hotreload.js +15 -0
- package/dist/commands/inspect.js +16 -0
- package/dist/commands/inspect_commands/contexts.js +55 -0
- package/dist/commands/inspect_commands/devices.js +53 -0
- package/dist/commands/inspect_commands/heap.js +59 -0
- package/dist/commands/inspect_commands/select.js +43 -0
- package/dist/commands/inspect_commands/snapshot.js +129 -0
- package/dist/commands/inspect_commands/snapshot.spec.js +105 -0
- package/dist/commands/inspect_commands/status.js +68 -0
- package/dist/commands/inspect_commands/tree.js +86 -0
- package/dist/commands/preview.js +81 -0
- package/dist/commands/profile.js +16 -0
- package/dist/commands/profile_commands/capture.js +106 -0
- package/dist/commands/projectsync.js +9 -7
- package/dist/commands/skills_commands/install.js +6 -1
- package/dist/commands/skills_commands/update.js +2 -1
- package/dist/core/analyze/clusterer.js +150 -0
- package/dist/core/analyze/fingerprint.js +2 -0
- package/dist/core/analyze/knownPatterns.js +76 -0
- package/dist/core/analyze/parser.js +177 -0
- package/dist/core/analyze/reporter.js +83 -0
- package/dist/core/analyze/scanner.js +172 -0
- package/dist/core/analyze/similarity.js +56 -0
- package/dist/core/constants.js +1 -1
- package/dist/core/packageFiles.spec.js +29 -0
- package/dist/preview/previewGenerator.js +240 -0
- package/dist/preview/previewGenerator.spec.js +203 -0
- package/dist/preview/viewModelParser.js +86 -0
- package/dist/preview/viewModelParser.spec.js +171 -0
- package/dist/setup/DevSetupHelper.js +0 -51
- package/dist/setup/linuxSetup.js +0 -2
- package/dist/setup/macOSSetup.js +1 -4
- package/dist/utils/BazelClient.js +15 -0
- package/dist/utils/daemonClient.js +344 -0
- package/dist/utils/hermesClient.js +252 -0
- package/dist/utils/skillsAdapters.js +86 -5
- package/dist/utils/skillsAdapters.spec.js +60 -0
- package/dist/utils/skillsRegistry.js +8 -0
- package/dist/utils/stringUtils.spec.js +1 -1
- package/package.json +30 -12
- package/dist/setup/versions.js +0 -8
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HermesConnection = exports.NotHermesError = exports.HERMES_BUILD_FLAG = exports.HERMES_PORT = void 0;
|
|
4
|
+
exports.listHermesDevices = listHermesDevices;
|
|
5
|
+
exports.normalizeHermesProfile = normalizeHermesProfile;
|
|
6
|
+
const tslib_1 = require("tslib");
|
|
7
|
+
const net = tslib_1.__importStar(require("net"));
|
|
8
|
+
const crypto = tslib_1.__importStar(require("crypto"));
|
|
9
|
+
const http = tslib_1.__importStar(require("http"));
|
|
10
|
+
const errors_1 = require("../core/errors");
|
|
11
|
+
exports.HERMES_PORT = 13595;
|
|
12
|
+
exports.HERMES_BUILD_FLAG = '--@valdi//bzl/valdi:js_engine=hermes --@valdi//bzl/valdi:js_bytecode_format=hermes';
|
|
13
|
+
class NotHermesError extends errors_1.CliError {
|
|
14
|
+
constructor(port) {
|
|
15
|
+
super(`Hermes debug socket not found on port ${port}.\n\n` +
|
|
16
|
+
`CPU profiling requires:\n` +
|
|
17
|
+
` 1. A Hermes build (the default JS engine is QuickJS):\n` +
|
|
18
|
+
` valdi install android --bazel_args="${exports.HERMES_BUILD_FLAG}"\n` +
|
|
19
|
+
` valdi install ios --bazel_args="${exports.HERMES_BUILD_FLAG}"\n\n` +
|
|
20
|
+
` 2. The hot-reloader running (it establishes the debug tunnel on port ${port}):\n` +
|
|
21
|
+
` valdi hotreload android\n`);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.NotHermesError = NotHermesError;
|
|
25
|
+
async function listHermesDevices(port) {
|
|
26
|
+
return new Promise((resolve, reject) => {
|
|
27
|
+
const timer = setTimeout(() => {
|
|
28
|
+
req.destroy();
|
|
29
|
+
reject(new NotHermesError(port));
|
|
30
|
+
}, 3_000);
|
|
31
|
+
const req = http.get(`http://127.0.0.1:${port}/json`, (res) => {
|
|
32
|
+
let body = '';
|
|
33
|
+
res.on('data', (chunk) => { body += chunk; });
|
|
34
|
+
res.on('end', () => {
|
|
35
|
+
clearTimeout(timer);
|
|
36
|
+
try {
|
|
37
|
+
resolve(JSON.parse(body));
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
reject(new errors_1.CliError(`Invalid response from Hermes debug server on port ${port}`));
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
req.on('error', (err) => {
|
|
45
|
+
clearTimeout(timer);
|
|
46
|
+
if (err.code === 'ECONNREFUSED') {
|
|
47
|
+
reject(new NotHermesError(port));
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
reject(err);
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
function encodeWsFrame(text) {
|
|
56
|
+
const payload = Buffer.from(text, 'utf8');
|
|
57
|
+
const mask = crypto.randomBytes(4);
|
|
58
|
+
const masked = Buffer.alloc(payload.length);
|
|
59
|
+
for (let i = 0; i < payload.length; i++) {
|
|
60
|
+
masked[i] = payload[i] ^ mask[i % 4];
|
|
61
|
+
}
|
|
62
|
+
const len = payload.length;
|
|
63
|
+
let header;
|
|
64
|
+
if (len < 126) {
|
|
65
|
+
header = Buffer.alloc(6);
|
|
66
|
+
header[0] = 0x81;
|
|
67
|
+
header[1] = 0x80 | len;
|
|
68
|
+
mask.copy(header, 2);
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
header = Buffer.alloc(8);
|
|
72
|
+
header[0] = 0x81;
|
|
73
|
+
header[1] = 0x80 | 126;
|
|
74
|
+
header.writeUInt16BE(len, 2);
|
|
75
|
+
mask.copy(header, 4);
|
|
76
|
+
}
|
|
77
|
+
return Buffer.concat([header, masked]);
|
|
78
|
+
}
|
|
79
|
+
function normalizeHermesProfile(profile) {
|
|
80
|
+
const { samples = [], timeDeltas = [], startTime, endTime, nodes } = profile;
|
|
81
|
+
if (samples.length < 2 || timeDeltas.length < 2)
|
|
82
|
+
return profile;
|
|
83
|
+
const absTimes = [];
|
|
84
|
+
let t = startTime;
|
|
85
|
+
for (const d of timeDeltas) {
|
|
86
|
+
t += d;
|
|
87
|
+
absTimes.push(t);
|
|
88
|
+
}
|
|
89
|
+
const realStart = absTimes[1];
|
|
90
|
+
const realAbsTimes = absTimes.slice(1);
|
|
91
|
+
const realSamples = samples.slice(1);
|
|
92
|
+
const newDeltas = [0];
|
|
93
|
+
for (let i = 1; i < realAbsTimes.length; i++) {
|
|
94
|
+
newDeltas.push(realAbsTimes[i] - realAbsTimes[i - 1]);
|
|
95
|
+
}
|
|
96
|
+
return { nodes, startTime: realStart, endTime, samples: realSamples, timeDeltas: newDeltas };
|
|
97
|
+
}
|
|
98
|
+
class HermesConnection {
|
|
99
|
+
socket;
|
|
100
|
+
recvBuf = Buffer.alloc(0);
|
|
101
|
+
callId = 0;
|
|
102
|
+
pending = new Map();
|
|
103
|
+
constructor(socket) {
|
|
104
|
+
this.socket = socket;
|
|
105
|
+
socket.on('data', (chunk) => this.onData(chunk));
|
|
106
|
+
socket.on('close', () => {
|
|
107
|
+
this.rejectAll(new Error('Hermes debug WebSocket closed unexpectedly'));
|
|
108
|
+
});
|
|
109
|
+
socket.on('error', (err) => this.rejectAll(err));
|
|
110
|
+
}
|
|
111
|
+
static connect(port, deviceId) {
|
|
112
|
+
return new Promise((resolve, reject) => {
|
|
113
|
+
const socket = net.createConnection({ port, host: '127.0.0.1' });
|
|
114
|
+
const timer = setTimeout(() => {
|
|
115
|
+
socket.destroy();
|
|
116
|
+
reject(new errors_1.CliError(`Timeout connecting to Hermes debug socket on port ${port}.\n` +
|
|
117
|
+
`Make sure the Valdi app is running and the hot-reloader is active.`));
|
|
118
|
+
}, 5_000);
|
|
119
|
+
socket.once('error', (err) => {
|
|
120
|
+
clearTimeout(timer);
|
|
121
|
+
if (err.code === 'ECONNREFUSED') {
|
|
122
|
+
reject(new NotHermesError(port));
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
reject(err);
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
socket.once('connect', () => {
|
|
129
|
+
const key = crypto.randomBytes(16).toString('base64');
|
|
130
|
+
const handshake = `GET /${deviceId} HTTP/1.1\r\n` +
|
|
131
|
+
`Host: localhost:${port}\r\n` +
|
|
132
|
+
`Upgrade: websocket\r\n` +
|
|
133
|
+
`Connection: Upgrade\r\n` +
|
|
134
|
+
`Sec-WebSocket-Key: ${key}\r\n` +
|
|
135
|
+
`Sec-WebSocket-Version: 13\r\n` +
|
|
136
|
+
`\r\n`;
|
|
137
|
+
socket.write(handshake);
|
|
138
|
+
let handshakeBuf = '';
|
|
139
|
+
const onHandshakeData = (chunk) => {
|
|
140
|
+
handshakeBuf += chunk.toString('utf8');
|
|
141
|
+
if (handshakeBuf.includes('\r\n\r\n')) {
|
|
142
|
+
socket.removeListener('data', onHandshakeData);
|
|
143
|
+
clearTimeout(timer);
|
|
144
|
+
if (!handshakeBuf.includes('101 Switching Protocols')) {
|
|
145
|
+
socket.destroy();
|
|
146
|
+
reject(new errors_1.CliError(`Hermes WebSocket handshake failed: ${handshakeBuf.slice(0, 100)}`));
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
resolve(new HermesConnection(socket));
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
socket.on('data', onHandshakeData);
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
call(method, params = {}, timeoutMs = 10_000) {
|
|
157
|
+
const id = ++this.callId;
|
|
158
|
+
return new Promise((resolve, reject) => {
|
|
159
|
+
const timer = setTimeout(() => {
|
|
160
|
+
this.pending.delete(id);
|
|
161
|
+
reject(new Error(`Timeout waiting for response to ${method}`));
|
|
162
|
+
}, timeoutMs);
|
|
163
|
+
this.pending.set(id, {
|
|
164
|
+
resolve: (v) => { clearTimeout(timer); resolve(v); },
|
|
165
|
+
reject: (e) => { clearTimeout(timer); reject(e); },
|
|
166
|
+
});
|
|
167
|
+
this.socket.write(encodeWsFrame(JSON.stringify({ id, method, params })));
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
async startProfiling() {
|
|
171
|
+
await this.call('Profiler.start');
|
|
172
|
+
}
|
|
173
|
+
async stopProfiling() {
|
|
174
|
+
const result = await this.call('Profiler.stop', {}, 60_000);
|
|
175
|
+
return normalizeHermesProfile(result.profile);
|
|
176
|
+
}
|
|
177
|
+
close() {
|
|
178
|
+
this.socket.destroy();
|
|
179
|
+
}
|
|
180
|
+
rejectAll(err) {
|
|
181
|
+
for (const pending of this.pending.values())
|
|
182
|
+
pending.reject(err);
|
|
183
|
+
this.pending.clear();
|
|
184
|
+
}
|
|
185
|
+
onData(chunk) {
|
|
186
|
+
this.recvBuf = Buffer.concat([this.recvBuf, chunk]);
|
|
187
|
+
this.drainBuffer();
|
|
188
|
+
}
|
|
189
|
+
drainBuffer() {
|
|
190
|
+
for (;;) {
|
|
191
|
+
if (this.recvBuf.length < 2)
|
|
192
|
+
break;
|
|
193
|
+
const firstByte = this.recvBuf[0];
|
|
194
|
+
const secondByte = this.recvBuf[1];
|
|
195
|
+
const opcode = firstByte & 0x0f;
|
|
196
|
+
if (opcode === 0x08) {
|
|
197
|
+
this.rejectAll(new Error('Hermes debug WebSocket closed by server'));
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
const isMasked = (secondByte & 0x80) !== 0;
|
|
201
|
+
let payloadLen = secondByte & 0x7f;
|
|
202
|
+
let offset = 2;
|
|
203
|
+
if (payloadLen === 126) {
|
|
204
|
+
if (this.recvBuf.length < 4)
|
|
205
|
+
break;
|
|
206
|
+
payloadLen = this.recvBuf.readUInt16BE(2);
|
|
207
|
+
offset = 4;
|
|
208
|
+
}
|
|
209
|
+
else if (payloadLen === 127) {
|
|
210
|
+
if (this.recvBuf.length < 10)
|
|
211
|
+
break;
|
|
212
|
+
payloadLen = this.recvBuf.readUInt32BE(6);
|
|
213
|
+
offset = 10;
|
|
214
|
+
}
|
|
215
|
+
const maskLen = isMasked ? 4 : 0;
|
|
216
|
+
const totalLen = offset + maskLen + payloadLen;
|
|
217
|
+
if (this.recvBuf.length < totalLen)
|
|
218
|
+
break;
|
|
219
|
+
if (opcode !== 0x01 && opcode !== 0x02) {
|
|
220
|
+
this.recvBuf = this.recvBuf.subarray(totalLen);
|
|
221
|
+
continue;
|
|
222
|
+
}
|
|
223
|
+
let payload = this.recvBuf.subarray(offset + maskLen, totalLen);
|
|
224
|
+
if (isMasked) {
|
|
225
|
+
const mask = this.recvBuf.subarray(offset, offset + 4);
|
|
226
|
+
payload = Buffer.from(payload.map((b, i) => b ^ mask[i % 4]));
|
|
227
|
+
}
|
|
228
|
+
this.recvBuf = this.recvBuf.subarray(totalLen);
|
|
229
|
+
try {
|
|
230
|
+
this.dispatchMessage(JSON.parse(payload.toString('utf8')));
|
|
231
|
+
}
|
|
232
|
+
catch {
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
dispatchMessage(msg) {
|
|
237
|
+
if (typeof msg['id'] !== 'number')
|
|
238
|
+
return;
|
|
239
|
+
const pending = this.pending.get(msg['id']);
|
|
240
|
+
if (!pending)
|
|
241
|
+
return;
|
|
242
|
+
this.pending.delete(msg['id']);
|
|
243
|
+
if (msg['error']) {
|
|
244
|
+
const err = msg['error'];
|
|
245
|
+
pending.reject(new Error(String(err['message'] ?? 'Unknown CDP error')));
|
|
246
|
+
}
|
|
247
|
+
else {
|
|
248
|
+
pending.resolve(msg['result']);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
exports.HermesConnection = HermesConnection;
|
|
@@ -1,32 +1,113 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ALL_ADAPTERS = void 0;
|
|
3
|
+
exports.ALL_ADAPTERS = exports.conflictingClaudePluginKeys = void 0;
|
|
4
4
|
exports.detectAdapters = detectAdapters;
|
|
5
5
|
exports.getAdapterByName = getAdapterByName;
|
|
6
6
|
const tslib_1 = require("tslib");
|
|
7
7
|
const fs = tslib_1.__importStar(require("fs"));
|
|
8
8
|
const path = tslib_1.__importStar(require("path"));
|
|
9
9
|
const os = tslib_1.__importStar(require("os"));
|
|
10
|
+
function copyDirSync(src, dst) {
|
|
11
|
+
fs.mkdirSync(dst, { recursive: true });
|
|
12
|
+
for (const entry of fs.readdirSync(src, { withFileTypes: true })) {
|
|
13
|
+
if (entry.name.startsWith('test_') || entry.name.endsWith('.spec.ts') || entry.name === '__pycache__') {
|
|
14
|
+
continue;
|
|
15
|
+
}
|
|
16
|
+
const srcEntry = path.join(src, entry.name);
|
|
17
|
+
const dstEntry = path.join(dst, entry.name);
|
|
18
|
+
if (entry.isDirectory()) {
|
|
19
|
+
copyDirSync(srcEntry, dstEntry);
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
fs.copyFileSync(srcEntry, dstEntry);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.conflictingClaudePluginKeys = [];
|
|
27
|
+
function getClaudeSkillsDir() {
|
|
28
|
+
return path.join(os.homedir(), '.claude', 'skills');
|
|
29
|
+
}
|
|
30
|
+
function cleanupLegacyPluginArtifacts() {
|
|
31
|
+
const claudeDir = path.join(os.homedir(), '.claude');
|
|
32
|
+
const valdiPluginDir = path.join(claudeDir, 'plugins', 'local', 'valdi');
|
|
33
|
+
if (fs.existsSync(valdiPluginDir)) {
|
|
34
|
+
fs.rmSync(valdiPluginDir, { recursive: true, force: true });
|
|
35
|
+
}
|
|
36
|
+
const valdiCacheDir = path.join(claudeDir, 'plugins', 'cache', 'local', 'valdi');
|
|
37
|
+
if (fs.existsSync(valdiCacheDir)) {
|
|
38
|
+
fs.rmSync(valdiCacheDir, { recursive: true, force: true });
|
|
39
|
+
}
|
|
40
|
+
const installedPath = path.join(claudeDir, 'plugins', 'installed_plugins.json');
|
|
41
|
+
if (fs.existsSync(installedPath)) {
|
|
42
|
+
try {
|
|
43
|
+
const data = JSON.parse(fs.readFileSync(installedPath, 'utf8'));
|
|
44
|
+
if (Array.isArray(data)) {
|
|
45
|
+
const filtered = data.filter((entry) => !entry.key?.startsWith('valdi'));
|
|
46
|
+
if (filtered.length !== data.length) {
|
|
47
|
+
fs.writeFileSync(installedPath, JSON.stringify(filtered, null, 2), 'utf8');
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
const settingsPath = path.join(claudeDir, 'settings.json');
|
|
55
|
+
if (fs.existsSync(settingsPath)) {
|
|
56
|
+
try {
|
|
57
|
+
const settings = JSON.parse(fs.readFileSync(settingsPath, 'utf8'));
|
|
58
|
+
let changed = false;
|
|
59
|
+
if (Array.isArray(settings.enabledPlugins)) {
|
|
60
|
+
const before = settings.enabledPlugins.length;
|
|
61
|
+
settings.enabledPlugins = settings.enabledPlugins.filter((p) => !p.includes('valdi'));
|
|
62
|
+
if (settings.enabledPlugins.length === 0)
|
|
63
|
+
delete settings.enabledPlugins;
|
|
64
|
+
if ((settings.enabledPlugins?.length ?? 0) !== before)
|
|
65
|
+
changed = true;
|
|
66
|
+
}
|
|
67
|
+
if (Array.isArray(settings.extraKnownMarketplaces)) {
|
|
68
|
+
const before = settings.extraKnownMarketplaces.length;
|
|
69
|
+
settings.extraKnownMarketplaces = settings.extraKnownMarketplaces.filter((m) => m.name !== 'local');
|
|
70
|
+
if (settings.extraKnownMarketplaces.length === 0)
|
|
71
|
+
delete settings.extraKnownMarketplaces;
|
|
72
|
+
if ((settings.extraKnownMarketplaces?.length ?? 0) !== before)
|
|
73
|
+
changed = true;
|
|
74
|
+
}
|
|
75
|
+
if (changed) {
|
|
76
|
+
fs.writeFileSync(settingsPath, JSON.stringify(settings, null, 2), 'utf8');
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
catch {
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
10
83
|
const ClaudeCodeAdapter = {
|
|
11
84
|
name: 'claude',
|
|
12
85
|
detect() {
|
|
13
86
|
const claudeDir = path.join(os.homedir(), '.claude');
|
|
14
87
|
return fs.existsSync(claudeDir);
|
|
15
88
|
},
|
|
16
|
-
install(skillName, content, meta) {
|
|
17
|
-
|
|
89
|
+
install(skillName, content, meta, resourceDir) {
|
|
90
|
+
cleanupLegacyPluginArtifacts();
|
|
91
|
+
const skillDir = path.join(getClaudeSkillsDir(), skillName);
|
|
18
92
|
fs.mkdirSync(skillDir, { recursive: true });
|
|
19
93
|
const frontmatter = `---\nname: ${meta.name}\ndescription: ${meta.description}\n---\n\n`;
|
|
20
94
|
fs.writeFileSync(path.join(skillDir, 'SKILL.md'), frontmatter + content, 'utf8');
|
|
95
|
+
if (resourceDir) {
|
|
96
|
+
for (const entry of fs.readdirSync(resourceDir, { withFileTypes: true })) {
|
|
97
|
+
if (entry.isDirectory()) {
|
|
98
|
+
copyDirSync(path.join(resourceDir, entry.name), path.join(skillDir, entry.name));
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
21
102
|
},
|
|
22
103
|
remove(skillName) {
|
|
23
|
-
const skillDir = path.join(
|
|
104
|
+
const skillDir = path.join(getClaudeSkillsDir(), skillName);
|
|
24
105
|
if (fs.existsSync(skillDir)) {
|
|
25
106
|
fs.rmSync(skillDir, { recursive: true, force: true });
|
|
26
107
|
}
|
|
27
108
|
},
|
|
28
109
|
listInstalled() {
|
|
29
|
-
const skillsDir =
|
|
110
|
+
const skillsDir = getClaudeSkillsDir();
|
|
30
111
|
if (!fs.existsSync(skillsDir))
|
|
31
112
|
return [];
|
|
32
113
|
return fs
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
require("jasmine");
|
|
5
|
+
const fs = tslib_1.__importStar(require("fs"));
|
|
6
|
+
const path = tslib_1.__importStar(require("path"));
|
|
7
|
+
const os = tslib_1.__importStar(require("os"));
|
|
8
|
+
const skillsAdapters_1 = require("./skillsAdapters");
|
|
9
|
+
describe('ClaudeCodeAdapter', () => {
|
|
10
|
+
let tmpHome;
|
|
11
|
+
let origHome;
|
|
12
|
+
beforeEach(() => {
|
|
13
|
+
tmpHome = fs.mkdtempSync(path.join(os.tmpdir(), 'valdi-test-'));
|
|
14
|
+
origHome = process.env['HOME'];
|
|
15
|
+
process.env['HOME'] = tmpHome;
|
|
16
|
+
fs.mkdirSync(path.join(tmpHome, '.claude'), { recursive: true });
|
|
17
|
+
});
|
|
18
|
+
afterEach(() => {
|
|
19
|
+
process.env['HOME'] = origHome;
|
|
20
|
+
fs.rmSync(tmpHome, { recursive: true, force: true });
|
|
21
|
+
});
|
|
22
|
+
function getAdapter() {
|
|
23
|
+
const adapter = (0, skillsAdapters_1.getAdapterByName)('claude');
|
|
24
|
+
expect(adapter).toBeDefined();
|
|
25
|
+
return adapter;
|
|
26
|
+
}
|
|
27
|
+
it('writes SKILL.md with frontmatter to ~/.claude/skills/', () => {
|
|
28
|
+
const adapter = getAdapter();
|
|
29
|
+
adapter.install('my-skill', '# My content', { name: 'my-skill', description: 'Desc', tags: [], path: '', category: [] });
|
|
30
|
+
const skillPath = path.join(tmpHome, '.claude', 'skills', 'my-skill', 'SKILL.md');
|
|
31
|
+
expect(fs.existsSync(skillPath)).toBe(true);
|
|
32
|
+
const content = fs.readFileSync(skillPath, 'utf8');
|
|
33
|
+
expect(content).toContain('name: my-skill');
|
|
34
|
+
expect(content).toContain('description: Desc');
|
|
35
|
+
expect(content).toContain('# My content');
|
|
36
|
+
});
|
|
37
|
+
it('does not modify settings.json', () => {
|
|
38
|
+
const settingsFile = path.join(tmpHome, '.claude', 'settings.json');
|
|
39
|
+
fs.writeFileSync(settingsFile, JSON.stringify({ model: 'claude-opus-4-6' }), 'utf8');
|
|
40
|
+
const adapter = getAdapter();
|
|
41
|
+
adapter.install('test-skill', '# Content', { name: 'test-skill', description: 'Desc', tags: [], path: '', category: [] });
|
|
42
|
+
const settings = JSON.parse(fs.readFileSync(settingsFile, 'utf8'));
|
|
43
|
+
expect(settings).toEqual({ model: 'claude-opus-4-6' });
|
|
44
|
+
});
|
|
45
|
+
it('lists installed skills', () => {
|
|
46
|
+
const adapter = getAdapter();
|
|
47
|
+
adapter.install('skill-a', '# A', { name: 'skill-a', description: 'A', tags: [], path: '', category: [] });
|
|
48
|
+
adapter.install('skill-b', '# B', { name: 'skill-b', description: 'B', tags: [], path: '', category: [] });
|
|
49
|
+
const installed = adapter.listInstalled();
|
|
50
|
+
expect(installed).toContain('skill-a');
|
|
51
|
+
expect(installed).toContain('skill-b');
|
|
52
|
+
});
|
|
53
|
+
it('removes a skill', () => {
|
|
54
|
+
const adapter = getAdapter();
|
|
55
|
+
adapter.install('to-remove', '# Remove me', { name: 'to-remove', description: 'R', tags: [], path: '', category: [] });
|
|
56
|
+
expect(adapter.listInstalled()).toContain('to-remove');
|
|
57
|
+
adapter.remove('to-remove');
|
|
58
|
+
expect(adapter.listInstalled()).not.toContain('to-remove');
|
|
59
|
+
});
|
|
60
|
+
});
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.loadLocalRegistry = loadLocalRegistry;
|
|
4
4
|
exports.fetchRegistry = fetchRegistry;
|
|
5
5
|
exports.fetchSkillContent = fetchSkillContent;
|
|
6
|
+
exports.getSkillResourceDir = getSkillResourceDir;
|
|
6
7
|
const tslib_1 = require("tslib");
|
|
7
8
|
const path = tslib_1.__importStar(require("path"));
|
|
8
9
|
const fs = tslib_1.__importStar(require("fs"));
|
|
@@ -38,3 +39,10 @@ async function fetchSkillContent(skillPath) {
|
|
|
38
39
|
}
|
|
39
40
|
throw new Error(`Skill content not found for "${skillPath}". Re-install @snap/valdi to get the latest bundle.`);
|
|
40
41
|
}
|
|
42
|
+
function getSkillResourceDir(skillPath) {
|
|
43
|
+
const bundledDir = findBundledSkillsDir();
|
|
44
|
+
if (bundledDir == null)
|
|
45
|
+
return null;
|
|
46
|
+
const dir = path.join(bundledDir, path.dirname(skillPath));
|
|
47
|
+
return fs.existsSync(dir) ? dir : null;
|
|
48
|
+
}
|
|
@@ -75,7 +75,7 @@ describe('stringUtils', () => {
|
|
|
75
75
|
expect((0, stringUtils_1.validateProjectName)('@#$')).toBeTruthy();
|
|
76
76
|
});
|
|
77
77
|
it('handles names that start with numbers', () => {
|
|
78
|
-
expect((0, stringUtils_1.validateProjectName)('123project')).
|
|
78
|
+
expect((0, stringUtils_1.validateProjectName)('123project')).toContain('sanitized');
|
|
79
79
|
});
|
|
80
80
|
});
|
|
81
81
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@snap/valdi",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.5",
|
|
4
4
|
"description": "Valdi CLI tools for developers",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -8,19 +8,23 @@
|
|
|
8
8
|
"url": "https://github.com/Snapchat/Valdi.git",
|
|
9
9
|
"directory": "npm_modules/cli"
|
|
10
10
|
},
|
|
11
|
-
"publishConfig": {
|
|
11
|
+
"publishConfig": {
|
|
12
|
+
"access": "public"
|
|
13
|
+
},
|
|
12
14
|
"bin": {
|
|
13
15
|
"valdi": "dist/index.js"
|
|
14
16
|
},
|
|
15
17
|
"files": [
|
|
16
18
|
"dist",
|
|
17
|
-
"bundled-skills"
|
|
19
|
+
"bundled-skills",
|
|
20
|
+
".metadata",
|
|
21
|
+
".bootstrap"
|
|
18
22
|
],
|
|
19
23
|
"scripts": {
|
|
20
24
|
"prepare": "npm run build",
|
|
21
25
|
"prebuild": "node scripts/bundle-skills.js",
|
|
22
26
|
"build": "npm exec --package=typescript@5.9.2 tsc -- --project ./tsconfig.dist.json",
|
|
23
|
-
"test": "
|
|
27
|
+
"test": "tsx node_modules/jasmine/bin/jasmine",
|
|
24
28
|
"watch": "tsc --watch",
|
|
25
29
|
"main": "ts-node ./src/index.ts",
|
|
26
30
|
"format": "prettier --ignore-path .gitignore --write \"**/*.+(js|ts|json)\"",
|
|
@@ -36,11 +40,6 @@
|
|
|
36
40
|
"@bazel/bazelisk": "^1.19.0",
|
|
37
41
|
"@types/inquirer": "^9.0.7",
|
|
38
42
|
"@types/yargs": "^17.0.32",
|
|
39
|
-
"@typescript-eslint/eslint-plugin": "^5.59.9",
|
|
40
|
-
"eslint": "^8.42.0",
|
|
41
|
-
"eslint-config-prettier": "^8.8.0",
|
|
42
|
-
"eslint-plugin-import": "^2.27.5",
|
|
43
|
-
"eslint-plugin-unicorn": "^47.0.0",
|
|
44
43
|
"extract-zip": "^2.0.1",
|
|
45
44
|
"glob": "^11.0.1",
|
|
46
45
|
"inquirer": "^8.0.0",
|
|
@@ -48,17 +47,36 @@
|
|
|
48
47
|
"ora": "^8.2.0",
|
|
49
48
|
"prettier": "^3.3.1",
|
|
50
49
|
"tslib": "^2.5.3",
|
|
51
|
-
"typescript": "^5.3.3",
|
|
52
50
|
"yaml": "^2.4.5",
|
|
53
51
|
"yargs": "^17.7.2"
|
|
54
52
|
},
|
|
53
|
+
"peerDependencies": {
|
|
54
|
+
"@typescript-eslint/eslint-plugin": "^5.59.9",
|
|
55
|
+
"eslint": "^8.42.0",
|
|
56
|
+
"eslint-config-prettier": "^8.8.0",
|
|
57
|
+
"eslint-plugin-import": "^2.27.5",
|
|
58
|
+
"eslint-plugin-unicorn": "^47.0.0",
|
|
59
|
+
"typescript": "^5.3.3"
|
|
60
|
+
},
|
|
55
61
|
"devDependencies": {
|
|
56
62
|
"@types/eslint": "^9.6.1",
|
|
57
63
|
"@types/jasmine": "^5.1.7",
|
|
64
|
+
"@typescript-eslint/eslint-plugin": "^5.59.9",
|
|
65
|
+
"eslint": "^8.42.0",
|
|
66
|
+
"eslint-config-prettier": "^8.8.0",
|
|
67
|
+
"eslint-plugin-import": "^2.27.5",
|
|
68
|
+
"eslint-plugin-unicorn": "^47.0.0",
|
|
58
69
|
"jasmine": "^5.6.0",
|
|
59
|
-
"ts-node": "^10.9.2"
|
|
70
|
+
"ts-node": "^10.9.2",
|
|
71
|
+
"tsx": "^4.19.0",
|
|
72
|
+
"typescript": "^5.3.3"
|
|
60
73
|
},
|
|
61
74
|
"overrides": {
|
|
62
|
-
"
|
|
75
|
+
"minimatch@3": {
|
|
76
|
+
"brace-expansion": "2.0.2"
|
|
77
|
+
},
|
|
78
|
+
"minimatch@9": {
|
|
79
|
+
"brace-expansion": "2.0.2"
|
|
80
|
+
}
|
|
63
81
|
}
|
|
64
82
|
}
|
package/dist/setup/versions.js
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ANDROID_LINUX_COMMANDLINE_TOOLS = exports.ANDROID_MACOS_COMMANDLINE_TOOLS = exports.ANDROID_PLATFORM_VERSION = exports.ANDROID_NDK_VERSION = exports.ANDROID_BUILD_TOOLS_VERSION = void 0;
|
|
4
|
-
exports.ANDROID_BUILD_TOOLS_VERSION = '34.0.0';
|
|
5
|
-
exports.ANDROID_NDK_VERSION = '25.2.9519653';
|
|
6
|
-
exports.ANDROID_PLATFORM_VERSION = 'android-36';
|
|
7
|
-
exports.ANDROID_MACOS_COMMANDLINE_TOOLS = 'https://dl.google.com/android/repository/commandlinetools-mac-13114758_latest.zip';
|
|
8
|
-
exports.ANDROID_LINUX_COMMANDLINE_TOOLS = 'https://dl.google.com/android/repository/commandlinetools-linux-13114758_latest.zip';
|