@r_masseater/vite-plus-adopt 0.8.1 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +29 -1
- package/THIRD-PARTY-NOTICES +55 -0
- package/dist/attw.mjs +1 -1
- package/dist/cli.mjs +2 -2
- package/dist/fsd.d.mts +1 -1
- package/dist/fsd.mjs +1 -1
- package/dist/{index-D34U8BFs.d.mts → index-vq2Re-JL.d.mts} +20 -5
- package/dist/index.d.mts +2 -9
- package/dist/index.mjs +2 -2
- package/dist/{output-DKrfYl9Q.mjs → output-BdvTIQ-k.mjs} +36 -29
- package/dist/output-BdvTIQ-k.mjs.map +1 -0
- package/dist/postinstall.mjs +2 -2
- package/dist/{run-cli-BVnXT7zF.mjs → run-cli-BiPFbX9J.mjs} +2 -2
- package/dist/{run-cli-BVnXT7zF.mjs.map → run-cli-BiPFbX9J.mjs.map} +1 -1
- package/dist/steiger-Bi33gRXU.mjs +6225 -0
- package/dist/steiger-Bi33gRXU.mjs.map +1 -0
- package/dist/{vpa-Cvkfsskf.mjs → vpa-B2qvWn3Q.mjs} +418 -44
- package/dist/vpa-B2qvWn3Q.mjs.map +1 -0
- package/package.json +24 -6
- package/skills/configure-checks/SKILL.md +99 -0
- package/dist/output-DKrfYl9Q.mjs.map +0 -1
- package/dist/vpa-Cvkfsskf.mjs.map +0 -1
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { a as ACTIONLINT, c as readTarGz, f as checksFailed, l as runCaptured, m as toolFailed, n as writeTo, o as BETTERLEAKS, p as configMissing, r as runVendored, s as ZIZMOR, t as finish, u as attempt } from "./output-BdvTIQ-k.mjs";
|
|
2
2
|
import { n as toJson } from "./json-QtVKpodH.mjs";
|
|
3
|
-
import {
|
|
3
|
+
import { n as linter, r as processConfiguration } from "./steiger-Bi33gRXU.mjs";
|
|
4
|
+
import { Array, Config, Context, Effect, Exit, FileSystem, Function, Layer, Option, Order, Path, Predicate, Record, Redacted, Schema, String, pipe } from "effect";
|
|
4
5
|
import { resolveConfigFromFile } from "vite-plus";
|
|
6
|
+
import { FetchHttpClient, HttpClient, HttpClientRequest } from "effect/http";
|
|
5
7
|
import format from "@commitlint/format";
|
|
6
8
|
import lint from "@commitlint/lint";
|
|
7
9
|
import load from "@commitlint/load";
|
|
@@ -12,11 +14,12 @@ import { TextlintKernelDescriptor } from "@textlint/kernel";
|
|
|
12
14
|
import { createLinter, loadLinterFormatter } from "textlint";
|
|
13
15
|
import { builtInPlugins } from "textlint/lib/src/loader/TextlintrcLoader.js";
|
|
14
16
|
import { normalizeTextlintPresetSubRuleKey } from "@textlint/utils";
|
|
17
|
+
import { parse } from "yaml";
|
|
15
18
|
import { stringify } from "smol-toml";
|
|
16
19
|
import { minimatch } from "minimatch";
|
|
17
|
-
import {
|
|
20
|
+
import { findWorkspaceProjectsNoCheck } from "@pnpm/workspace.projects-reader";
|
|
21
|
+
import { readWorkspaceManifest } from "@pnpm/workspace.workspace-manifest-reader";
|
|
18
22
|
import { intersects, valid, validRange } from "semver";
|
|
19
|
-
import { linter, processConfiguration } from "steiger";
|
|
20
23
|
// src/entities/vite-config/model/config.ts
|
|
21
24
|
const CONFIG_FILES = [
|
|
22
25
|
"vite.config.ts",
|
|
@@ -35,7 +38,7 @@ const loadViteConfig = (root) => findConfigFile(root).pipe(Effect.flatMap((file)
|
|
|
35
38
|
const requireSection = (key) => (config) => Effect.fromOption(Option.fromNullishOr(config[key])).pipe(Effect.mapError(() => configMissing(`vite.config has no "${key}" section`)));
|
|
36
39
|
/** @internal */
|
|
37
40
|
const loadSection = Function.dual(2, (root, key) => loadViteConfig(root).pipe(Effect.flatMap(requireSection(key))));
|
|
38
|
-
// src/features/
|
|
41
|
+
// src/features/check-text/model/commitlint.ts
|
|
39
42
|
const DATA_FIRST_ARITY_3$3 = 3;
|
|
40
43
|
const COMMENT_CHAR = "#";
|
|
41
44
|
const parserOptionsOf = (loaded) => {
|
|
@@ -53,7 +56,7 @@ const lintOptionsOf = (loaded) => ({
|
|
|
53
56
|
/** @internal */
|
|
54
57
|
const lintCommitMessages = Function.dual(DATA_FIRST_ARITY_3$3, (config, root, messages) => Effect.gen(function* lintMessages() {
|
|
55
58
|
const loaded = yield* attempt("commitlint")(() => load(config, { cwd: root }));
|
|
56
|
-
const results = yield*
|
|
59
|
+
const results = yield* Effect.forEach(messages, (message) => attempt("commitlint")(() => lint(message, loaded.rules, lintOptionsOf(loaded))), { concurrency: 1 });
|
|
57
60
|
return {
|
|
58
61
|
valid: pipe(results, Array.every((result) => result.valid)),
|
|
59
62
|
output: format({ results }, { color: false })
|
|
@@ -96,7 +99,7 @@ const listCommitMessages = Function.dual(DATA_FIRST_ARITY$3, (root, range) => Ef
|
|
|
96
99
|
], { cwd: root }));
|
|
97
100
|
return pipe(String.split(output, "\0"), Array.filter(String.isNonEmpty));
|
|
98
101
|
}));
|
|
99
|
-
// src/features/
|
|
102
|
+
// src/features/check-text/model/markdownlint.ts
|
|
100
103
|
const DATA_FIRST_ARITY_3$2 = 3;
|
|
101
104
|
const formatError = (file) => (error) => {
|
|
102
105
|
const detail = pipe([error.errorDetail, error.errorContext], Array.filter((part) => part !== null && part !== ""), Array.map((part) => ` [${part}]`), Array.join(""));
|
|
@@ -128,7 +131,7 @@ const lintMarkdown = Function.dual(DATA_FIRST_ARITY_3$2, (config, root, files) =
|
|
|
128
131
|
output: Array.join(lines, "\n")
|
|
129
132
|
};
|
|
130
133
|
}));
|
|
131
|
-
// src/features/
|
|
134
|
+
// src/features/check-text/model/textlint-presets.ts
|
|
132
135
|
const NO_OPTIONS = {};
|
|
133
136
|
const isRuleOptions = Predicate.or(Predicate.isBoolean, Predicate.isReadonlyObject);
|
|
134
137
|
/** @internal */
|
|
@@ -154,7 +157,7 @@ const rawConfigOf = (config) => {
|
|
|
154
157
|
rules: pipe(rawConfig.rules ?? {}, Record.filter((_setting, name) => !Record.has(presets, name)))
|
|
155
158
|
};
|
|
156
159
|
};
|
|
157
|
-
// src/features/
|
|
160
|
+
// src/features/check-text/model/textlint.ts
|
|
158
161
|
const DATA_FIRST_ARITY_3$1 = 3;
|
|
159
162
|
const descriptorOf = (loaded, root, config) => {
|
|
160
163
|
if (!loaded.ok) return Effect.fail(toolFailed("textlint")(loaded.error.message));
|
|
@@ -185,7 +188,7 @@ const lintTexts = Function.dual(DATA_FIRST_ARITY_3$1, (config, root, files) => E
|
|
|
185
188
|
output: formatter.format(results)
|
|
186
189
|
};
|
|
187
190
|
}));
|
|
188
|
-
// src/features/
|
|
191
|
+
// src/features/check-text/model/text-checks.ts
|
|
189
192
|
const MARKDOWN = "*.md";
|
|
190
193
|
const GLOB_PATHSPEC = ":(glob)";
|
|
191
194
|
const markdownFiles = (root, ignores = []) => listGitFiles(root, [MARKDOWN, ...pipe(ignores, Array.map((glob) => `:(glob,exclude)${glob}`))]);
|
|
@@ -202,12 +205,381 @@ const textlintCheck = withSection("textlint", (config, { root }) => {
|
|
|
202
205
|
...source,
|
|
203
206
|
presets
|
|
204
207
|
}, root, listed))));
|
|
205
|
-
return Effect.all([markdown, ...sources]).pipe(Effect.map(mergeReports));
|
|
208
|
+
return Effect.all([markdown, ...sources], { concurrency: 1 }).pipe(Effect.map(mergeReports));
|
|
206
209
|
});
|
|
207
210
|
/** @internal */
|
|
208
211
|
const markdownlintCheck = withSection("markdownlint", (config, { root }) => markdownFiles(root, config.ignores).pipe(Effect.flatMap((files) => lintMarkdown(config, root, files))));
|
|
209
212
|
/** @internal */
|
|
210
213
|
const commitlintCheck = withSection("commitlint", (config, { root, base }) => listCommitMessages(root, `${base}..HEAD`).pipe(Effect.flatMap((messages) => lintCommitMessages(config, root, messages))));
|
|
214
|
+
// src/shared/config/skills.ts
|
|
215
|
+
const Repository = Schema.String.check(Schema.isPattern(/^[\w-][\w.-]*\/[\w.-]+$/u));
|
|
216
|
+
const LocalDirectory = Schema.String.check(Schema.isPattern(/^\.\/[\w.-]+(?:\/[\w.-]+)*$/u));
|
|
217
|
+
const Commit = Schema.String.check(Schema.isPattern(/^[0-9a-f]{40}$/u));
|
|
218
|
+
const SkillName = Schema.String.check(Schema.isPattern(/^[a-z0-9]+(?:-[a-z0-9]+)*$/u));
|
|
219
|
+
const Selection = Schema.Union([Schema.Literal("all"), Schema.NonEmptyArray(SkillName)]);
|
|
220
|
+
const RemoteSkillSourceSchema = Schema.Struct({
|
|
221
|
+
commit: Commit,
|
|
222
|
+
root: Schema.optional(Schema.String),
|
|
223
|
+
skills: Selection
|
|
224
|
+
});
|
|
225
|
+
const LocalSkillSourceSchema = Schema.Struct({ skills: Selection });
|
|
226
|
+
const SkillsSectionSchema = Schema.Record(Schema.Union([Repository, LocalDirectory]), Schema.Union([RemoteSkillSourceSchema, LocalSkillSourceSchema]));
|
|
227
|
+
// src/features/install-skills/model/cache.ts
|
|
228
|
+
const SkillCacheDirectory = Context.Reference("vite-plus-adopt/SkillCacheDirectory", { defaultValue: Option.none });
|
|
229
|
+
const SUBDIRECTORY = ["vpa", "skills"];
|
|
230
|
+
const variable = (name) => Config.option(Config.NonEmptyString(name)).pipe(Effect.orElseSucceed(Option.none));
|
|
231
|
+
const platformCache = Effect.gen(function* platformCache() {
|
|
232
|
+
const path = yield* Path.Path;
|
|
233
|
+
if (process.platform === "win32") return yield* variable("LOCALAPPDATA");
|
|
234
|
+
const home = yield* variable("HOME");
|
|
235
|
+
return pipe(home, Option.map((directory) => path.join(directory, ".cache")));
|
|
236
|
+
});
|
|
237
|
+
const baseDirectory = variable("XDG_CACHE_HOME").pipe(Effect.flatMap(Option.match({
|
|
238
|
+
onNone: () => platformCache,
|
|
239
|
+
onSome: Effect.succeedSome
|
|
240
|
+
})), Effect.flatMap(Effect.fromOption), Effect.mapError(() => configMissing("No cache directory: set XDG_CACHE_HOME or HOME")));
|
|
241
|
+
/** @internal */
|
|
242
|
+
const skillCacheDirectory = Effect.gen(function* skillCache() {
|
|
243
|
+
const path = yield* Path.Path;
|
|
244
|
+
const configured = yield* SkillCacheDirectory;
|
|
245
|
+
if (Option.isSome(configured)) return configured.value;
|
|
246
|
+
const base = yield* baseDirectory;
|
|
247
|
+
return path.join(base, ...SUBDIRECTORY);
|
|
248
|
+
});
|
|
249
|
+
// src/features/install-skills/model/link.ts
|
|
250
|
+
const KEEP = ".gitkeep";
|
|
251
|
+
const junction = (target, link) => runCaptured({
|
|
252
|
+
root: ".",
|
|
253
|
+
file: "cmd.exe",
|
|
254
|
+
args: [
|
|
255
|
+
"/d",
|
|
256
|
+
"/c",
|
|
257
|
+
"mklink",
|
|
258
|
+
"/J",
|
|
259
|
+
link,
|
|
260
|
+
target
|
|
261
|
+
]
|
|
262
|
+
}).pipe(Effect.filterOrFail(({ valid }) => valid, ({ output }) => toolFailed("mklink")(output)), Effect.asVoid);
|
|
263
|
+
const linkTo = (directory) => ({ name, target }) => Effect.gen(function* linkOne() {
|
|
264
|
+
const fs = yield* FileSystem.FileSystem;
|
|
265
|
+
const link = (yield* Path.Path).join(directory, name);
|
|
266
|
+
if (process.platform === "win32") return yield* junction(target, link);
|
|
267
|
+
return yield* fs.symlink(target, link);
|
|
268
|
+
});
|
|
269
|
+
const pointsAt = (directory) => ({ name, target }) => Effect.gen(function* readTarget() {
|
|
270
|
+
const fs = yield* FileSystem.FileSystem;
|
|
271
|
+
const path = yield* Path.Path;
|
|
272
|
+
const found = yield* fs.readLink(path.join(directory, name));
|
|
273
|
+
return path.resolve(directory, found) === path.resolve(target);
|
|
274
|
+
});
|
|
275
|
+
const isCurrent = (directory, links) => Effect.gen(function* matches() {
|
|
276
|
+
const entries = yield* (yield* FileSystem.FileSystem).readDirectory(directory);
|
|
277
|
+
const expected = pipe(links, Array.map(({ name }) => name), Array.append(KEEP));
|
|
278
|
+
const linked = yield* Effect.forEach(links, pointsAt(directory), { concurrency: 1 });
|
|
279
|
+
return pipe(entries, Array.every((entry) => Array.contains(expected, entry))) && pipe(linked, Array.every(Boolean));
|
|
280
|
+
}).pipe(Effect.orElseSucceed(() => false));
|
|
281
|
+
const buildNext = (agents, skills, links) => Effect.gen(function* stageLinks() {
|
|
282
|
+
const fs = yield* FileSystem.FileSystem;
|
|
283
|
+
const path = yield* Path.Path;
|
|
284
|
+
const next = yield* fs.makeTempDirectory({
|
|
285
|
+
directory: agents,
|
|
286
|
+
prefix: ".skills-next-"
|
|
287
|
+
});
|
|
288
|
+
yield* Effect.forEach(links, linkTo(next), {
|
|
289
|
+
concurrency: 1,
|
|
290
|
+
discard: true
|
|
291
|
+
});
|
|
292
|
+
if (yield* fs.exists(path.join(skills, KEEP))) yield* fs.writeFileString(path.join(next, KEEP), "");
|
|
293
|
+
return next;
|
|
294
|
+
});
|
|
295
|
+
const swapIn = (agents, skills, next) => Effect.gen(function* replaceDirectory() {
|
|
296
|
+
const fs = yield* FileSystem.FileSystem;
|
|
297
|
+
const path = yield* Path.Path;
|
|
298
|
+
if (!(yield* fs.exists(skills))) return yield* fs.rename(next, skills);
|
|
299
|
+
const previous = yield* fs.makeTempDirectory({
|
|
300
|
+
directory: agents,
|
|
301
|
+
prefix: ".skills-old-"
|
|
302
|
+
});
|
|
303
|
+
yield* fs.rename(skills, path.join(previous, "skills"));
|
|
304
|
+
yield* fs.rename(next, skills);
|
|
305
|
+
return yield* fs.remove(previous, { recursive: true });
|
|
306
|
+
});
|
|
307
|
+
/** @internal */
|
|
308
|
+
const linkSkills = (root) => (links) => Effect.gen(function* link() {
|
|
309
|
+
const fs = yield* FileSystem.FileSystem;
|
|
310
|
+
const path = yield* Path.Path;
|
|
311
|
+
const agents = path.join(root, ".agents");
|
|
312
|
+
const skills = path.join(agents, "skills");
|
|
313
|
+
if (yield* isCurrent(skills, links)) return;
|
|
314
|
+
yield* fs.makeDirectory(agents, { recursive: true });
|
|
315
|
+
const next = yield* buildNext(agents, skills, links);
|
|
316
|
+
yield* swapIn(agents, skills, next);
|
|
317
|
+
});
|
|
318
|
+
const SKILL_FILE$1 = "SKILL.md";
|
|
319
|
+
const FRONTMATTER = /^---\r?\n(?<yaml>[\s\S]*?)\r?\n---/u;
|
|
320
|
+
const NEXT = 1;
|
|
321
|
+
const START = 0;
|
|
322
|
+
const SINGLE$2 = 1;
|
|
323
|
+
const SHORT_COMMIT = 7;
|
|
324
|
+
const Frontmatter = Schema.Struct({ name: Schema.String });
|
|
325
|
+
const decodeFrontmatter = Schema.decodeUnknownOption(Frontmatter);
|
|
326
|
+
const parseYaml = Option.liftThrowable((yaml) => parse(yaml));
|
|
327
|
+
const nameOf = (markdown) => pipe(Option.fromNullishOr(FRONTMATTER.exec(markdown)), Option.flatMap((found) => Option.fromNullishOr(found.groups)), Option.flatMap((groups) => Record.get(groups, "yaml")), Option.flatMap(parseYaml), Option.flatMap(decodeFrontmatter), Option.map(({ name }) => name));
|
|
328
|
+
const afterFirstSegment = (path) => pipe(path, String.indexOf("/"), Option.match({
|
|
329
|
+
onNone: () => path,
|
|
330
|
+
onSome: (at) => String.slice(at + NEXT)(path)
|
|
331
|
+
}));
|
|
332
|
+
const withoutTopDirectory = ({ header, bytes }) => ({
|
|
333
|
+
header: {
|
|
334
|
+
...header,
|
|
335
|
+
path: afterFirstSegment(header.path)
|
|
336
|
+
},
|
|
337
|
+
bytes
|
|
338
|
+
});
|
|
339
|
+
/** @internal */
|
|
340
|
+
const isUnder = (directory) => (path) => directory === "" || String.startsWith(`${directory}/`)(path);
|
|
341
|
+
/** @internal */
|
|
342
|
+
const relativeTo = (directory) => (path) => {
|
|
343
|
+
if (directory === "") return path;
|
|
344
|
+
return String.slice(directory.length + NEXT)(path);
|
|
345
|
+
};
|
|
346
|
+
const parentOf = (path) => pipe(path, String.lastIndexOf("/"), Option.match({
|
|
347
|
+
onNone: () => "",
|
|
348
|
+
onSome: (at) => String.slice(START, at)(path)
|
|
349
|
+
}));
|
|
350
|
+
const isSkillFile = (root) => (entry) => entry.header.type === "File" && (entry.header.path === SKILL_FILE$1 || String.endsWith(`/${SKILL_FILE$1}`)(entry.header.path)) && isUnder(root)(entry.header.path);
|
|
351
|
+
const isOutermost = (candidates) => ({ directory }) => !pipe(candidates, Array.some((other) => other.directory !== directory && isUnder(other.directory)(directory)));
|
|
352
|
+
const toFound = ({ directory, name }) => pipe(name, Option.map((found) => ({
|
|
353
|
+
name: found,
|
|
354
|
+
directory
|
|
355
|
+
})), Option.toArray);
|
|
356
|
+
const duplicatesOf = (found) => pipe(found, Array.groupBy(({ name }) => name), Record.filter((group) => group.length > SINGLE$2), Record.keys);
|
|
357
|
+
/** @internal */
|
|
358
|
+
const skillsIn = ({ repository, source }) => (entries) => {
|
|
359
|
+
const decoder = new TextDecoder();
|
|
360
|
+
const root = source.root ?? "";
|
|
361
|
+
const candidates = pipe(entries, Array.filter(isSkillFile(root)), Array.map(({ header, bytes }) => ({
|
|
362
|
+
directory: parentOf(header.path),
|
|
363
|
+
name: nameOf(decoder.decode(bytes))
|
|
364
|
+
})));
|
|
365
|
+
const found = pipe(candidates, Array.filter(isOutermost(candidates)), Array.flatMap(toFound));
|
|
366
|
+
const duplicated = duplicatesOf(found);
|
|
367
|
+
if (Array.isReadonlyArrayNonEmpty(duplicated)) return Effect.fail(checksFailed(`${repository} declares ${Array.join(duplicated, ", ")} in more than one folder`));
|
|
368
|
+
return Effect.succeed(found);
|
|
369
|
+
};
|
|
370
|
+
/** @internal */
|
|
371
|
+
const labelOf = ({ repository, source }) => `${repository}@${String.slice(START, SHORT_COMMIT)(source.commit)}`;
|
|
372
|
+
const codeload = ({ repository, source }) => HttpClientRequest.get(`https://codeload.github.com/${repository}/tar.gz/${source.commit}`);
|
|
373
|
+
const api = ({ repository, source }) => (token) => HttpClientRequest.get(`https://api.github.com/repos/${repository}/tarball/${source.commit}`).pipe(HttpClientRequest.bearerToken(Redacted.value(token)));
|
|
374
|
+
const fetchBytes = (request) => Effect.gen(function* fetchArchive() {
|
|
375
|
+
const httpClient = yield* HttpClient.HttpClient;
|
|
376
|
+
const body = yield* (yield* HttpClient.filterStatusOk(httpClient).execute(request)).arrayBuffer;
|
|
377
|
+
return new Uint8Array(body);
|
|
378
|
+
});
|
|
379
|
+
const githubToken = Config.option(Config.Redacted("GITHUB_TOKEN")).pipe(Effect.orElseSucceed(Option.none));
|
|
380
|
+
const download = (declared) => Effect.gen(function* downloadArchive() {
|
|
381
|
+
const fromCodeload = yield* Effect.exit(fetchBytes(codeload(declared)));
|
|
382
|
+
const token = yield* githubToken;
|
|
383
|
+
if (Exit.isSuccess(fromCodeload) || Option.isNone(token)) return yield* fromCodeload;
|
|
384
|
+
return yield* token.value.pipe(api(declared), fetchBytes);
|
|
385
|
+
}).pipe(Effect.mapError(toolFailed(`downloading ${declared.repository}`)));
|
|
386
|
+
/** @internal */
|
|
387
|
+
const downloadEntries = (declared) => download(declared).pipe(Effect.flatMap(readTarGz), Effect.map(Array.map(withoutTopDirectory)));
|
|
388
|
+
// src/features/install-skills/model/select.ts
|
|
389
|
+
/** @internal */
|
|
390
|
+
const selectSkills = ({ label, skills }) => (available) => {
|
|
391
|
+
if (skills === "all") return Effect.succeed(available);
|
|
392
|
+
const missing = pipe(skills, Array.filter((name) => !Array.contains(available, name)));
|
|
393
|
+
if (Array.isReadonlyArrayNonEmpty(missing)) return Effect.fail(checksFailed(`${label} has no skill named ${Array.join(missing, ", ")}. It has: ${Array.join(available, ", ")}`));
|
|
394
|
+
return Effect.succeed(skills);
|
|
395
|
+
};
|
|
396
|
+
// src/features/install-skills/model/local.ts
|
|
397
|
+
const SKILL_FILE = "SKILL.md";
|
|
398
|
+
const hasSkillFile = (base) => (name) => Effect.gen(function* checkSkillFile() {
|
|
399
|
+
const fs = yield* FileSystem.FileSystem;
|
|
400
|
+
const path = yield* Path.Path;
|
|
401
|
+
return yield* fs.exists(path.join(base, name, SKILL_FILE));
|
|
402
|
+
}).pipe(Effect.orElseSucceed(() => false));
|
|
403
|
+
/** @internal */
|
|
404
|
+
const resolveLocal = (root) => ({ directory, skills }) => Effect.gen(function* resolveLocalSource() {
|
|
405
|
+
const fs = yield* FileSystem.FileSystem;
|
|
406
|
+
const base = (yield* Path.Path).join(root, ...String.split("/")(directory));
|
|
407
|
+
const entries = yield* fs.readDirectory(base).pipe(Effect.mapError(() => checksFailed(`${directory} is not a folder`)));
|
|
408
|
+
const available = yield* pipe(Array.sort(entries, String.Order), Effect.filter(hasSkillFile(base)));
|
|
409
|
+
return {
|
|
410
|
+
repository: directory,
|
|
411
|
+
names: yield* selectSkills({
|
|
412
|
+
label: directory,
|
|
413
|
+
skills
|
|
414
|
+
})(available),
|
|
415
|
+
directory: base
|
|
416
|
+
};
|
|
417
|
+
});
|
|
418
|
+
// src/features/install-skills/model/extract.ts
|
|
419
|
+
/** @internal */
|
|
420
|
+
const INDEX = ".index.json";
|
|
421
|
+
const READ_ONLY = 292;
|
|
422
|
+
const READ_ONLY_EXECUTABLE = 365;
|
|
423
|
+
const OWNER_EXECUTE = 64;
|
|
424
|
+
const BIT = 2;
|
|
425
|
+
const SET = 1;
|
|
426
|
+
const modeOf = (mode) => {
|
|
427
|
+
if (Math.trunc(mode / OWNER_EXECUTE) % BIT === SET) return READ_ONLY_EXECUTABLE;
|
|
428
|
+
return READ_ONLY;
|
|
429
|
+
};
|
|
430
|
+
const renameOrKeep = (staging, target) => Effect.gen(function* renameOrKeepPlaced() {
|
|
431
|
+
const fs = yield* FileSystem.FileSystem;
|
|
432
|
+
const renamed = yield* Effect.exit(fs.rename(staging, target));
|
|
433
|
+
if (Exit.isSuccess(renamed) || !(yield* fs.exists(target))) return yield* renamed;
|
|
434
|
+
return yield* fs.remove(staging, { recursive: true });
|
|
435
|
+
});
|
|
436
|
+
const placeAtomically = (target, write) => Effect.gen(function* place() {
|
|
437
|
+
const fs = yield* FileSystem.FileSystem;
|
|
438
|
+
const path = yield* Path.Path;
|
|
439
|
+
yield* fs.makeDirectory(path.dirname(target), { recursive: true });
|
|
440
|
+
const staging = yield* fs.makeTempDirectory({
|
|
441
|
+
directory: path.dirname(target),
|
|
442
|
+
prefix: ".partial-"
|
|
443
|
+
});
|
|
444
|
+
yield* write(staging);
|
|
445
|
+
yield* renameOrKeep(staging, target);
|
|
446
|
+
});
|
|
447
|
+
const writeEntry = (staging, skill) => ({ header, bytes }) => Effect.gen(function* writeFile() {
|
|
448
|
+
const fs = yield* FileSystem.FileSystem;
|
|
449
|
+
const path = yield* Path.Path;
|
|
450
|
+
const relative = relativeTo(skill.directory)(header.path);
|
|
451
|
+
const file = path.join(staging, ...String.split("/")(relative));
|
|
452
|
+
yield* fs.makeDirectory(path.dirname(file), { recursive: true });
|
|
453
|
+
yield* fs.writeFile(file, bytes);
|
|
454
|
+
yield* fs.chmod(file, modeOf(header.mode));
|
|
455
|
+
});
|
|
456
|
+
/** @internal */
|
|
457
|
+
const extractSkill = ({ skill, target }) => (entries) => placeAtomically(target, (staging) => Effect.forEach(pipe(entries, Array.filter(({ header }) => header.type === "File" && isUnder(skill.directory)(header.path))), writeEntry(staging, skill), {
|
|
458
|
+
concurrency: 1,
|
|
459
|
+
discard: true
|
|
460
|
+
}));
|
|
461
|
+
/** @internal */
|
|
462
|
+
const writeIndex = (directory) => (available) => Effect.gen(function* writeIndexFile() {
|
|
463
|
+
const fs = yield* FileSystem.FileSystem;
|
|
464
|
+
const path = yield* Path.Path;
|
|
465
|
+
yield* fs.makeDirectory(directory, { recursive: true });
|
|
466
|
+
const staging = yield* fs.makeTempDirectory({
|
|
467
|
+
directory,
|
|
468
|
+
prefix: ".partial-"
|
|
469
|
+
});
|
|
470
|
+
const partial = path.join(staging, INDEX);
|
|
471
|
+
yield* fs.writeFileString(partial, toJson(available));
|
|
472
|
+
yield* fs.rename(partial, path.join(directory, INDEX));
|
|
473
|
+
yield* fs.remove(staging, { recursive: true });
|
|
474
|
+
});
|
|
475
|
+
// src/features/install-skills/model/source.ts
|
|
476
|
+
const Index = Schema.fromJsonString(Schema.Array(Schema.String));
|
|
477
|
+
const readIndex = (directory) => Effect.gen(function* readIndexFile() {
|
|
478
|
+
const fs = yield* FileSystem.FileSystem;
|
|
479
|
+
const path = yield* Path.Path;
|
|
480
|
+
const text = yield* fs.readFileString(path.join(directory, INDEX));
|
|
481
|
+
return yield* Schema.decodeEffect(Index)(text);
|
|
482
|
+
}).pipe(Effect.option);
|
|
483
|
+
const isPresent = (directory) => (name) => Effect.gen(function* checkPresent() {
|
|
484
|
+
const fs = yield* FileSystem.FileSystem;
|
|
485
|
+
const path = yield* Path.Path;
|
|
486
|
+
return yield* fs.exists(path.join(directory, name));
|
|
487
|
+
}).pipe(Effect.orElseSucceed(() => false));
|
|
488
|
+
const missingFrom = (directory, names) => pipe(names, Effect.filter((name) => isPresent(directory)(name).pipe(Effect.map((present) => !present))));
|
|
489
|
+
const cachedNames = (declared, directory) => Effect.gen(function* fromCache() {
|
|
490
|
+
const index = yield* readIndex(directory);
|
|
491
|
+
if (Option.isNone(index)) return Option.none();
|
|
492
|
+
const names = yield* selectSkills({
|
|
493
|
+
label: labelOf(declared),
|
|
494
|
+
skills: declared.source.skills
|
|
495
|
+
})(index.value);
|
|
496
|
+
const missing = yield* missingFrom(directory, names);
|
|
497
|
+
return Option.liftPredicate(names, () => Array.isReadonlyArrayEmpty(missing));
|
|
498
|
+
});
|
|
499
|
+
const extractMissing = (entries, directory) => (skill) => Effect.gen(function* extractIfMissing() {
|
|
500
|
+
const path = yield* Path.Path;
|
|
501
|
+
if (!(yield* isPresent(directory)(skill.name))) yield* extractSkill({
|
|
502
|
+
skill,
|
|
503
|
+
target: path.join(directory, skill.name)
|
|
504
|
+
})(entries);
|
|
505
|
+
});
|
|
506
|
+
const fetchNames = (declared, directory) => Effect.gen(function* fromArchive() {
|
|
507
|
+
const entries = yield* downloadEntries(declared);
|
|
508
|
+
const found = yield* skillsIn(declared)(entries);
|
|
509
|
+
const available = pipe(found, Array.map(({ name }) => name));
|
|
510
|
+
const selected = yield* selectSkills({
|
|
511
|
+
label: labelOf(declared),
|
|
512
|
+
skills: declared.source.skills
|
|
513
|
+
})(available);
|
|
514
|
+
yield* Effect.forEach(pipe(found, Array.filter(({ name }) => Array.contains(selected, name))), extractMissing(entries, directory), {
|
|
515
|
+
concurrency: 1,
|
|
516
|
+
discard: true
|
|
517
|
+
});
|
|
518
|
+
yield* writeIndex(directory)(available);
|
|
519
|
+
return selected;
|
|
520
|
+
});
|
|
521
|
+
/** @internal */
|
|
522
|
+
const resolveSource = (cache) => (declared) => Effect.gen(function* resolve() {
|
|
523
|
+
const directory = (yield* Path.Path).join(cache, ...String.split("/")(declared.repository), declared.source.commit);
|
|
524
|
+
const cached = yield* cachedNames(declared, directory);
|
|
525
|
+
const names = yield* Option.match(cached, {
|
|
526
|
+
onNone: () => fetchNames(declared, directory),
|
|
527
|
+
onSome: Effect.succeed
|
|
528
|
+
});
|
|
529
|
+
return {
|
|
530
|
+
repository: declared.repository,
|
|
531
|
+
names,
|
|
532
|
+
directory
|
|
533
|
+
};
|
|
534
|
+
});
|
|
535
|
+
// src/features/install-skills/model/install-skills.ts
|
|
536
|
+
const isRemote = Schema.is(RemoteSkillSourceSchema);
|
|
537
|
+
const LOCAL_PREFIX = "./";
|
|
538
|
+
const SINGLE$1 = 1;
|
|
539
|
+
const decodeSection = (raw) => Schema.decodeUnknownEffect(SkillsSectionSchema)(raw, { onExcessProperty: "error" }).pipe(Effect.mapError((failure) => checksFailed(`vite.config "skills": ${failure.message}`)));
|
|
540
|
+
const namedLinks = (path) => ({ repository, names, directory }) => pipe(names, Array.map((name) => ({
|
|
541
|
+
name,
|
|
542
|
+
repository,
|
|
543
|
+
target: path.join(directory, name)
|
|
544
|
+
})));
|
|
545
|
+
const describeClash = ([name, group]) => `${name} (${Array.join(pipe(group, Array.map(({ repository }) => repository)), ", ")})`;
|
|
546
|
+
const linksOf = (resolved) => Effect.gen(function* collectLinks() {
|
|
547
|
+
const path = yield* Path.Path;
|
|
548
|
+
const links = pipe(resolved, Array.flatMap(namedLinks(path)));
|
|
549
|
+
const clashes = pipe(links, Array.groupBy(({ name }) => name), Record.filter((group) => group.length > SINGLE$1), Record.toEntries, Array.map(describeClash));
|
|
550
|
+
if (Array.isReadonlyArrayNonEmpty(clashes)) return yield* checksFailed(`More than one source provides ${Array.join(clashes, "; ")}`);
|
|
551
|
+
return pipe(links, Array.map(({ name, target }) => ({
|
|
552
|
+
name,
|
|
553
|
+
target
|
|
554
|
+
})));
|
|
555
|
+
});
|
|
556
|
+
const resolveEntry = (root, cache) => ([key, source]) => {
|
|
557
|
+
const local = String.startsWith(LOCAL_PREFIX)(key);
|
|
558
|
+
if (isRemote(source)) {
|
|
559
|
+
if (local) return Effect.fail(checksFailed(`vite.config "skills": ${key} is a folder in this repository and takes no commit`));
|
|
560
|
+
return resolveSource(cache)({
|
|
561
|
+
repository: key,
|
|
562
|
+
source
|
|
563
|
+
});
|
|
564
|
+
}
|
|
565
|
+
if (!local) return Effect.fail(checksFailed(`vite.config "skills": ${key} needs a commit`));
|
|
566
|
+
return resolveLocal(root)({
|
|
567
|
+
directory: key,
|
|
568
|
+
skills: source.skills
|
|
569
|
+
});
|
|
570
|
+
};
|
|
571
|
+
/** @internal */
|
|
572
|
+
const installSkills = (root) => Effect.gen(function* install() {
|
|
573
|
+
const config = yield* loadViteConfig(root);
|
|
574
|
+
const raw = Option.fromNullishOr(config.skills);
|
|
575
|
+
if (Option.isNone(raw)) return Option.none();
|
|
576
|
+
const section = yield* decodeSection(raw.value);
|
|
577
|
+
const cache = yield* skillCacheDirectory;
|
|
578
|
+
const resolved = yield* Effect.forEach(Record.toEntries(section), resolveEntry(root, cache), { concurrency: "unbounded" });
|
|
579
|
+
const links = yield* linksOf(resolved);
|
|
580
|
+
yield* linkSkills(root)(links);
|
|
581
|
+
return Option.some(links.length);
|
|
582
|
+
});
|
|
211
583
|
// src/features/scan-secrets/model/betterleaks.ts
|
|
212
584
|
const toBetterleaksToml = (config) => {
|
|
213
585
|
const { ignoredSecrets: _ignoredSecrets, ...rest } = config;
|
|
@@ -317,38 +689,33 @@ const DEPENDENCY_FIELDS = [
|
|
|
317
689
|
"optionalDependencies",
|
|
318
690
|
"peerDependencies"
|
|
319
691
|
];
|
|
320
|
-
const
|
|
321
|
-
const
|
|
322
|
-
const
|
|
323
|
-
const
|
|
324
|
-
const
|
|
325
|
-
const
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
const text = yield* fs.readFileString(path.join(root, "pnpm-workspace.yaml"));
|
|
334
|
-
const raw = parse(text);
|
|
335
|
-
const workspace = yield* decodeWorkspace(raw);
|
|
336
|
-
const found = yield* listGitFiles(root, pipe(workspace.packages ?? [], Array.map(manifestPathspec)));
|
|
337
|
-
return ["package.json", ...Array.sort(found, String.Order)];
|
|
338
|
-
});
|
|
339
|
-
const dependenciesOf = (manifest) => (fields) => pipe(DEPENDENCY_FIELDS, Effect.forEach((field) => decodeSpecifiers(fields[field] ?? {}).pipe(Effect.map((specifiers) => pipe(Record.toEntries(specifiers), Array.map(([name, specifier]) => ({
|
|
340
|
-
manifest,
|
|
341
|
-
field,
|
|
342
|
-
name,
|
|
343
|
-
specifier
|
|
344
|
-
})))))), Effect.map(Array.flatten));
|
|
692
|
+
const MANIFEST_FILE = "package.json";
|
|
693
|
+
const pnpm = attempt("pnpm");
|
|
694
|
+
const byFile = Order.mapInput(String.Order, ({ file }) => file);
|
|
695
|
+
const manifestIn = (directory) => pipe(Option.liftPredicate(directory, String.isNonEmpty), Option.map((own) => `${own}/${MANIFEST_FILE}`), Option.getOrElse(() => MANIFEST_FILE));
|
|
696
|
+
const dependenciesIn = (file, declared) => pipe(DEPENDENCY_FIELDS, Array.flatMap((field) => {
|
|
697
|
+
const entries = Record.toEntries(Option.getOrElse(Option.fromUndefinedOr(declared[field]), () => ({})));
|
|
698
|
+
return pipe(entries, Array.map(([name, specifier]) => ({
|
|
699
|
+
manifest: file,
|
|
700
|
+
field,
|
|
701
|
+
name,
|
|
702
|
+
specifier
|
|
703
|
+
})));
|
|
704
|
+
}));
|
|
345
705
|
/** @internal */
|
|
346
706
|
const listDependencies = (root) => Effect.gen(function* list() {
|
|
347
|
-
const fs = yield* FileSystem.FileSystem;
|
|
348
707
|
const path = yield* Path.Path;
|
|
349
|
-
const
|
|
350
|
-
const
|
|
351
|
-
|
|
708
|
+
const workspace = yield* pnpm(() => readWorkspaceManifest(root));
|
|
709
|
+
const patterns = pipe(Option.fromUndefinedOr(workspace), Option.flatMap(({ packages }) => Option.fromNullishOr(packages)), Option.getOrElse(() => []));
|
|
710
|
+
const projects = yield* pnpm(() => findWorkspaceProjectsNoCheck(root, { patterns }));
|
|
711
|
+
const listed = pipe(projects, Array.map(({ rootDir, manifest }) => {
|
|
712
|
+
const file = manifestIn(path.relative(root, rootDir));
|
|
713
|
+
return {
|
|
714
|
+
file,
|
|
715
|
+
dependencies: dependenciesIn(file, manifest)
|
|
716
|
+
};
|
|
717
|
+
}));
|
|
718
|
+
return pipe(Array.sort(listed, byFile), Array.flatMap(({ dependencies }) => dependencies));
|
|
352
719
|
});
|
|
353
720
|
// src/features/check-repository/model/dependency-rules.ts
|
|
354
721
|
const DATA_FIRST_ARITY$1 = 2;
|
|
@@ -412,7 +779,7 @@ const reportOf = (diagnostics, relative) => ({
|
|
|
412
779
|
const checkSlices = Function.dual(DATA_FIRST_ARITY_3, (config, root, targets) => Effect.gen(function* check() {
|
|
413
780
|
const path = yield* Path.Path;
|
|
414
781
|
processConfiguration([...config], root);
|
|
415
|
-
const perTarget = yield*
|
|
782
|
+
const perTarget = yield* Effect.forEach(targets, (target) => attempt("steiger")(() => linter.run(path.resolve(root, target))), { concurrency: 1 });
|
|
416
783
|
return reportOf(Array.flatten(perTarget), (file) => path.relative(root, file));
|
|
417
784
|
}));
|
|
418
785
|
// src/features/check-repository/model/repository-checks.ts
|
|
@@ -515,7 +882,7 @@ const runFallow = (config, root) => Effect.gen(function* fallow() {
|
|
|
515
882
|
const configFile = path.join(directory, ".fallowrc.json");
|
|
516
883
|
const configText = yield* Schema.encodeUnknownEffect(Schema.fromJsonString(Schema.Unknown))(config).pipe(Effect.orDie);
|
|
517
884
|
yield* fs.writeFileString(configFile, configText);
|
|
518
|
-
const reports = yield*
|
|
885
|
+
const reports = yield* Effect.forEach(RUNS, (args) => runCaptured({
|
|
519
886
|
root,
|
|
520
887
|
file: "fallow",
|
|
521
888
|
args: [
|
|
@@ -523,7 +890,7 @@ const runFallow = (config, root) => Effect.gen(function* fallow() {
|
|
|
523
890
|
"-c",
|
|
524
891
|
configFile
|
|
525
892
|
]
|
|
526
|
-
}))
|
|
893
|
+
}), { concurrency: 1 });
|
|
527
894
|
const smells = yield* componentSmells(root, configFile);
|
|
528
895
|
const all = [...reports, smells];
|
|
529
896
|
return {
|
|
@@ -615,6 +982,7 @@ const runAllChecks = (root) => Effect.gen(function* all() {
|
|
|
615
982
|
const DATA_FIRST_ARITY = 2;
|
|
616
983
|
const USAGE = pipe([
|
|
617
984
|
"Usage: vpa run every check configured in vite.config.ts",
|
|
985
|
+
" vpa --prepare install the skills in vite.config.ts into .agents/skills (prepare)",
|
|
618
986
|
" vpa --staged scan the staged changes for secrets (pre-commit)",
|
|
619
987
|
" vpa --commit-msg <file> lint a commit message (commit-msg)",
|
|
620
988
|
" vpa --message <text> lint a message"
|
|
@@ -631,7 +999,13 @@ const lintMessage = (toMessage) => (root, rest) => pipe(Array.head(rest), Option
|
|
|
631
999
|
})
|
|
632
1000
|
}));
|
|
633
1001
|
const readMessage = (file) => FileSystem.FileSystem.pipe(Effect.flatMap((fs) => fs.readFileString(file)));
|
|
1002
|
+
const reportLinked = Option.match({
|
|
1003
|
+
onNone: () => Effect.void,
|
|
1004
|
+
onSome: (count) => writeTo("stdout", `Linked ${count} skills into .agents/skills\n`)
|
|
1005
|
+
});
|
|
1006
|
+
const prepare = (root) => Layer.build(FetchHttpClient.layer).pipe(Effect.flatMap((context) => Effect.provideContext(installSkills(root), context)), Effect.flatMap(reportLinked), Effect.scoped);
|
|
634
1007
|
const HOOKS = {
|
|
1008
|
+
"--prepare": prepare,
|
|
635
1009
|
"--staged": stagedSecrets,
|
|
636
1010
|
"--commit-msg": lintMessage(readMessage),
|
|
637
1011
|
"--message": lintMessage(Effect.succeed)
|
|
@@ -646,4 +1020,4 @@ const runVpa = Function.dual(DATA_FIRST_ARITY, (root, args) => pipe(args, Array.
|
|
|
646
1020
|
})));
|
|
647
1021
|
export { loadViteConfig as n, runVpa as t };
|
|
648
1022
|
|
|
649
|
-
//# sourceMappingURL=vpa-
|
|
1023
|
+
//# sourceMappingURL=vpa-B2qvWn3Q.mjs.map
|