@r_masseater/vite-plus-adopt 0.8.1 → 0.9.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.
@@ -1,11 +1,13 @@
1
- import { c as ZIZMOR, d as checksFailed, f as configMissing, i as runCaptured, l as attempt, n as writeTo, o as ACTIONLINT, p as toolFailed, r as runVendored, s as BETTERLEAKS, t as finish } from "./output-DKrfYl9Q.mjs";
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 { Array, Config, Effect, FileSystem, Function, Option, Path, Predicate, Record, Schema, String, pipe } from "effect";
3
+ import { Array, Config, Context, Effect, Exit, FileSystem, Function, Layer, Option, Order, Path, Predicate, Record, Redacted, Schema, String, pipe } from "effect";
4
4
  import { resolveConfigFromFile } from "vite-plus";
5
+ import { FetchHttpClient, HttpClient, HttpClientRequest } from "effect/http";
6
+ import { ChildProcess, ChildProcessSpawner } from "effect/process";
7
+ import { parse } from "yaml";
5
8
  import format from "@commitlint/format";
6
9
  import lint from "@commitlint/lint";
7
10
  import load from "@commitlint/load";
8
- import { ChildProcess, ChildProcessSpawner } from "effect/process";
9
11
  import { lint as lint$1 } from "markdownlint/promise";
10
12
  import { loadPackagesFromRawConfig } from "@textlint/config-loader";
11
13
  import { TextlintKernelDescriptor } from "@textlint/kernel";
@@ -14,7 +16,8 @@ import { builtInPlugins } from "textlint/lib/src/loader/TextlintrcLoader.js";
14
16
  import { normalizeTextlintPresetSubRuleKey } from "@textlint/utils";
15
17
  import { stringify } from "smol-toml";
16
18
  import { minimatch } from "minimatch";
17
- import { parse } from "yaml";
19
+ import { findWorkspaceProjectsNoCheck } from "@pnpm/workspace.projects-reader";
20
+ import { readWorkspaceManifest } from "@pnpm/workspace.workspace-manifest-reader";
18
21
  import { intersects, valid, validRange } from "semver";
19
22
  import { linter, processConfiguration } from "steiger";
20
23
  // src/entities/vite-config/model/config.ts
