@r_masseater/vite-plus-adopt 0.14.0 → 0.15.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/dist/cli.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { i as VpToolsError, n as writeTo, t as runVpa } from "./vpa-jp87uBqF.mjs";
2
+ import { i as VpToolsError, n as writeTo, t as runVpa } from "./vpa-B16TImrg.mjs";
3
3
  import { Cause, Effect, Layer, Option, Path, Schema, Stdio, pipe } from "effect";
4
4
  import { runMainWith } from "@r_masseater/node-main";
5
5
  // src/app/run-cli.ts
package/dist/index.d.mts CHANGED
@@ -22,6 +22,13 @@ declare const SkillsSectionSchema: Schema.$Record<Schema.Union<readonly [Schema.
22
22
  readonly skills: Schema.Union<readonly [Schema.Literal<"all">, Schema.NonEmptyArray<Schema.String>]>;
23
23
  }>]>>;
24
24
  type SkillsSection = typeof SkillsSectionSchema.Encoded;
25
+ declare const ToolsSectionSchema: Schema.$Record<Schema.String, Schema.Struct<{
26
+ readonly version: Schema.String;
27
+ readonly base: Schema.optional<Schema.String>;
28
+ readonly bin: Schema.optional<Schema.NonEmptyArray<Schema.String>>;
29
+ readonly assets: Schema.$Record<Schema.String, Schema.String>;
30
+ }>>;
31
+ type ToolsSection = typeof ToolsSectionSchema.Encoded;
25
32
  interface CommitlintConfig extends Readonly<UserConfig> {}
26
33
  type TextlintRuleOptions = NonNullable<TextlintKernelRule["options"]>;
27
34
  interface TextlintPreset {
@@ -56,6 +63,7 @@ interface ToolSections {
56
63
  readonly h56m?: H56mConfig;
57
64
  readonly skills?: SkillsSection;
58
65
  readonly textlint?: TextlintConfig;
66
+ readonly tools?: ToolsSection;
59
67
  }
60
68
  declare module "vite" {
61
69
  interface UserConfig extends ToolSections {}
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- export { i as VpToolsError, r as loadViteConfig, t as runVpa } from "./vpa-jp87uBqF.mjs";
1
+ export { i as VpToolsError, r as loadViteConfig, t as runVpa } from "./vpa-B16TImrg.mjs";
@@ -1,7 +1,6 @@
1
1
  import { n as toJson } from "./json-QtVKpodH.mjs";
2
2
  import { Array, Boolean as Boolean$1, Config, Context, Effect, Exit, FileSystem, Function, Layer, Option, Order, Path, Predicate, Record, Redacted, Schedule, Schema, Stdio, Stream, String as String$1, pipe } from "effect";
3
3
  import { resolveConfigFromFile } from "vite-plus";
4
- import { FetchHttpClient, HttpClient, HttpClientRequest } from "effect/http";
5
4
  import format from "@commitlint/format";
6
5
  import lint from "@commitlint/lint";
7
6
  import load from "@commitlint/load";
@@ -11,10 +10,11 @@ import { TextlintKernelDescriptor } from "@textlint/kernel";
11
10
  import { createLinter, loadLinterFormatter } from "textlint";
12
11
  import { loadBuiltinPlugins } from "textlint/lib/src/loader/TextlintrcLoader.js";
13
12
  import { normalizeTextlintPresetSubRuleKey } from "@textlint/utils";
13
+ import { format as format$1, makeDetector } from "@r_masseater/h56m";
14
+ import { FetchHttpClient, HttpClient, HttpClientRequest } from "effect/http";
14
15
  import { minimatch } from "minimatch";
15
16
  import { parse } from "yaml";
16
17
  import { Tar } from "effect/encoding";
17
- import { format as format$1, makeDetector } from "@r_masseater/h56m";
18
18
  import { findWorkspaceProjectsNoCheck } from "@pnpm/workspace.projects-reader";
19
19
  import { readWorkspaceManifest } from "@pnpm/workspace.workspace-manifest-reader";
20
20
  import { intersects, valid, validRange } from "semver";
@@ -97,9 +97,9 @@ const withSection = Function.dual(2, (key, run) => (context) => pipe(Option.from
97
97
  onSome: (section) => Effect.asSome(run(section, context))
98
98
  })));
99
99
  // src/shared/lib/git.ts
100
- const DATA_FIRST_ARITY$4 = 2;
100
+ const DATA_FIRST_ARITY$7 = 2;
101
101
  /** @internal */