@@ -35,6 +38,375 @@ 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))));
41
+ // src/shared/config/skills.ts
42
+ const Repository = Schema.String.check(Schema.isPattern(/^[\w-][\w.-]*\/[\w.-]+$/u));
43
+ const LocalDirectory = Schema.String.check(Schema.isPattern(/^\.\/[\w.-]+(?:\/[\w.-]+)*$/u));
44
+ const Commit = Schema.String.check(Schema.isPattern(/^[0-9a-f]{40}$/u));
45
+ const SkillName = Schema.String.check(Schema.isPattern(/^[a-z0-9]+(?:-[a-z0-9]+)*$/u));
46
+ const Selection = Schema.Union([Schema.Literal("all"), Schema.NonEmptyArray(SkillName)]);
47
+ const RemoteSkillSourceSchema = Schema.Struct({
48
+ commit: Commit,
49
+ root: Schema.optional(Schema.String),
50
+ skills: Selection
51
+ });
52
+ const LocalSkillSourceSchema = Schema.Struct({ skills: Selection });
53
+ const SkillsSectionSchema = Schema.Record(Schema.Union([Repository, LocalDirectory]), Schema.Union([RemoteSkillSourceSchema, LocalSkillSourceSchema]));
54
+ // src/features/install-skills/model/cache.ts
55
+ const SkillCacheDirectory = Context.Reference("vite-plus-adopt/SkillCacheDirectory", { defaultValue: Option.none });
56
+ const SUBDIRECTORY = ["vpa", "skills"];
57
+ const variable = (name) => Config.option(Config.NonEmptyString(name)).pipe(Effect.orElseSucceed(Option.none));
58
+ const platformCache = Effect.gen(function* platformCache() {
59
+ const path = yield* Path.Path;
60
+ if (process.platform === "win32") return yield* variable("LOCALAPPDATA");
61
+ const home = yield* variable("HOME");
62
+ return pipe(home, Option.map((directory) => path.join(directory, ".cache")));
63
+ });
64
+ const baseDirectory = variable("XDG_CACHE_HOME").pipe(Effect.flatMap(Option.match({
65
+ onNone: () => platformCache,
66
+ onSome: Effect.succeedSome
67
+ })), Effect.flatMap(Effect.fromOption), Effect.mapError(() => configMissing("No cache directory: set XDG_CACHE_HOME or HOME")));
68
+ /** @internal */
69
+ const skillCacheDirectory = Effect.gen(function* skillCache() {
70
+ const path = yield* Path.Path;
71
+ const configured = yield* SkillCacheDirectory;
72
+ if (Option.isSome(configured)) return configured.value;
73
+ const base = yield* baseDirectory;
74
+ return path.join(base, ...SUBDIRECTORY);
75
+ });
76
+ // src/features/install-skills/model/link.ts
77
+ const KEEP = ".gitkeep";
78
+ const junction = (target, link) => runCaptured({
79
+ root: ".",
80
+ file: "cmd.exe",
81
+ args: [
82
+ "/d",
83
+ "/c",
84
+ "mklink",
85
+ "/J",
86
+ link,
87
+ target
88
+ ]
89
+ }).pipe(Effect.filterOrFail(({ valid }) => valid, ({ output }) => toolFailed("mklink")(output)), Effect.asVoid);
90
+ const linkTo = (directory) => ({ name, target }) => Effect.gen(function* linkOne() {
91
+ const fs = yield* FileSystem.FileSystem;
92
+ const link = (yield* Path.Path).join(directory, name);
93
+ if (process.platform === "win32") return yield* junction(target, link);
94
+ return yield* fs.symlink(target, link);
95
+ });
96
+ const pointsAt = (directory) => ({ name, target }) => Effect.gen(function* readTarget() {
97
+ const fs = yield* FileSystem.FileSystem;
98
+ const path = yield* Path.Path;
99
+ const found = yield* fs.readLink(path.join(directory, name));
100
+ return path.resolve(directory, found) === path.resolve(target);
101
+ });
102
+ const isCurrent = (directory, links) => Effect.gen(function* matches() {
103
+ const entries = yield* (yield* FileSystem.FileSystem).readDirectory(directory);
104
+ const expected = pipe(links, Array.map(({ name }) => name), Array.append(KEEP));
105
+ const linked = yield* Effect.forEach(links, pointsAt(directory), { concurrency: 1 });
106
+ return pipe(entries, Array.every((entry) => Array.contains(expected, entry))) && pipe(linked, Array.every(Boolean));
107
+ }).pipe(Effect.orElseSucceed(() => false));
108
+ const buildNext = (agents, skills, links) => Effect.gen(function* stageLinks() {
109
+ const fs = yield* FileSystem.FileSystem;
110
+ const path = yield* Path.Path;
111
+ const next = yield* fs.makeTempDirectory({
112
+ directory: agents,
113
+ prefix: ".skills-next-"
114
+ });
115
+ yield* Effect.forEach(links, linkTo(next), {
116
+ concurrency: 1,
117
+ discard: true
118
+ });
119
+ if (yield* fs.exists(path.join(skills, KEEP))) yield* fs.writeFileString(path.join(next, KEEP), "");
120
+ return next;
121
+ });
122
+ const swapIn = (agents, skills, next) => Effect.gen(function* replaceDirectory() {
123
+ const fs = yield* FileSystem.FileSystem;
124
+ const path = yield* Path.Path;
125
+ if (!(yield* fs.exists(skills))) return yield* fs.rename(next, skills);
126
+ const previous = yield* fs.makeTempDirectory({
127
+ directory: agents,
128
+ prefix: ".skills-old-"
129
+ });
130
+ yield* fs.rename(skills, path.join(previous, "skills"));
131
+ yield* fs.rename(next, skills);
132
+ return yield* fs.remove(previous, { recursive: true });
133
+ });
134
+ /** @internal */
135
+ const linkSkills = (root) => (links) => Effect.gen(function* link() {
136
+ const fs = yield* FileSystem.FileSystem;
137
+ const path = yield* Path.Path;
138
+ const agents = path.join(root, ".agents");
139
+ const skills = path.join(agents, "skills");
140
+ if (yield* isCurrent(skills, links)) return;
141
+ yield* fs.makeDirectory(agents, { recursive: true });
142
+ const next = yield* buildNext(agents, skills, links);
143
+ yield* swapIn(agents, skills, next);
144
+ });
145
+ const SKILL_FILE$1 = "SKILL.md";
146
+ const FRONTMATTER = /^---\r?\n(?<yaml>[\s\S]*?)\r?\n---/u;
147
+ const NEXT = 1;
148
+ const START = 0;
149
+ const SINGLE$2 = 1;
150
+ const SHORT_COMMIT = 7;
151
+ const Frontmatter = Schema.Struct({ name: Schema.String });
152
+ const decodeFrontmatter = Schema.decodeUnknownOption(Frontmatter);
153
+ const parseYaml = Option.liftThrowable((yaml) => parse(yaml));
154
+ 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));
155
+ const afterFirstSegment = (path) => pipe(path, String.indexOf("/"), Option.match({
156
+ onNone: () => path,
157
+ onSome: (at) => String.slice(at + NEXT)(path)
158
+ }));
159
+ const withoutTopDirectory = ({ header, bytes }) => ({
160
+ header: {
161
+ ...header,
162
+ path: afterFirstSegment(header.path)
163
+ },
164
+ bytes
165
+ });
166
+ /** @internal */
167
+ const isUnder = (directory) => (path) => directory === "" || String.startsWith(`${directory}/`)(path);
168
+ /** @internal */
169
+ const relativeTo = (directory) => (path) => {
170
+ if (directory === "") return path;
171
+ return String.slice(directory.length + NEXT)(path);
172
+ };
173
+ const parentOf = (path) => pipe(path, String.lastIndexOf("/"), Option.match({
174
+ onNone: () => "",
175
+ onSome: (at) => String.slice(START, at)(path)
176
+ }));
177
+ 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);
178
+ const isOutermost = (candidates) => ({ directory }) => !pipe(candidates, Array.some((other) => other.directory !== directory && isUnder(other.directory)(directory)));
179
+ const toFound = ({ directory, name }) => pipe(name, Option.map((found) => ({
180
+ name: found,
181
+ directory
182
+ })), Option.toArray);
183
+ const duplicatesOf = (found) => pipe(found, Array.groupBy(({ name }) => name), Record.filter((group) => group.length > SINGLE$2), Record.keys);
184
+ /** @internal */
185
+ const skillsIn = ({ repository, source }) => (entries) => {
186
+ const decoder = new TextDecoder();
187
+ const root = source.root ?? "";
188
+ const candidates = pipe(entries, Array.filter(isSkillFile(root)), Array.map(({ header, bytes }) => ({
189
+ directory: parentOf(header.path),
190
+ name: nameOf(decoder.decode(bytes))
191
+ })));
192
+ const found = pipe(candidates, Array.filter(isOutermost(candidates)), Array.flatMap(toFound));
193
+ const duplicated = duplicatesOf(found);
194
+ if (Array.isReadonlyArrayNonEmpty(duplicated)) return Effect.fail(checksFailed(`${repository} declares ${Array.join(duplicated, ", ")} in more than one folder`));
195
+ return Effect.succeed(found);
196
+ };
197
+ /** @internal */
198
+ const labelOf = ({ repository, source }) => `${repository}@${String.slice(START, SHORT_COMMIT)(source.commit)}`;
199
+ const codeload = ({ repository, source }) => HttpClientRequest.get(`https://codeload.github.com/${repository}/tar.gz/${source.commit}`);
200
+ const api = ({ repository, source }) => (token) => HttpClientRequest.get(`https://api.github.com/repos/${repository}/tarball/${source.commit}`).pipe(HttpClientRequest.bearerToken(Redacted.value(token)));
201
+ const fetchBytes = (request) => Effect.gen(function* fetchArchive() {
202
+ const httpClient = yield* HttpClient.HttpClient;
203
+ const body = yield* (yield* HttpClient.filterStatusOk(httpClient).execute(request)).arrayBuffer;
204
+ return new Uint8Array(body);
205
+ });
206
+ const githubToken = Config.option(Config.Redacted("GITHUB_TOKEN")).pipe(Effect.orElseSucceed(Option.none));
207
+ const download = (declared) => Effect.gen(function* downloadArchive() {
208
+ const fromCodeload = yield* Effect.exit(fetchBytes(codeload(declared)));
209
+ const token = yield* githubToken;
210
+ if (Exit.isSuccess(fromCodeload) || Option.isNone(token)) return yield* fromCodeload;
211
+ return yield* token.value.pipe(api(declared), fetchBytes);
212
+ }).pipe(Effect.mapError(toolFailed(`downloading ${declared.repository}`)));
213
+ /** @internal */
214
+ const downloadEntries = (declared) => download(declared).pipe(Effect.flatMap(readTarGz), Effect.map(Array.map(withoutTopDirectory)));
215
+ // src/features/install-skills/model/select.ts
216
+ /** @internal */
217
+ const selectSkills = ({ label, skills }) => (available) => {
218
+ if (skills === "all") return Effect.succeed(available);
219
+ const missing = pipe(skills, Array.filter((name) => !Array.contains(available, name)));
220
+ if (Array.isReadonlyArrayNonEmpty(missing)) return Effect.fail(checksFailed(`${label} has no skill named ${Array.join(missing, ", ")}. It has: ${Array.join(available, ", ")}`));
221
+ return Effect.succeed(skills);
222
+ };
223
+ // src/features/install-skills/model/local.ts
224
+ const SKILL_FILE = "SKILL.md";
225
+ const hasSkillFile = (base) => (name) => Effect.gen(function* checkSkillFile() {
226
+ const fs = yield* FileSystem.FileSystem;
227
+ const path = yield* Path.Path;
228
+ return yield* fs.exists(path.join(base, name, SKILL_FILE));
229
+ }).pipe(Effect.orElseSucceed(() => false));
230
+ /** @internal */
231
+ const resolveLocal = (root) => ({ directory, skills }) => Effect.gen(function* resolveLocalSource() {
232
+ const fs = yield* FileSystem.FileSystem;
233
+ const base = (yield* Path.Path).join(root, ...String.split("/")(directory));
234
+ const entries = yield* fs.readDirectory(base).pipe(Effect.mapError(() => checksFailed(`${directory} is not a folder`)));
235
+ const available = yield* pipe(Array.sort(entries, String.Order), Effect.filter(hasSkillFile(base)));
236
+ return {
237
+ repository: directory,
238
+ names: yield* selectSkills({
239
+ label: directory,
240
+ skills
241
+ })(available),
242
+ directory: base
243
+ };
244
+ });
245
+ // src/features/install-skills/model/extract.ts
246
+ /** @internal */
247
+ const INDEX = ".index.json";
248
+ const READ_ONLY = 292;
249
+ const READ_ONLY_EXECUTABLE = 365;
250
+ const OWNER_EXECUTE = 64;
251
+ const BIT = 2;
252
+ const SET = 1;
253
+ const modeOf = (mode) => {
254
+ if (Math.trunc(mode / OWNER_EXECUTE) % BIT === SET) return READ_ONLY_EXECUTABLE;
255
+ return READ_ONLY;
256
+ };
257
+ const renameOrKeep = (staging, target) => Effect.gen(function* renameOrKeepPlaced() {
258
+ const fs = yield* FileSystem.FileSystem;
259
+ const renamed = yield* Effect.exit(fs.rename(staging, target));
260
+ if (Exit.isSuccess(renamed) || !(yield* fs.exists(target))) return yield* renamed;
261
+ return yield* fs.remove(staging, { recursive: true });
262
+ });
263
+ const placeAtomically = (target, write) => Effect.gen(function* place() {
264
+ const fs = yield* FileSystem.FileSystem;
265
+ const path = yield* Path.Path;
266
+ yield* fs.makeDirectory(path.dirname(target), { recursive: true });
267
+ const staging = yield* fs.makeTempDirectory({
268
+ directory: path.dirname(target),
269
+ prefix: ".partial-"
270
+ });
271
+ yield* write(staging);
272
+ yield* renameOrKeep(staging, target);
273
+ });
274
+ const writeEntry = (staging, skill) => ({ header, bytes }) => Effect.gen(function* writeFile() {
275
+ const fs = yield* FileSystem.FileSystem;
276
+ const path = yield* Path.Path;
277
+ const relative = relativeTo(skill.directory)(header.path);
278
+ const file = path.join(staging, ...String.split("/")(relative));
279
+ yield* fs.makeDirectory(path.dirname(file), { recursive: true });
280
+ yield* fs.writeFile(file, bytes);
281
+ yield* fs.chmod(file, modeOf(header.mode));
282
+ });
283
+ /** @internal */
284
+ 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), {
285
+ concurrency: 1,
286
+ discard: true
287
+ }));
288
+ /** @internal */
289
+ const writeIndex = (directory) => (available) => Effect.gen(function* writeIndexFile() {
290
+ const fs = yield* FileSystem.FileSystem;
291
+ const path = yield* Path.Path;
292
+ yield* fs.makeDirectory(directory, { recursive: true });
293
+ const staging = yield* fs.makeTempDirectory({
294
+ directory,
295
+ prefix: ".partial-"
296
+ });
297
+ const partial = path.join(staging, INDEX);
298
+ yield* fs.writeFileString(partial, toJson(available));
299
+ yield* fs.rename(partial, path.join(directory, INDEX));
300
+ yield* fs.remove(staging, { recursive: true });
301
+ });
302
+ // src/features/install-skills/model/source.ts
303
+ const Index = Schema.fromJsonString(Schema.Array(Schema.String));
304
+ const readIndex = (directory) => Effect.gen(function* readIndexFile() {
305
+ const fs = yield* FileSystem.FileSystem;
306
+ const path = yield* Path.Path;
307
+ const text = yield* fs.readFileString(path.join(directory, INDEX));
308
+ return yield* Schema.decodeEffect(Index)(text);
309
+ }).pipe(Effect.option);
310
+ const isPresent = (directory) => (name) => Effect.gen(function* checkPresent() {
311
+ const fs = yield* FileSystem.FileSystem;
312
+ const path = yield* Path.Path;
313
+ return yield* fs.exists(path.join(directory, name));
314
+ }).pipe(Effect.orElseSucceed(() => false));
315
+ const missingFrom = (directory, names) => pipe(names, Effect.filter((name) => isPresent(directory)(name).pipe(Effect.map((present) => !present))));
316
+ const cachedNames = (declared, directory) => Effect.gen(function* fromCache() {
317
+ const index = yield* readIndex(directory);
318
+ if (Option.isNone(index)) return Option.none();
319
+ const names = yield* selectSkills({
320
+ label: labelOf(declared),
321
+ skills: declared.source.skills
322
+ })(index.value);
323
+ const missing = yield* missingFrom(directory, names);
324
+ return Option.liftPredicate(names, () => Array.isReadonlyArrayEmpty(missing));
325
+ });
326
+ const extractMissing = (entries, directory) => (skill) => Effect.gen(function* extractIfMissing() {
327
+ const path = yield* Path.Path;
328
+ if (!(yield* isPresent(directory)(skill.name))) yield* extractSkill({
329
+ skill,
330
+ target: path.join(directory, skill.name)
331
+ })(entries);
332
+ });
333
+ const fetchNames = (declared, directory) => Effect.gen(function* fromArchive() {
334
+ const entries = yield* downloadEntries(declared);
335
+ const found = yield* skillsIn(declared)(entries);
336
+ const available = pipe(found, Array.map(({ name }) => name));
337
+ const selected = yield* selectSkills({
338
+ label: labelOf(declared),
339
+ skills: declared.source.skills
340
+ })(available);
341
+ yield* Effect.forEach(pipe(found, Array.filter(({ name }) => Array.contains(selected, name))), extractMissing(entries, directory), {
342
+ concurrency: 1,
343
+ discard: true
344
+ });
345
+ yield* writeIndex(directory)(available);
346
+ return selected;
347
+ });
348
+ /** @internal */
349
+ const resolveSource = (cache) => (declared) => Effect.gen(function* resolve() {
350
+ const directory = (yield* Path.Path).join(cache, ...String.split("/")(declared.repository), declared.source.commit);
351
+ const cached = yield* cachedNames(declared, directory);
352
+ const names = yield* Option.match(cached, {
353
+ onNone: () => fetchNames(declared, directory),
354
+ onSome: Effect.succeed
355
+ });
356
+ return {
357
+ repository: declared.repository,
358
+ names,
359
+ directory
360
+ };
361
+ });
362
+ // src/features/install-skills/model/install-skills.ts
363
+ const isRemote = Schema.is(RemoteSkillSourceSchema);
364
+ const LOCAL_PREFIX = "./";
365
+ const SINGLE$1 = 1;
366
+ const decodeSection = (raw) => Schema.decodeUnknownEffect(SkillsSectionSchema)(raw, { onExcessProperty: "error" }).pipe(Effect.mapError((failure) => checksFailed(`vite.config "skills": ${failure.message}`)));
367
+ const namedLinks = (path) => ({ repository, names, directory }) => pipe(names, Array.map((name) => ({
368
+ name,
369
+ repository,
370
+ target: path.join(directory, name)
371
+ })));
372
+ const describeClash = ([name, group]) => `${name} (${Array.join(pipe(group, Array.map(({ repository }) => repository)), ", ")})`;
373
+ const linksOf = (resolved) => Effect.gen(function* collectLinks() {
374
+ const path = yield* Path.Path;
375
+ const links = pipe(resolved, Array.flatMap(namedLinks(path)));
376
+ const clashes = pipe(links, Array.groupBy(({ name }) => name), Record.filter((group) => group.length > SINGLE$1), Record.toEntries, Array.map(describeClash));
377
+ if (Array.isReadonlyArrayNonEmpty(clashes)) return yield* checksFailed(`More than one source provides ${Array.join(clashes, "; ")}`);
378
+ return pipe(links, Array.map(({ name, target }) => ({
379
+ name,
380
+ target
381
+ })));
382
+ });
383
+ const resolveEntry = (root, cache) => ([key, source]) => {
384
+ const local = String.startsWith(LOCAL_PREFIX)(key);
385
+ if (isRemote(source)) {
386
+ if (local) return Effect.fail(checksFailed(`vite.config "skills": ${key} is a folder in this repository and takes no commit`));
387
+ return resolveSource(cache)({
388
+ repository: key,
389
+ source
390
+ });
391
+ }
392
+ if (!local) return Effect.fail(checksFailed(`vite.config "skills": ${key} needs a commit`));
393
+ return resolveLocal(root)({
394
+ directory: key,
395
+ skills: source.skills
396
+ });
397
+ };
398
+ /** @internal */
399
+ const installSkills = (root) => Effect.gen(function* install() {
400
+ const config = yield* loadViteConfig(root);
401
+ const raw = Option.fromNullishOr(config.skills);
402
+ if (Option.isNone(raw)) return Option.none();
403
+ const section = yield* decodeSection(raw.value);
404
+ const cache = yield* skillCacheDirectory;
405
+ const resolved = yield* Effect.forEach(Record.toEntries(section), resolveEntry(root, cache), { concurrency: "unbounded" });
406
+ const links = yield* linksOf(resolved);
407
+ yield* linkSkills(root)(links);
408
+ return Option.some(links.length);
409
+ });
38
410
  // src/features/lint-text/model/commitlint.ts
39
411
  const DATA_FIRST_ARITY_3$3 = 3;
40
412
  const COMMENT_CHAR = "#";
@@ -53,7 +425,7 @@ const lintOptionsOf = (loaded) => ({
53
425
  /** @internal */
54
426
  const lintCommitMessages = Function.dual(DATA_FIRST_ARITY_3$3, (config, root, messages) => Effect.gen(function* lintMessages() {
55
427
  const loaded = yield* attempt("commitlint")(() => load(config, { cwd: root }));
56
- const results = yield* pipe(messages, Effect.forEach((message) => attempt("commitlint")(() => lint(message, loaded.rules, lintOptionsOf(loaded)))));
428
+ const results = yield* Effect.forEach(messages, (message) => attempt("commitlint")(() => lint(message, loaded.rules, lintOptionsOf(loaded))), { concurrency: 1 });
57
429
  return {
58
430
  valid: pipe(results, Array.every((result) => result.valid)),
59
431
  output: format({ results }, { color: false })
@@ -202,7 +574,7 @@ const textlintCheck = withSection("textlint", (config, { root }) => {
202
574
  ...source,
203
575
  presets
204
576
  }, root, listed))));
205
- return Effect.all([markdown, ...sources]).pipe(Effect.map(mergeReports));
577
+ return Effect.all([markdown, ...sources], { concurrency: 1 }).pipe(Effect.map(mergeReports));
206
578
  });
207
579
  /** @internal */
208
580
  const markdownlintCheck = withSection("markdownlint", (config, { root }) => markdownFiles(root, config.ignores).pipe(Effect.flatMap((files) => lintMarkdown(config, root, files))));
@@ -317,38 +689,33 @@ const DEPENDENCY_FIELDS = [
317
689
  "optionalDependencies",
318
690
  "peerDependencies"
319
691
  ];
320
- const Manifest = Schema.Record(Schema.String, Schema.Unknown);
321
- const decodeSpecifiers = Schema.decodeUnknownEffect(Schema.Record(Schema.String, Schema.String));
322
- const Workspace = Schema.Struct({ packages: Schema.optionalKey(Schema.Array(Schema.String)) });
323
- const decodeManifest = Schema.decodeEffect(Schema.fromJsonString(Manifest));
324
- const decodeWorkspace = Schema.decodeUnknownEffect(Workspace);
325
- const NEGATION = "!";
326
- const manifestPathspec = (pattern) => {
327
- if (String.startsWith(NEGATION)(pattern)) return `:(glob,exclude)${String.slice(1)(pattern)}/package.json`;
328
- return `:(glob)${pattern}/package.json`;
329
- };
330
- const listManifests = (root) => Effect.gen(function* list() {
331
- const fs = yield* FileSystem.FileSystem;
332
- const path = yield* Path.Path;
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 manifests = yield* listManifests(root);
350
- const parsed = yield* pipe(manifests, Effect.forEach((manifest) => fs.readFileString(path.join(root, manifest)).pipe(Effect.flatMap(decodeManifest), Effect.flatMap(dependenciesOf(manifest)))));
351
- return Array.flatten(parsed);
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* pipe(targets, Effect.forEach((target) => attempt("steiger")(() => linter.run(path.resolve(root, target)))));
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* pipe(RUNS, Effect.forEach((args) => runCaptured({
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-Cvkfsskf.mjs.map
1023
+ //# sourceMappingURL=vpa-WxGKHnY6.mjs.map