102
- const listGitFiles = Function.dual(DATA_FIRST_ARITY$4, (root, pathspecs) => Effect.gen(function* list() {
102
+ const listGitFiles = Function.dual(DATA_FIRST_ARITY$7, (root, pathspecs) => Effect.gen(function* list() {
103
103
  const output = yield* (yield* ChildProcessSpawner.ChildProcessSpawner).string(ChildProcess.make("git", [
104
104
  "-c",
105
105
  "core.quotePath=false",
@@ -113,7 +113,7 @@ const listGitFiles = Function.dual(DATA_FIRST_ARITY$4, (root, pathspecs) => Effe
113
113
  return pipe(String$1.split(output, "\0"), Array.filter(String$1.isNonEmpty));
114
114
  }));
115
115
  /** @internal */
116
- const listCommitMessages = Function.dual(DATA_FIRST_ARITY$4, (root, range) => Effect.gen(function* messages() {
116
+ const listCommitMessages = Function.dual(DATA_FIRST_ARITY$7, (root, range) => Effect.gen(function* messages() {
117
117
  const output = yield* (yield* ChildProcessSpawner.ChildProcessSpawner).string(ChildProcess.make("git", [
118
118
  "log",
119
119
  "-z",
@@ -203,6 +203,70 @@ const textlintCheck = withSection("textlint", (config, { root }) => {
203
203
  });
204
204
  /** @internal */
205
205
  const commitlintCheck = withSection("commitlint", (config, { root, range }) => listCommitMessages(root, range).pipe(Effect.flatMap((messages) => lintCommitMessages(config, root, messages))));
206
+ // src/features/scan-secrets/model/secret-checks.ts
207
+ const DATA_FIRST_ARITY$6 = 2;
208
+ const SUCCESS$1 = 0;
209
+ const RANGE = "..";
210
+ const HEAD = "HEAD";
211
+ const lacksHistory = (root) => Effect.gen(function* history() {
212
+ const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
213
+ const shallow = yield* spawner.string(ChildProcess.make("git", ["rev-parse", "--is-shallow-repository"], { cwd: root }));
214
+ const promisor = yield* spawner.exitCode(ChildProcess.make("git", [
215
+ "config",
216
+ "--get",
217
+ "remote.origin.promisor"
218
+ ], { cwd: root }));
219
+ return String$1.trim(shallow) === "true" || promisor === SUCCESS$1;
220
+ });
221
+ const historyOf = (range) => pipe(String$1.split(range, RANGE), Array.match({
222
+ onEmpty: () => ({
223
+ type: "history",
224
+ head: HEAD
225
+ }),
226
+ onNonEmpty: ([base, ...rest]) => Array.match(rest, {
227
+ onEmpty: () => ({
228
+ type: "history",
229
+ head: range
230
+ }),
231
+ onNonEmpty: ([head]) => ({
232
+ type: "history",
233
+ bases: [base],
234
+ head
235
+ })
236
+ })
237
+ }));
238
+ const sourceOf = (partial, range) => Boolean$1.match(partial, {
239
+ onTrue: () => ({
240
+ type: "snapshot",
241
+ revision: HEAD
242
+ }),
243
+ onFalse: () => historyOf(range)
244
+ });
245
+ const scan = (config, root, source) => Effect.gen(function* scanSource() {
246
+ const found = yield* (yield* makeDetector(config)).scanGit({
247
+ root,
248
+ source
249
+ });
250
+ return {
251
+ valid: Array.isReadonlyArrayEmpty(found),
252
+ output: pipe(found, Array.map(format$1), Array.join("\n"))
253
+ };
254
+ }).pipe(Effect.mapError(toolFailed("h56m")));
255
+ /** @internal */
256
+ const h56mCheck = withSection("h56m", (config, { root, range }) => lacksHistory(root).pipe(Effect.flatMap((partial) => scan(config, root, sourceOf(partial, range)))));
257
+ /** @internal */
258
+ const scanStagedSecrets = Function.dual(DATA_FIRST_ARITY$6, (config, root) => scan(config, root, { type: "staged" }));
259
+ /** @internal */
260
+ const writeTo = Function.dual(2, (sink, text) => Effect.gen(function* write() {
261
+ const stdio = yield* Stdio.Stdio;
262
+ yield* Stream.make(text).pipe(Stream.run(stdio[sink]()), Effect.orDie);
263
+ }));
264
+ /** @internal */
265
+ const finish = (report) => {
266
+ if (!report.valid) return Effect.fail(checksFailed(report.output));
267
+ if (report.output === "") return Effect.void;
268
+ return writeTo("stdout", `${report.output}\n`);
269
+ };
206
270
  // src/shared/config/skills.ts
207
271
  const Repository = Schema.String.check(Schema.isPattern(/^[\w-][\w.-]*\/[\w.-]+$/u));
208
272
  const LocalDirectory = Schema.String.check(Schema.isPattern(/^\.\/[\w.-]+(?:\/[\w.-]+)*$/u));
@@ -216,9 +280,22 @@ const RemoteSkillSourceSchema = Schema.Struct({
216
280
  });
217
281
  const LocalSkillSourceSchema = Schema.Struct({ skills: Selection });
218
282
  const SkillsSectionSchema = Schema.Record(Schema.Union([Repository, LocalDirectory]), Schema.Union([RemoteSkillSourceSchema, LocalSkillSourceSchema]));
219
- // src/features/install-skills/model/cache.ts
220
- const SkillCacheDirectory = Context.Reference("vite-plus-adopt/SkillCacheDirectory", { defaultValue: Option.none });
221
- const SUBDIRECTORY = ["vpa", "skills"];
283
+ // src/shared/config/tools.ts
284
+ const ToolName = Schema.String.check(Schema.isPattern(/^[\w-][\w.-]*(?:\/[\w.-]+)?$/u));
285
+ const Platform = Schema.String.check(Schema.isPattern(/^(?:linux|darwin|win32)-(?:x64|arm64)$/u));
286
+ const Version = Schema.String.check(Schema.isPattern(/^\d[\w.+-]*$/u));
287
+ const BinaryName = Schema.String.check(Schema.isPattern(/^[\w][\w.-]*$/u));
288
+ const AssetFile = Schema.String.check(Schema.isPattern(/^[\w{}][\w.{}+-]*$/u));
289
+ const BinaryNames = Schema.NonEmptyArray(BinaryName);
290
+ const ToolSourceSchema = Schema.Struct({
291
+ version: Version,
292
+ base: Schema.optional(Schema.String),
293
+ bin: Schema.optional(BinaryNames),
294
+ assets: Schema.Record(Platform, AssetFile)
295
+ });
296
+ const ToolsSectionSchema = Schema.Record(ToolName, ToolSourceSchema);
297
+ // src/shared/lib/cache.ts
298
+ const ROOT$2 = ["vpa"];
222
299
  const variable = (name) => Config.option(Config.NonEmptyString(name)).pipe(Effect.orElseSucceed(Option.none));
223
300
  const platformCache = Effect.gen(function* platformCache() {
224
301
  const path = yield* Path.Path;
@@ -231,15 +308,21 @@ const baseDirectory = variable("XDG_CACHE_HOME").pipe(Effect.flatMap(Option.matc
231
308
  onSome: Effect.succeedSome
232
309
  })), Effect.flatMap(Effect.fromOption), Effect.mapError(() => configMissing("No cache directory: set XDG_CACHE_HOME or HOME")));
233
310
  /** @internal */
234
- const skillCacheDirectory = Effect.gen(function* skillCache() {
311
+ const vpaCacheDirectory = (subdirectory) => Effect.gen(function* vpaCache() {
235
312
  const path = yield* Path.Path;
313
+ const base = yield* baseDirectory;
314
+ return path.join(base, ...ROOT$2, subdirectory);
315
+ });
316
+ // src/features/install-skills/model/cache.ts
317
+ const SkillCacheDirectory = Context.Reference("vite-plus-adopt/SkillCacheDirectory", { defaultValue: Option.none });
318
+ /** @internal */
319
+ const skillCacheDirectory = Effect.gen(function* skillCache() {
236
320
  const configured = yield* SkillCacheDirectory;
237
321
  if (Option.isSome(configured)) return configured.value;
238
- const base = yield* baseDirectory;
239
- return path.join(base, ...SUBDIRECTORY);
322
+ return yield* vpaCacheDirectory("skills");
240
323
  });
241
324
  // src/shared/lib/process.ts
242
- const SUCCESS$1 = 0;
325
+ const SUCCESS = 0;
243
326
  const stdinOf = (input) => pipe(Option.fromNullishOr(input), Option.match({
244
327
  onNone: () => "ignore",
245
328
  onSome: (text) => Stream.make(new TextEncoder().encode(text))
@@ -254,7 +337,7 @@ const runCaptured = ({ root, file, args, env = {}, input, output = "all" }) => E
254
337
  }));
255
338
  const [text, exitCode] = yield* Effect.all([handle[output].pipe(Stream.decodeText, Stream.mkString), handle.exitCode], { concurrency: "unbounded" });
256
339
  return {
257
- valid: exitCode === SUCCESS$1,
340
+ valid: exitCode === SUCCESS,
258
341
  output: text
259
342
  };
260
343
  }).pipe(Effect.scoped);
@@ -391,6 +474,17 @@ const isInside = (directory) => (path) => path !== directory && (directory === R
391
474
  const below = (directory) => (path) => pipe(Option.liftPredicate(path, () => String$1.isEmpty(directory)), Option.orElse(() => afterPrefix(`${directory}/`)(path)));
392
475
  String$1.startsWith("!");
393
476
  String$1.slice(1);
477
+ // src/shared/lib/http.ts
478
+ const RETRY_DELAY = "1 second";
479
+ const RETRIES = 4;
480
+ /** @internal */
481
+ const fetchBytes = (request) => Effect.gen(function* fetchArchive() {
482
+ const body = yield* (yield* (yield* HttpClient.HttpClient).pipe(HttpClient.filterStatusOk, HttpClient.retryTransient({
483
+ schedule: Schedule.exponential(RETRY_DELAY),
484
+ times: RETRIES
485
+ })).execute(request)).arrayBuffer;
486
+ return new Uint8Array(body);
487
+ });
394
488
  // src/shared/lib/tar-gz.ts
395
489
  const gunzipped = (data) => {
396
490
  const compressed = new Blob([new Uint8Array(data)]).stream();
@@ -405,7 +499,7 @@ const readTarGz = (data) => Effect.flatMap(gunzipped(data), untarred);
405
499
  const SKILL_FILE$1 = "SKILL.md";
406
500
  const FRONTMATTER = /^---\r?\n(?<yaml>[\s\S]*?)\r?\n---/u;
407
501
  const NEXT = 1;
408
- const START = 0;
502
+ const START$1 = 0;
409
503
  const SINGLE$2 = 1;
410
504
  const SHORT_COMMIT = 7;
411
505
  const Frontmatter = Schema.Struct({ name: Schema.String });
@@ -425,7 +519,7 @@ const withoutTopDirectory = ({ header, bytes }) => ({
425
519
  });
426
520
  const parentOf = (path) => pipe(path, String$1.lastIndexOf("/"), Option.match({
427
521
  onNone: () => "",
428
- onSome: (at) => String$1.slice(START, at)(path)
522
+ onSome: (at) => String$1.slice(START$1, at)(path)
429
523
  }));
430
524
  const isSkillFile = (root) => (entry) => entry.header.type === "File" && (entry.header.path === SKILL_FILE$1 || String$1.endsWith(`/${SKILL_FILE$1}`)(entry.header.path)) && isInside(root)(entry.header.path);
431
525
  const isOutermost = (candidates) => ({ directory }) => !pipe(candidates, Array.some((other) => other.directory !== directory && isInside(other.directory)(directory)));
@@ -448,18 +542,9 @@ const skillsIn = ({ repository, source }) => (entries) => {
448
542
  return Effect.succeed(found);
449
543
  };
450
544
  /** @internal */
451
- const labelOf = ({ repository, source }) => `${repository}@${String$1.slice(START, SHORT_COMMIT)(source.commit)}`;
452
- const RETRY_DELAY = "1 second";
453
- const RETRIES = 4;
545
+ const labelOf = ({ repository, source }) => `${repository}@${String$1.slice(START$1, SHORT_COMMIT)(source.commit)}`;
454
546
  const codeload = ({ repository, source }) => HttpClientRequest.get(`https://codeload.github.com/${repository}/tar.gz/${source.commit}`);
455
547
  const api = ({ repository, source }) => (token) => HttpClientRequest.get(`https://api.github.com/repos/${repository}/tarball/${source.commit}`).pipe(HttpClientRequest.bearerToken(Redacted.value(token)));
456
- const fetchBytes = (request) => Effect.gen(function* fetchArchive() {
457
- const body = yield* (yield* (yield* HttpClient.HttpClient).pipe(HttpClient.filterStatusOk, HttpClient.retryTransient({
458
- schedule: Schedule.exponential(RETRY_DELAY),
459
- times: RETRIES
460
- })).execute(request)).arrayBuffer;
461
- return new Uint8Array(body);
462
- });
463
548
  const githubToken = Config.option(Config.Redacted("GITHUB_TOKEN")).pipe(Effect.orElseSucceed(Option.none));
464
549
  const download = (declared) => Effect.gen(function* downloadArchive() {
465
550
  const fromCodeload = yield* codeload(declared).pipe(fetchBytes, Effect.exit);
@@ -499,25 +584,15 @@ const resolveLocal = (root) => ({ directory, skills }) => Effect.gen(function* r
499
584
  directory: base
500
585
  };
501
586
  });
502
- // src/features/install-skills/model/extract.ts
503
- /** @internal */
504
- const INDEX = ".index.json";
505
- const READ_ONLY = 292;
506
- const READ_ONLY_EXECUTABLE = 365;
507
- const OWNER_EXECUTE = 64;
508
- const BIT = 2;
509
- const SET = 1;
510
- const modeOf = (mode) => {
511
- if (Math.trunc(mode / OWNER_EXECUTE) % BIT === SET) return READ_ONLY_EXECUTABLE;
512
- return READ_ONLY;
513
- };
587
+ // src/shared/lib/place.ts
514
588
  const renameOrKeep = (staging, target) => Effect.gen(function* renameOrKeepPlaced() {
515
589
  const fs = yield* FileSystem.FileSystem;
516
590
  const renamed = yield* Effect.exit(fs.rename(staging, target));
517
591
  if (Exit.isSuccess(renamed) || !(yield* fs.exists(target))) return yield* renamed;
518
592
  return yield* fs.remove(staging, { recursive: true });
519
593
  });
520
- const placeAtomically = (target, write) => Effect.gen(function* place() {
594
+ /** @internal */
595
+ const placeAtomically = Function.dual(2, (target, write) => Effect.gen(function* place() {
521
596
  const fs = yield* FileSystem.FileSystem;
522
597
  const path = yield* Path.Path;
523
598
  yield* fs.makeDirectory(path.dirname(target), { recursive: true });
@@ -527,7 +602,19 @@ const placeAtomically = (target, write) => Effect.gen(function* place() {
527
602
  });
528
603
  yield* write(staging);
529
604
  yield* renameOrKeep(staging, target);
530
- });
605
+ }));
606
+ // src/features/install-skills/model/extract.ts
607
+ /** @internal */
608
+ const INDEX = ".index.json";
609
+ const READ_ONLY = 292;
610
+ const READ_ONLY_EXECUTABLE = 365;
611
+ const OWNER_EXECUTE = 64;
612
+ const BIT = 2;
613
+ const SET = 1;
614
+ const modeOf = (mode) => {
615
+ if (Math.trunc(mode / OWNER_EXECUTE) % BIT === SET) return READ_ONLY_EXECUTABLE;
616
+ return READ_ONLY;
617
+ };
531
618
  const writeEntry = (staging, skill) => ({ header, bytes }) => Effect.gen(function* writeFile() {
532
619
  const fs = yield* FileSystem.FileSystem;
533
620
  const path = yield* Path.Path;
@@ -620,7 +707,7 @@ const resolveSource = (cache) => (declared) => Effect.gen(function* resolve() {
620
707
  const isRemote = Schema.is(RemoteSkillSourceSchema);
621
708
  const LOCAL_PREFIX = "./";
622
709
  const SINGLE$1 = 1;
623
- const decodeSection = (raw) => Schema.decodeUnknownEffect(SkillsSectionSchema)(raw, { onExcessProperty: "error" }).pipe(Effect.mapError((failure) => checksFailed(`vite.config "skills": ${failure.message}`)));
710
+ const decodeSection$1 = (raw) => Schema.decodeUnknownEffect(SkillsSectionSchema)(raw, { onExcessProperty: "error" }).pipe(Effect.mapError((failure) => checksFailed(`vite.config "skills": ${failure.message}`)));
624
711
  const namedLinks = (path) => ({ repository, names, directory }) => pipe(names, Array.map((name) => ({
625
712
  name,
626
713
  repository,
@@ -657,77 +744,229 @@ const installSkills = (root) => Effect.gen(function* install() {
657
744
  const config = yield* loadViteConfig(root);
658
745
  const raw = Option.fromNullishOr(config.skills);
659
746
  if (Option.isNone(raw)) return Option.none();
660
- const section = yield* decodeSection(raw.value);
747
+ const section = yield* decodeSection$1(raw.value);
661
748
  const cache = yield* skillCacheDirectory;
662
749
  const resolved = yield* Effect.forEach(Record.toEntries(section), resolveEntry(root, cache), { concurrency: "unbounded" });
663
750
  const links = yield* linksOf(resolved);
664
751
  yield* linkSkills(root)(links);
665
752
  return Option.some(links.length);
666
753
  });
667
- // src/features/scan-secrets/model/secret-checks.ts
668
- const DATA_FIRST_ARITY$3 = 2;
669
- const SUCCESS = 0;
670
- const RANGE = "..";
671
- const HEAD = "HEAD";
672
- const lacksHistory = (root) => Effect.gen(function* history() {
673
- const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
674
- const shallow = yield* spawner.string(ChildProcess.make("git", ["rev-parse", "--is-shallow-repository"], { cwd: root }));
675
- const promisor = yield* spawner.exitCode(ChildProcess.make("git", [
676
- "config",
677
- "--get",
678
- "remote.origin.promisor"
679
- ], { cwd: root }));
680
- return String$1.trim(shallow) === "true" || promisor === SUCCESS;
754
+ // src/features/install-tools/model/find-executable.ts
755
+ const WINDOWS_EXTENSION = ".exe";
756
+ const SEPARATORS = /[\\/]/u;
757
+ const fileNameOf = (name) => {
758
+ if (process.platform === "win32") return `${name}${WINDOWS_EXTENSION}`;
759
+ return name;
760
+ };
761
+ const depthOf = (entry) => Array.length(String$1.split(SEPARATORS)(entry));
762
+ const byDepth = Order.mapInput(Order.Number, depthOf);
763
+ /** @internal */
764
+ const findExecutable = (directory) => (name) => Effect.gen(function* find() {
765
+ const fs = yield* FileSystem.FileSystem;
766
+ const path = yield* Path.Path;
767
+ const entries = yield* fs.readDirectory(directory, { recursive: true });
768
+ const wanted = fileNameOf(name);
769
+ return yield* pipe(entries, Array.filter((entry) => path.basename(entry) === wanted), Array.sortBy(byDepth), Array.head, Option.map((entry) => path.join(directory, entry)), Effect.fromOption, Effect.mapError(() => checksFailed(`${wanted} is not in the archive unpacked at ${directory}`)));
681
770
  });
682
- const historyOf = (range) => pipe(String$1.split(range, RANGE), Array.match({
683
- onEmpty: () => ({
684
- type: "history",
685
- head: HEAD
686
- }),
687
- onNonEmpty: ([base, ...rest]) => Array.match(rest, {
688
- onEmpty: () => ({
689
- type: "history",
690
- head: range
691
- }),
692
- onNonEmpty: ([head]) => ({
693
- type: "history",
694
- bases: [base],
695
- head
696
- })
697
- })
698
- }));
699
- const sourceOf = (partial, range) => Boolean$1.match(partial, {
700
- onTrue: () => ({
701
- type: "snapshot",
702
- revision: HEAD
703
- }),
704
- onFalse: () => historyOf(range)
771
+ // src/features/install-tools/model/download.ts
772
+ const HEX = 16;
773
+ const BYTE_DIGITS = 2;
774
+ const hexOf = (digest) => pipe([...new Uint8Array(digest)], Array.map((byte) => String$1.padStart(BYTE_DIGITS, "0")(byte.toString(HEX))), Array.join(""));
775
+ const sha256Of = (bytes) => attempt("sha256")(() => crypto.subtle.digest("SHA-256", new Uint8Array(bytes))).pipe(Effect.map(hexOf));
776
+ const verified = (url, expected) => (downloaded) => Option.match(expected, {
777
+ onNone: () => Effect.succeed(downloaded),
778
+ onSome: (pinned) => Effect.filterOrFail(Effect.succeed(downloaded), ({ sha256 }) => sha256 === pinned, ({ sha256 }) => checksFailed(`${url} has sha256 ${sha256}, but vpa-lock.json pins ${pinned}`))
705
779
  });
706
- const scan = (config, root, source) => Effect.gen(function* scanSource() {
707
- const found = yield* (yield* makeDetector(config)).scanGit({
708
- root,
709
- source
780
+ /** @internal */
781
+ const downloadAsset = (expected) => ({ name, version, url }) => fetchBytes(HttpClientRequest.get(url)).pipe(Effect.mapError(toolFailed(`downloading ${name}@${version}`)), Effect.flatMap((bytes) => sha256Of(bytes).pipe(Effect.map((sha256) => ({
782
+ bytes,
783
+ sha256
784
+ })))), Effect.flatMap(verified(url, expected)));
785
+ // src/features/install-tools/model/extract.ts
786
+ const ARCHIVE_SUFFIX = ".archive";
787
+ const DEFAULT_SYSTEM_ROOT = String.raw`C:\Windows`;
788
+ const tarFile = Effect.gen(function* tarFile() {
789
+ if (process.platform !== "win32") return "tar";
790
+ const path = yield* Path.Path;
791
+ const systemRoot = yield* Config.NonEmptyString("SystemRoot").pipe(Effect.orElseSucceed(() => DEFAULT_SYSTEM_ROOT));
792
+ return path.join(systemRoot, "System32", "tar.exe");
793
+ });
794
+ const untar = (archive, directory) => Effect.gen(function* run() {
795
+ const file = yield* tarFile;
796
+ const report = yield* runCaptured({
797
+ root: directory,
798
+ file,
799
+ args: [
800
+ "-xf",
801
+ archive,
802
+ "-C",
803
+ directory
804
+ ]
710
805
  });
806
+ yield* Effect.filterOrFail(Effect.succeed(report), ({ valid }) => valid, ({ output }) => toolFailed("tar")(output));
807
+ });
808
+ /** @internal */
809
+ const unpackArchive = (target) => (bytes) => placeAtomically(target, (staging) => Effect.gen(function* unpack() {
810
+ const fs = yield* FileSystem.FileSystem;
811
+ const archive = `${staging}${ARCHIVE_SUFFIX}`;
812
+ yield* fs.writeFile(archive, bytes);
813
+ yield* untar(archive, staging);
814
+ yield* fs.remove(archive);
815
+ }));
816
+ // src/features/install-tools/model/install-one.ts
817
+ const SHORT_HASH = 12;
818
+ const DATA_FIRST_ARITY$3 = 3;
819
+ const START = 0;
820
+ const SEPARATOR$1 = "/";
821
+ const directoryFor = (cache, { name, version, platform }, sha256) => Effect.gen(function* directory() {
822
+ return (yield* Path.Path).join(cache, ...String$1.split(SEPARATOR$1)(name), `${version}-${platform}-${String$1.slice(START, SHORT_HASH)(sha256)}`);
823
+ });
824
+ const alreadyInstalled = (cache, planned, locked) => Effect.gen(function* lookup() {
825
+ const fs = yield* FileSystem.FileSystem;
826
+ if (Option.isNone(locked)) return Option.none();
827
+ const directory = yield* directoryFor(cache, planned, locked.value);
828
+ const present = yield* fs.exists(directory).pipe(Effect.orElseSucceed(() => false));
829
+ return Option.liftPredicate(directory, () => present);
830
+ });
831
+ /** @internal */
832
+ const installOne = Function.dual(DATA_FIRST_ARITY$3, (cache, lock, planned) => Effect.gen(function* install() {
833
+ const locked = Record.get(lock, planned.url);
834
+ const cached = yield* alreadyInstalled(cache, planned, locked);
835
+ if (Option.isSome(cached)) return {
836
+ planned,
837
+ directory: cached.value,
838
+ recorded: Option.none()
839
+ };
840
+ const { bytes, sha256 } = yield* downloadAsset(locked)(planned);
841
+ const directory = yield* directoryFor(cache, planned, sha256);
842
+ yield* unpackArchive(directory)(bytes);
711
843
  return {
712
- valid: Array.isReadonlyArrayEmpty(found),
713
- output: pipe(found, Array.map(format$1), Array.join("\n"))
844
+ planned,
845
+ directory,
846
+ recorded: Option.liftPredicate([planned.url, sha256], () => Option.isNone(locked))
714
847
  };
715
- }).pipe(Effect.mapError(toolFailed("h56m")));
848
+ }));
849
+ // src/features/install-tools/model/link-bin.ts
850
+ const BIN_DIRECTORY = ["node_modules", ".bin"];
851
+ const launcher = (target) => `@"${target}" %*\r\n`;
716
852
  /** @internal */
717
- const h56mCheck = withSection("h56m", (config, { root, range }) => lacksHistory(root).pipe(Effect.flatMap((partial) => scan(config, root, sourceOf(partial, range)))));
853
+ const linkExecutable = (root) => ({ name, target }) => Effect.gen(function* linkOne() {
854
+ const fs = yield* FileSystem.FileSystem;
855
+ const path = yield* Path.Path;
856
+ const directory = path.join(root, ...BIN_DIRECTORY);
857
+ yield* fs.makeDirectory(directory, { recursive: true });
858
+ if (process.platform === "win32") return yield* fs.writeFileString(path.join(directory, `${name}.cmd`), launcher(target));
859
+ const entry = path.join(directory, name);
860
+ yield* fs.remove(entry, { force: true });
861
+ return yield* fs.symlink(target, entry);
862
+ });
863
+ // src/features/install-tools/model/lock.ts
718
864
  /** @internal */
719
- const scanStagedSecrets = Function.dual(DATA_FIRST_ARITY$3, (config, root) => scan(config, root, { type: "staged" }));
865
+ const LOCK_FILE = "vpa-lock.json";
866
+ const Sha256 = Schema.String.check(Schema.isPattern(/^[0-9a-f]{64}$/u));
867
+ const LockFile = Schema.Record(Schema.String, Sha256).pipe(Schema.fromJsonString);
868
+ const byUrl = Order.mapInput(String$1.Order, ([url]) => url);
869
+ const entryLine = ([url, sha256]) => ` ${toJson(url)}: ${toJson(sha256)}`;
870
+ const render = (lock) => pipe(Record.toEntries(lock), Array.sortBy(byUrl), Array.map(entryLine), Array.join(",\n"), (body) => `{\n${body}\n}\n`);
720
871
  /** @internal */
721
- const writeTo = Function.dual(2, (sink, text) => Effect.gen(function* write() {
722
- const stdio = yield* Stdio.Stdio;
723
- yield* Stream.make(text).pipe(Stream.run(stdio[sink]()), Effect.orDie);
724
- }));
872
+ const readLock = (root) => Effect.gen(function* read() {
873
+ const fs = yield* FileSystem.FileSystem;
874
+ const path = yield* Path.Path;
875
+ const text = yield* fs.readFileString(path.join(root, LOCK_FILE));
876
+ return yield* Schema.decodeEffect(LockFile)(text);
877
+ }).pipe(Effect.orElseSucceed(() => ({})));
725
878
  /** @internal */
726
- const finish = (report) => {
727
- if (!report.valid) return Effect.fail(checksFailed(report.output));
728
- if (report.output === "") return Effect.void;
729
- return writeTo("stdout", `${report.output}\n`);
879
+ const writeLock = (root) => (lock) => Effect.gen(function* write() {
880
+ const fs = yield* FileSystem.FileSystem;
881
+ const path = yield* Path.Path;
882
+ yield* fs.writeFileString(path.join(root, LOCK_FILE), render(lock));
883
+ });
884
+ // src/features/install-tools/model/plan.ts
885
+ const SEPARATOR = "/";
886
+ const PLACEHOLDER = "{version}";
887
+ const DATA_FIRST_ARITY$2 = 2;
888
+ const withVersion = (version) => (template) => String$1.replaceAll(PLACEHOLDER, version)(template);
889
+ const defaultBase = (name) => Option.liftPredicate(`https://github.com/${name}/releases/download/v${PLACEHOLDER}`, () => String$1.includes(SEPARATOR)(name));
890
+ const binsOf = (name, bin) => Option.getOrElse(Option.fromNullishOr(bin), () => [pipe(String$1.split(SEPARATOR)(name), Array.last, Option.getOrElse(() => name))]);
891
+ const planOne = (platform) => ([name, source]) => {
892
+ const file = Record.get(source.assets, platform);
893
+ if (Option.isNone(file)) return Effect.succeedNone;
894
+ const base = Option.orElse(Option.fromNullishOr(source.base), () => defaultBase(name));
895
+ if (Option.isNone(base)) return Effect.fail(checksFailed(`vite.config "tools": ${name} needs a "base" URL`));
896
+ const render = withVersion(source.version);
897
+ return Effect.succeedSome({
898
+ name,
899
+ version: source.version,
900
+ platform,
901
+ url: `${render(base.value)}/${render(file.value)}`,
902
+ bins: binsOf(name, source.bin)
903
+ });
904
+ };
905
+ /** @internal */
906
+ const planTools = Function.dual(DATA_FIRST_ARITY$2, (section, platform) => pipe(Record.toEntries(section), Effect.forEach(planOne(platform), { concurrency: 1 }), Effect.map(Array.getSomes)));
907
+ // src/features/install-tools/model/section.ts
908
+ const DISABLED = [
909
+ "false",
910
+ "0",
911
+ "off"
912
+ ];
913
+ /** @internal */
914
+ const decodeSection = (raw) => Schema.decodeUnknownEffect(ToolsSectionSchema)(raw, { onExcessProperty: "error" }).pipe(Effect.mapError((failure) => checksFailed(`vite.config "tools": ${failure.message}`)));
915
+ /** @internal */
916
+ const toolsEnabled = Config.option(Config.String("VPA_TOOLS")).pipe(Effect.map(Option.exists((value) => Array.contains(DISABLED, String$1.toLowerCase(value)))), Effect.map((disabled) => !disabled), Effect.orElseSucceed(() => true));
917
+ // src/features/install-tools/model/install-tools.ts
918
+ const CONCURRENCY = 4;
919
+ const executablesOf = ({ planned, directory }) => Effect.forEach(planned.bins, (name) => findExecutable(directory)(name).pipe(Effect.map((target) => ({
920
+ name,
921
+ target
922
+ }))), { concurrency: 1 });
923
+ const record = (root, lock) => (installed) => {
924
+ const recorded = pipe(installed, Array.flatMap(({ recorded: entry }) => Option.toArray(entry)));
925
+ if (Array.isReadonlyArrayEmpty(recorded)) return Effect.void;
926
+ return writeLock(root)({
927
+ ...lock,
928
+ ...Record.fromEntries(recorded)
929
+ });
730
930
  };
931
+ const plannedTools = (root) => Effect.gen(function* plan() {
932
+ const config = yield* loadViteConfig(root);
933
+ const enabled = yield* toolsEnabled;
934
+ const raw = Option.fromNullishOr(config.tools);
935
+ if (Option.isNone(raw) || !enabled) return Option.none();
936
+ const section = yield* decodeSection(raw.value);
937
+ const planned = yield* planTools(section, `${process.platform}-${process.arch}`);
938
+ return Option.some(planned);
939
+ });
940
+ const installAll = (root, planned) => Effect.gen(function* installPlanned() {
941
+ const lock = yield* readLock(root);
942
+ const cache = yield* vpaCacheDirectory("tools");
943
+ const installed = yield* Effect.forEach(planned, (tool) => installOne(cache, lock, tool), { concurrency: CONCURRENCY });
944
+ yield* record(root, lock)(installed);
945
+ const found = yield* Effect.forEach(installed, executablesOf, { concurrency: CONCURRENCY });
946
+ const executables = Array.flatten(found);
947
+ yield* Effect.forEach(executables, linkExecutable(root), {
948
+ concurrency: 1,
949
+ discard: true
950
+ });
951
+ return Array.length(executables);
952
+ });
953
+ /** @internal */
954
+ const installTools = (root) => plannedTools(root).pipe(Effect.flatMap(Option.match({
955
+ onNone: () => Effect.succeedNone,
956
+ onSome: (planned) => installAll(root, planned).pipe(Effect.asSome)
957
+ })));
958
+ // src/app/prepare.ts
959
+ const reportLinked = (what, destination) => (count) => Option.match(count, {
960
+ onNone: () => Effect.void,
961
+ onSome: (linked) => writeTo("stdout", `Linked ${linked} ${what} into ${destination}\n`)
962
+ });
963
+ /** @internal */
964
+ const prepare = (root) => Layer.build(FetchHttpClient.layer).pipe(Effect.flatMap((context) => Effect.provideContext(Effect.gen(function* prepareAll() {
965
+ const skills = yield* installSkills(root);
966
+ yield* reportLinked("skills", ".agents/skills")(skills);
967
+ const tools = yield* installTools(root);
968
+ yield* reportLinked("tools", "node_modules/.bin")(tools);
969
+ }), context)), Effect.scoped);
731
970
  // src/shared/lib/workspace.ts
732
971
  const DEPENDENCY_FIELDS = [
733
972
  "dependencies",
@@ -979,7 +1218,7 @@ const runAllChecks = (root) => Effect.gen(function* all() {
979
1218
  const DATA_FIRST_ARITY = 2;
980
1219
  const USAGE = pipe([
981
1220
  "Usage: vpa run every check configured in vite.config.ts",
982
- " vpa --prepare install the skills in vite.config.ts into .agents/skills (prepare)",
1221
+ " vpa --prepare install the skills and tools in vite.config.ts (prepare)",
983
1222
  " vpa --staged scan the staged changes for secrets (pre-commit)",
984
1223
  " vpa --commit-msg <file> lint a commit message (commit-msg)",
985
1224
  " vpa --message <text> lint a message"
@@ -996,11 +1235,6 @@ const lintMessage = (toMessage) => (root, rest) => pipe(Array.head(rest), Option
996
1235
  })
997
1236
  }));
998
1237
  const readMessage = (file) => FileSystem.FileSystem.pipe(Effect.flatMap((fs) => fs.readFileString(file)));
999
- const reportLinked = Option.match({
1000
- onNone: () => Effect.void,
1001
- onSome: (count) => writeTo("stdout", `Linked ${count} skills into .agents/skills\n`)
1002
- });
1003
- const prepare = (root) => Layer.build(FetchHttpClient.layer).pipe(Effect.flatMap((context) => Effect.provideContext(installSkills(root), context)), Effect.flatMap(reportLinked), Effect.scoped);
1004
1238
  const HOOKS = {
1005
1239
  "--prepare": prepare,
1006
1240
  "--staged": stagedSecrets,
@@ -1017,4 +1251,4 @@ const runVpa = Function.dual(DATA_FIRST_ARITY, (root, args) => pipe(args, Array.
1017
1251
  })));
1018
1252
  export { VpToolsError as i, writeTo as n, loadViteConfig as r, runVpa as t };
1019
1253
 
1020
- //# sourceMappingURL=vpa-jp87uBqF.mjs.map
1254
+ //# sourceMappingURL=vpa-B16TImrg.mjs.map