@r_masseater/vite-plus-adopt 0.27.5 → 0.28.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 CHANGED
@@ -40,19 +40,12 @@ export default defineConfig({
40
40
  });
41
41
  ```
42
42
 
43
- `import type {} from "@r_masseater/vite-plus-adopt"` types the keys vpa reads (`commitlint`, `dependencyRules`, `fallow`, `h56m`, `skills`, `textlint` and `tools`) on `defineConfig`.
43
+ `import type {} from "@r_masseater/vite-plus-adopt"` types the keys vpa reads (`commitlint`, `dependencyRules`, `fallow`, `gitHooks`, `h56m`, `skills`, `textlint` and `tools`) on `defineConfig`.
44
44
  textlint checks the Markdown files Git tracks. To check other files too, list their globs (`files`) and the settings for them in `textlint.sources`. `presets` work there as well.
45
45
  `filterModules` takes textlint filter rules as modules, such as `{ comments: commentsFilter }`, and `filters: { comments: true }` turns one on, so the repository does not have to install them for textlint to find them. With `reportUnusedDirectives: true`, a `textlint-disable` comment that hides no message is an error. The check lints a file with a disable comment a second time without the filters.
46
46
  `pluginModules` takes textlint plugins as modules in the same way, and `plugins: { name: true }` turns one on. A plugin given this way parses its extensions before the built-in Markdown and text plugins do.
47
47
 
48
- Write the Git hooks like this.
49
-
50
- ```sh
51
- # .vite-hooks/pre-commit
52
- vpa --staged
53
- # .vite-hooks/commit-msg
54
- vpa --commit-msg "$1"
55
- ```
48
+ List the commands of each Git hook in `gitHooks`, such as `{ "pre-push": ["vpa --pre-push", "vp run verify"] }`, and `vpa --prepare` writes them to `.vite-hooks/` and keeps them out of Git. `vpa --pre-push` merges new commits of the default branch and the pushed branch from `origin` and stops the push, so the next push sends the merged tree.
56
49
 
57
50
  ## Agent skills
58
51
 
package/dist/cli.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { a as stagedSecrets, c as runCi, d as checkPushedRefs, i as lintMessageText, l as version, r as lintMessageFile, s as prepare, t as runAllChecks } from "./run-checks-CD8YZNJq.mjs";
2
+ import { a as stagedSecrets, c as prePush, i as lintMessageText, l as runCi, r as lintMessageFile, s as prepare, t as runAllChecks, u as version } from "./run-checks-BCW3_df1.mjs";
3
3
  import { Effect, Option, Path } from "effect";
4
4
  import { hookFlags } from "@r_masseater/masseater-utils/hook-flags";
5
5
  import { runMain } from "@r_masseater/masseater-utils/node-main";
@@ -9,7 +9,7 @@ const switched = (on, hook) => Option.liftPredicate(hook, () => on);
9
9
  const hookOf = (input) => Option.firstSomeOf([
10
10
  switched(input.prepare, prepare),
11
11
  switched(input.staged, stagedSecrets),
12
- switched(input.prePush, checkPushedRefs),
12
+ switched(input.prePush, prePush),
13
13
  input.commitMsg.pipe(Option.map(lintMessageFile)),
14
14
  input.message.pipe(Option.map(lintMessageText))
15
15
  ]).pipe(Option.getOrElse(() => runAllChecks));
package/dist/cli.mjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"cli.mjs","names":["manifest.version"],"sources":["../src/app/cli.ts"],"sourcesContent":["import { hookFlags } from \"@r_masseater/masseater-utils/hook-flags\";\nimport { runMain } from \"@r_masseater/masseater-utils/node-main\";\nimport manifest from \"@r_masseater/vite-plus-adopt/package.json\" with { type: \"json\" };\nimport { Effect, Option, Path } from \"effect\";\nimport { Command } from \"effect/cli\";\n\nimport { checkPushedRefs } from \"#/features/check-pushed-refs/index.ts\";\nimport { runCi } from \"#/features/sync-ci/index.ts\";\n\nimport { lintMessageFile, lintMessageText, stagedSecrets } from \"./hooks.ts\";\nimport { prepare } from \"./prepare.ts\";\nimport { runAllChecks } from \"./run-checks.ts\";\n\ninterface HookInput {\n readonly prepare: boolean;\n readonly staged: boolean;\n readonly prePush: boolean;\n readonly commitMsg: Option.Option<string>;\n readonly message: Option.Option<string>;\n}\n\ntype Hook = typeof runAllChecks;\n\nconst switched = (on: boolean, hook: Hook): Option.Option<Hook> =>\n Option.liftPredicate(hook, () => on);\n\nconst hookOf = (input: HookInput): Hook =>\n Option.firstSomeOf([\n switched(input.prepare, prepare),\n switched(input.staged, stagedSecrets),\n switched(input.prePush, checkPushedRefs),\n input.commitMsg.pipe(Option.map(lintMessageFile)),\n input.message.pipe(Option.map(lintMessageText)),\n ]).pipe(Option.getOrElse((): Hook => runAllChecks));\n\nconst inRepository = Effect.fn(\"inRepository\")(function* inRepository(hook: Hook) {\n const path = yield* Path.Path;\n return yield* hook(path.resolve(\".\"));\n});\n\nconst ci = Command.make(\"ci\", {}, () => inRepository(runCi)).pipe(\n Command.withDescription(\n \"Puts the shared setup action into every job and workflow that runs vp, and drops the hand-written Actions caches\",\n ),\n);\n\nconst vpa = Command.make(\"vpa\", hookFlags, (input) => inRepository(hookOf(input))).pipe(\n Command.withDescription(\"Runs every check configured in vite.config.ts\"),\n Command.withSubcommands([ci]),\n);\n\nrunMain(\"vpa\")(Command.run(vpa, { version: manifest.version }));\n"],"mappings":";;;;;;;AAuBA,MAAM,YAAY,IAAa,SAC7B,OAAO,cAAc,YAAY,EAAE;AAErC,MAAM,UAAU,UACd,OAAO,YAAY;CACjB,SAAS,MAAM,SAAS,OAAO;CAC/B,SAAS,MAAM,QAAQ,aAAa;CACpC,SAAS,MAAM,SAAS,eAAe;CACvC,MAAM,UAAU,KAAK,OAAO,IAAI,eAAe,CAAC;CAChD,MAAM,QAAQ,KAAK,OAAO,IAAI,eAAe,CAAC;AAChD,CAAC,CAAC,CAAC,KAAK,OAAO,gBAAsB,YAAY,CAAC;AAEpD,MAAM,eAAe,OAAO,GAAG,cAAc,CAAC,CAAC,UAAU,aAAa,MAAY;CAEhF,OAAO,OAAO,MAAK,OADC,KAAK,KAAA,CACD,QAAQ,GAAG,CAAC;AACtC,CAAC;AAED,MAAM,KAAK,QAAQ,KAAK,MAAM,CAAC,SAAS,aAAa,KAAK,CAAC,CAAC,CAAC,KAC3D,QAAQ,gBACN,kHACF,CACF;AAEA,MAAM,MAAM,QAAQ,KAAK,OAAO,YAAY,UAAU,aAAa,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC,KACjF,QAAQ,gBAAgB,+CAA+C,GACvE,QAAQ,gBAAgB,CAAC,EAAE,CAAC,CAC9B;AAEA,QAAQ,KAAK,CAAC,CAAC,QAAQ,IAAI,KAAK,EAAWA,QAAiB,CAAC,CAAC"}
1
+ {"version":3,"file":"cli.mjs","names":["manifest.version"],"sources":["../src/app/cli.ts"],"sourcesContent":["import { hookFlags } from \"@r_masseater/masseater-utils/hook-flags\";\nimport { runMain } from \"@r_masseater/masseater-utils/node-main\";\nimport manifest from \"@r_masseater/vite-plus-adopt/package.json\" with { type: \"json\" };\nimport { Effect, Option, Path } from \"effect\";\nimport { Command } from \"effect/cli\";\n\nimport { runCi } from \"#/features/sync-ci/index.ts\";\n\nimport { lintMessageFile, lintMessageText, stagedSecrets } from \"./hooks.ts\";\nimport { prePush } from \"./pre-push.ts\";\nimport { prepare } from \"./prepare.ts\";\nimport { runAllChecks } from \"./run-checks.ts\";\n\ninterface HookInput {\n readonly prepare: boolean;\n readonly staged: boolean;\n readonly prePush: boolean;\n readonly commitMsg: Option.Option<string>;\n readonly message: Option.Option<string>;\n}\n\ntype Hook = typeof runAllChecks;\n\nconst switched = (on: boolean, hook: Hook): Option.Option<Hook> =>\n Option.liftPredicate(hook, () => on);\n\nconst hookOf = (input: HookInput): Hook =>\n Option.firstSomeOf([\n switched(input.prepare, prepare),\n switched(input.staged, stagedSecrets),\n switched(input.prePush, prePush),\n input.commitMsg.pipe(Option.map(lintMessageFile)),\n input.message.pipe(Option.map(lintMessageText)),\n ]).pipe(Option.getOrElse((): Hook => runAllChecks));\n\nconst inRepository = Effect.fn(\"inRepository\")(function* inRepository(hook: Hook) {\n const path = yield* Path.Path;\n return yield* hook(path.resolve(\".\"));\n});\n\nconst ci = Command.make(\"ci\", {}, () => inRepository(runCi)).pipe(\n Command.withDescription(\n \"Puts the shared setup action into every job and workflow that runs vp, and drops the hand-written Actions caches\",\n ),\n);\n\nconst vpa = Command.make(\"vpa\", hookFlags, (input) => inRepository(hookOf(input))).pipe(\n Command.withDescription(\"Runs every check configured in vite.config.ts\"),\n Command.withSubcommands([ci]),\n);\n\nrunMain(\"vpa\")(Command.run(vpa, { version: manifest.version }));\n"],"mappings":";;;;;;;AAuBA,MAAM,YAAY,IAAa,SAC7B,OAAO,cAAc,YAAY,EAAE;AAErC,MAAM,UAAU,UACd,OAAO,YAAY;CACjB,SAAS,MAAM,SAAS,OAAO;CAC/B,SAAS,MAAM,QAAQ,aAAa;CACpC,SAAS,MAAM,SAAS,OAAO;CAC/B,MAAM,UAAU,KAAK,OAAO,IAAI,eAAe,CAAC;CAChD,MAAM,QAAQ,KAAK,OAAO,IAAI,eAAe,CAAC;AAChD,CAAC,CAAC,CAAC,KAAK,OAAO,gBAAsB,YAAY,CAAC;AAEpD,MAAM,eAAe,OAAO,GAAG,cAAc,CAAC,CAAC,UAAU,aAAa,MAAY;CAEhF,OAAO,OAAO,MAAK,OADC,KAAK,KAAA,CACD,QAAQ,GAAG,CAAC;AACtC,CAAC;AAED,MAAM,KAAK,QAAQ,KAAK,MAAM,CAAC,SAAS,aAAa,KAAK,CAAC,CAAC,CAAC,KAC3D,QAAQ,gBACN,kHACF,CACF;AAEA,MAAM,MAAM,QAAQ,KAAK,OAAO,YAAY,UAAU,aAAa,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC,KACjF,QAAQ,gBAAgB,+CAA+C,GACvE,QAAQ,gBAAgB,CAAC,EAAE,CAAC,CAC9B;AAEA,QAAQ,KAAK,CAAC,CAAC,QAAQ,IAAI,KAAK,EAAWA,QAAiB,CAAC,CAAC"}
package/dist/index.d.mts CHANGED
@@ -14,6 +14,23 @@ declare const VpToolsError_base: Schema.Class<VpToolsError, Schema.TaggedStruct<
14
14
  export declare class VpToolsError extends VpToolsError_base {}
15
15
  /** @internal */
16
16
  type DependencyField = DependencySection;
17
+ declare const GitHooksSectionSchema: Schema.Struct<{
18
+ readonly "applypatch-msg": Schema.optional<Schema.$Array<Schema.String>>;
19
+ readonly "commit-msg": Schema.optional<Schema.$Array<Schema.String>>;
20
+ readonly "post-applypatch": Schema.optional<Schema.$Array<Schema.String>>;
21
+ readonly "post-checkout": Schema.optional<Schema.$Array<Schema.String>>;
22
+ readonly "post-commit": Schema.optional<Schema.$Array<Schema.String>>;
23
+ readonly "post-merge": Schema.optional<Schema.$Array<Schema.String>>;
24
+ readonly "post-rewrite": Schema.optional<Schema.$Array<Schema.String>>;
25
+ readonly "pre-applypatch": Schema.optional<Schema.$Array<Schema.String>>;
26
+ readonly "pre-auto-gc": Schema.optional<Schema.$Array<Schema.String>>;
27
+ readonly "pre-commit": Schema.optional<Schema.$Array<Schema.String>>;
28
+ readonly "pre-merge-commit": Schema.optional<Schema.$Array<Schema.String>>;
29
+ readonly "pre-push": Schema.optional<Schema.$Array<Schema.String>>;
30
+ readonly "pre-rebase": Schema.optional<Schema.$Array<Schema.String>>;
31
+ readonly "prepare-commit-msg": Schema.optional<Schema.$Array<Schema.String>>;
32
+ }>;
33
+ type GitHooksSection = typeof GitHooksSectionSchema.Encoded;
17
34
  declare const SkillsSectionSchema: Schema.$Record<Schema.Union<readonly [Schema.String, Schema.String]>, Schema.Union<readonly [Schema.Struct<{
18
35
  readonly commit: Schema.String;
19
36
  readonly root: Schema.optional<Schema.Union<readonly [Schema.String, Schema.NonEmptyArray<Schema.String>]>>;
@@ -63,6 +80,7 @@ interface ToolSections {
63
80
  readonly commitlint?: CommitlintConfig;
64
81
  readonly dependencyRules?: DependencyRules;
65
82
  readonly fallow?: FallowConfig;
83
+ readonly gitHooks?: GitHooksSection;
66
84
  readonly h56m?: H56mConfig;
67
85
  readonly skills?: SkillsSection;
68
86
  readonly textlint?: TextlintConfig;
@@ -95,5 +113,5 @@ interface CiDrift {
95
113
  type Services = FileSystem.FileSystem | Path.Path;
96
114
  /** @internal */
97
115
  export declare const findCiDrift: (root: string) => Effect.Effect<readonly CiDrift[], never, Services>;
98
- export type { CiDrift, CommitlintConfig, DependencyRules, FallowConfig, SkillsSection, TextlintConfig, ToolSections };
116
+ export type { CiDrift, CommitlintConfig, DependencyRules, FallowConfig, GitHooksSection, SkillsSection, TextlintConfig, ToolSections };
99
117
  //# sourceMappingURL=index.d.mts.map
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { f as loadViteConfig, n as HOOKS, o as usage, p as VpToolsError, t as runAllChecks, u as findCiDrift } from "./run-checks-CD8YZNJq.mjs";
1
+ import { d as findCiDrift, f as loadViteConfig, n as HOOKS, o as usage, p as VpToolsError, t as runAllChecks } from "./run-checks-BCW3_df1.mjs";
2
2
  import { Array, Function, Option, Record, pipe } from "effect";
3
3
  /** @internal */
4
4
  const runVpa = Function.dual(2, (root, args) => pipe(args, Array.match({
@@ -1,10 +1,10 @@
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, Match, Number, 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 { ChildProcess, ChildProcessSpawner } from "effect/process";
5
4
  import format from "@commitlint/format";
6
5
  import lint from "@commitlint/lint";
7
6
  import load from "@commitlint/load";
7
+ import { ChildProcess, ChildProcessSpawner } from "effect/process";
8
8
  import { createLinter, loadLinterFormatter } from "textlint";
9
9
  import { loadPackagesFromRawConfig } from "@textlint/config-loader";
10
10
  import { TextlintKernelDescriptor } from "@textlint/kernel";
@@ -64,34 +64,6 @@ const loadViteConfig = (root) => findConfigFile(root).pipe(Effect.flatMap((file)
64
64
  const requireSection = (key) => (config) => Effect.fromOption(Option.fromNullishOr(config[key])).pipe(Effect.mapError(() => configMissing(`vite.config has no "${key}" section`)));
65
65
  /** @internal */
66
66
  const loadSection = Function.dual(2, (root, key) => loadViteConfig(root).pipe(Effect.flatMap(requireSection(key))));
67
- // src/features/check-pushed-refs/model/pushed-refs.ts
68
- const DELETED = /^0+$/u;
69
- const TAG = "refs/tags/";
70
- const pushedRefOf = (line) => pipe(String$1.split(String$1.trim(line), /\s+/u), Array.match({
71
- onEmpty: () => [],
72
- onNonEmpty: ([localRef, localSha = "", remoteRef = ""]) => [{
73
- localRef,
74
- localSha,
75
- remoteRef
76
- }]
77
- }));
78
- const isPushedBranch = ({ localSha, remoteRef }) => localSha !== "" && !DELETED.test(localSha) && !String$1.startsWith(TAG)(remoteRef);
79
- const refsOtherThan = (head, stdin) => pipe(String$1.split(stdin, "\n"), Array.flatMap(pushedRefOf), Array.filter((ref) => isPushedBranch(ref) && ref.localSha !== head), Array.map(({ localRef, remoteRef }) => `${localRef} -> ${remoteRef}`));
80
- const messageFor = (refs) => pipe([
81
- "pre-push checks only the tree that is checked out, and these refs point at other commits:",
82
- ...pipe(refs, Array.map((ref) => ` ${ref}`)),
83
- "Check out each branch and push it on its own, so its own tree is checked."
84
- ], Array.join("\n"));
85
- /** @internal */
86
- const checkPushedRefs = (root) => Effect.gen(function* pushedRefs() {
87
- const stdio = yield* Stdio.Stdio;
88
- const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
89
- const stdin = yield* stdio.stdin.pipe(Stream.decodeText(), Stream.mkString);
90
- const head = yield* spawner.string(ChildProcess.make("git", ["rev-parse", "HEAD"], { cwd: root }));
91
- const others = refsOtherThan(String$1.trim(head), stdin);
92
- if (Array.isReadonlyArrayNonEmpty(others)) return yield* checksFailed(messageFor(others));
93
- return yield* Effect.void;
94
- });
95
67
  // src/features/check-text/model/commitlint.ts
96
68
  const DATA_FIRST_ARITY_3$1 = 3;
97
69
  const COMMENT_CHAR = "#";
@@ -357,7 +329,7 @@ const textlintCheck = withSection("textlint", (config, { root }) => {
357
329
  const commitlintCheck = withSection("commitlint", (config, { root, range }) => listCommitMessages(root, range).pipe(Effect.flatMap((messages) => lintCommitMessages(config, root, messages))));
358
330
  // src/features/scan-secrets/model/secret-checks.ts
359
331
  const DATA_FIRST_ARITY$5 = 2;
360
- const SUCCESS$1 = 0;
332
+ const SUCCESS$2 = 0;
361
333
  const RANGE = "..";
362
334
  const HEAD = "HEAD";
363
335
  const lacksHistory = (root) => Effect.gen(function* history() {
@@ -368,7 +340,7 @@ const lacksHistory = (root) => Effect.gen(function* history() {
368
340
  "--get",
369
341
  "remote.origin.promisor"
370
342
  ], { cwd: root }));
371
- return String$1.trim(shallow) === "true" || promisor === SUCCESS$1;
343
+ return String$1.trim(shallow) === "true" || promisor === SUCCESS$2;
372
344
  });
373
345
  const historyOf = (range) => pipe(String$1.split(range, RANGE), Array.match({
374
346
  onEmpty: () => ({
@@ -920,7 +892,7 @@ const syncCi = (root) => planned(root).pipe(Effect.flatMap(({ changes }) => Effe
920
892
  })));
921
893
  // package.json
922
894
  var name = "@r_masseater/vite-plus-adopt";
923
- var version = "0.27.5";
895
+ var version = "0.28.0";
924
896
  // src/features/sync-ci/model/installed-version.ts
925
897
  const RANGE_PREFIX = /^[\^~]/u;
926
898
  const pnpm$1 = attempt("pnpm");
@@ -938,6 +910,98 @@ const guardInstalledVersion = (root) => declaredIn(root).pipe(Effect.map((declar
938
910
  // src/features/sync-ci/model/run-ci.ts
939
911
  /** @internal */
940
912
  const runCi = (root) => guardInstalledVersion(root).pipe(Effect.andThen(syncCi(root)));
913
+ // src/features/check-pushed-refs/model/pushed-refs.ts
914
+ const DELETED = /^0+$/u;
915
+ const TAG = "refs/tags/";
916
+ const pushedRefOf = (line) => pipe(String$1.split(String$1.trim(line), /\s+/u), Array.match({
917
+ onEmpty: () => [],
918
+ onNonEmpty: ([localRef, localSha = "", remoteRef = ""]) => [{
919
+ localRef,
920
+ localSha,
921
+ remoteRef
922
+ }]
923
+ }));
924
+ const isPushedBranch = ({ localSha, remoteRef }) => localSha !== "" && !DELETED.test(localSha) && !String$1.startsWith(TAG)(remoteRef);
925
+ const refsOtherThan = (head, stdin) => pipe(String$1.split(stdin, "\n"), Array.flatMap(pushedRefOf), Array.filter((ref) => isPushedBranch(ref) && ref.localSha !== head), Array.map(({ localRef, remoteRef }) => `${localRef} -> ${remoteRef}`));
926
+ const messageFor = (refs) => pipe([
927
+ "pre-push checks only the tree that is checked out, and these refs point at other commits:",
928
+ ...pipe(refs, Array.map((ref) => ` ${ref}`)),
929
+ "Check out each branch and push it on its own, so its own tree is checked."
930
+ ], Array.join("\n"));
931
+ /** @internal */
932
+ const checkPushedRefs = (root) => Effect.gen(function* pushedRefs() {
933
+ const stdio = yield* Stdio.Stdio;
934
+ const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
935
+ const stdin = yield* stdio.stdin.pipe(Stream.decodeText(), Stream.mkString);
936
+ const head = yield* spawner.string(ChildProcess.make("git", ["rev-parse", "HEAD"], { cwd: root }));
937
+ const others = refsOtherThan(String$1.trim(head), stdin);
938
+ if (Array.isReadonlyArrayNonEmpty(others)) return yield* checksFailed(messageFor(others));
939
+ return yield* Effect.void;
940
+ });
941
+ // src/features/merge-remote/model/merge-remote.ts
942
+ const SUCCESS$1 = 0;
943
+ const REMOTE = "origin";
944
+ const DETACHED = "HEAD";
945
+ const FALLBACK_BASE = "main";
946
+ const DEFAULT_BRANCH = /^ref: refs\/heads\/(?<branch>\S+)\s+HEAD$/mu;
947
+ const succeeded = (root, args) => ChildProcessSpawner.ChildProcessSpawner.pipe(Effect.flatMap((spawner) => spawner.exitCode(ChildProcess.make("git", args, {
948
+ cwd: root,
949
+ stdout: "ignore"
950
+ }))), Effect.map((code) => code === SUCCESS$1));
951
+ const gitText = (root, args) => ChildProcessSpawner.ChildProcessSpawner.pipe(Effect.flatMap((spawner) => spawner.string(ChildProcess.make("git", args, { cwd: root }))), Effect.map(String$1.trim), Effect.asSome, Effect.orElseSucceed(() => Option.none()));
952
+ /** @internal */
953
+ const defaultBranchOf = (listing) => pipe(Option.fromNullishOr(DEFAULT_BRANCH.exec(listing)), Option.flatMapNullishOr((match) => match.groups), Option.flatMapNullishOr((groups) => groups["branch"]), Option.getOrElse(() => FALLBACK_BASE));
954
+ const isBehind = (root) => (branch) => Effect.gen(function* behind() {
955
+ if (!(yield* succeeded(root, [
956
+ "fetch",
957
+ "--quiet",
958
+ REMOTE,
959
+ branch
960
+ ]))) return false;
961
+ return !(yield* succeeded(root, [
962
+ "merge-base",
963
+ "--is-ancestor",
964
+ `${REMOTE}/${branch}`,
965
+ "HEAD"
966
+ ]));
967
+ });
968
+ const mergeRefs = (root, branch, refs) => Effect.gen(function* merge() {
969
+ const named = pipe(refs, Array.join(" and "));
970
+ if (yield* succeeded(root, [
971
+ "merge",
972
+ "--no-edit",
973
+ ...refs
974
+ ])) return yield* checksFailed(`Merged ${named} into ${branch}. Push again so the merged tree is checked and pushed.`);
975
+ yield* succeeded(root, ["merge", "--abort"]);
976
+ return yield* checksFailed(`${named} has commits that conflict with this branch. Merge it, resolve the conflicts, and push again.`);
977
+ });
978
+ const mergeBehind = (root, branch) => Effect.gen(function* behind() {
979
+ const listing = yield* gitText(root, [
980
+ "ls-remote",
981
+ "--symref",
982
+ REMOTE,
983
+ "HEAD"
984
+ ]);
985
+ const base = defaultBranchOf(Option.getOrElse(listing, () => ""));
986
+ const stale = yield* Effect.filter(Array.dedupe([base, branch]), isBehind(root));
987
+ const refs = pipe(stale, Array.map((name) => `${REMOTE}/${name}`));
988
+ return yield* Array.match(refs, {
989
+ onEmpty: () => Effect.void,
990
+ onNonEmpty: (named) => mergeRefs(root, branch, named)
991
+ });
992
+ });
993
+ /** @internal */
994
+ const mergeRemote = (root) => gitText(root, [
995
+ "rev-parse",
996
+ "--abbrev-ref",
997
+ "HEAD"
998
+ ]).pipe(Effect.map(Option.filter((branch) => branch !== DETACHED)), Effect.flatMap(Option.match({
999
+ onNone: () => Effect.void,
1000
+ onSome: (branch) => mergeBehind(root, branch)
1001
+ })));
1002
+ // src/app/pre-push.ts
1003
+ /** @internal */
1004
+ const prePush = (root) => checkPushedRefs(root).pipe(Effect.andThen(mergeRemote(root)));
941
1005
  // src/shared/config/skills.ts
942
1006
  const Repository = Schema.String.check(Schema.isPattern(/^[\w-][\w.-]*\/[\w.-]+$/u));
943
1007
  const LocalDirectory = Schema.String.check(Schema.isPattern(/^\.\/[\w.-]+(?:\/[\w.-]+)*$/u));
@@ -967,6 +1031,24 @@ const ToolSourceSchema = Schema.Struct({
967
1031
  assets: Schema.Record(Platform, AssetFile)
968
1032
  });
969
1033
  const ToolsSectionSchema = Schema.Record(ToolName, ToolSourceSchema);
1034
+ // src/shared/config/git-hooks.ts
1035
+ const Commands = Schema.String.pipe(Schema.Array, Schema.optional);
1036
+ const GitHooksSectionSchema = Schema.Struct({
1037
+ "applypatch-msg": Commands,
1038
+ "commit-msg": Commands,
1039
+ "post-applypatch": Commands,
1040
+ "post-checkout": Commands,
1041
+ "post-commit": Commands,
1042
+ "post-merge": Commands,
1043
+ "post-rewrite": Commands,
1044
+ "pre-applypatch": Commands,
1045
+ "pre-auto-gc": Commands,
1046
+ "pre-commit": Commands,
1047
+ "pre-merge-commit": Commands,
1048
+ "pre-push": Commands,
1049
+ "pre-rebase": Commands,
1050
+ "prepare-commit-msg": Commands
1051
+ });
970
1052
  // src/shared/lib/cache.ts
971
1053
  const ROOT$2 = ["vpa"];
972
1054
  const variable = (name) => Config.option(Config.NonEmptyString(name)).pipe(Effect.orElseSucceed(Option.none));
@@ -1634,7 +1716,110 @@ const installTools = (root) => plannedTools(root).pipe(Effect.flatMap(Option.mat
1634
1716
  onNone: () => Effect.succeedNone,
1635
1717
  onSome: (planned) => installAll(root, planned).pipe(Effect.asSome)
1636
1718
  })));
1719
+ // src/features/write-git-hooks/model/git-hooks.ts
1720
+ const HOOKS_DIRECTORY = ".vite-hooks";
1721
+ const ATTRIBUTES = ".gitattributes";
1722
+ const LFS_FILTER = /filter=lfs/u;
1723
+ const LFS_HOOKS = [
1724
+ "post-checkout",
1725
+ "post-commit",
1726
+ "post-merge",
1727
+ "pre-push"
1728
+ ];
1729
+ const BEGIN = "# vite-plus-adopt git hooks: begin";
1730
+ const END = "# vite-plus-adopt git hooks: end";
1731
+ const ENTRY = `/${HOOKS_DIRECTORY}/`;
1732
+ const NONE$1 = 0;
1733
+ const END_LINE = 1;
1734
+ const readIfPresent = (fs, file) => fs.readFileString(file).pipe(Effect.asSome, Effect.orElseSucceed(() => Option.none()));
1735
+ const decodeHooks = (raw) => Schema.decodeUnknownEffect(GitHooksSectionSchema)(raw, { onExcessProperty: "error" }).pipe(Effect.mapError((failure) => checksFailed(`vite.config "gitHooks": ${failure.message}`)));
1736
+ const commandsFor = (commands, name) => Option.getOrElse(Option.fromNullishOr(commands[name]), () => []);
1737
+ const scriptOf = (commands, lfs) => (name) => ({
1738
+ name,
1739
+ text: pipe(Option.liftPredicate(`git lfs ${name} "$@"`, () => Array.contains(lfs, name)), Option.toArray, Array.appendAll(commandsFor(commands, name)), Array.map(String$1.concat("\n")), Array.join(""))
1740
+ });
1741
+ /** @internal */
1742
+ const scriptsOf = (commands, usesLfs) => {
1743
+ const lfs = pipe(LFS_HOOKS, Array.filter(() => usesLfs));
1744
+ return pipe(Array.dedupe([...Record.keys(commands), ...lfs]), Array.map(scriptOf(commands, lfs)));
1745
+ };
1746
+ /** @internal */
1747
+ const withoutBlock = (exclude) => {
1748
+ const lines = String$1.split(exclude, "\n");
1749
+ const before = pipe(lines, Array.takeWhile((line) => line !== BEGIN));
1750
+ const after = pipe(lines, Array.dropWhile((line) => line !== END), Array.drop(END_LINE));
1751
+ return pipe([...before, ...after], Array.join("\n"));
1752
+ };
1753
+ /** @internal */
1754
+ const generatedNames = (exclude) => pipe(String$1.split(exclude, "\n"), Array.dropWhile((line) => line !== BEGIN), Array.takeWhile((line) => line !== END), Array.filter(String$1.startsWith(ENTRY)), Array.map(String$1.slice(ENTRY.length)));
1755
+ const blockOf = (scripts) => pipe(scripts, Array.map(({ name }) => `${ENTRY}${name}`), (entries) => [
1756
+ BEGIN,
1757
+ ...entries,
1758
+ END
1759
+ ], Array.join("\n"));
1760
+ const excludeFileOf = (root) => Effect.gen(function* gitPath() {
1761
+ const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
1762
+ const path = yield* Path.Path;
1763
+ const relative = yield* spawner.string(ChildProcess.make("git", [
1764
+ "rev-parse",
1765
+ "--git-path",
1766
+ "info/exclude"
1767
+ ], { cwd: root }));
1768
+ return path.resolve(root, String$1.trim(relative));
1769
+ });
1770
+ const writeScript = (fs, directory, path) => (script) => Effect.gen(function* one() {
1771
+ const file = path.join(directory, script.name);
1772
+ const current = yield* readIfPresent(fs, file);
1773
+ if (Option.contains(current, script.text)) return false;
1774
+ yield* fs.writeFileString(file, script.text);
1775
+ return true;
1776
+ });
1777
+ const sectionOf = (root) => Effect.gen(function* section() {
1778
+ const fs = yield* FileSystem.FileSystem;
1779
+ const path = yield* Path.Path;
1780
+ const config = yield* loadViteConfig(root);
1781
+ const commands = yield* decodeHooks(Option.getOrElse(Option.fromNullishOr(config.gitHooks), () => ({})));
1782
+ const attributes = yield* readIfPresent(fs, path.join(root, ATTRIBUTES));
1783
+ return scriptsOf(commands, Option.exists(attributes, (text) => LFS_FILTER.test(text)));
1784
+ });
1785
+ const removeStale = (directory, exclude, scripts) => Effect.gen(function* remove() {
1786
+ const fs = yield* FileSystem.FileSystem;
1787
+ const path = yield* Path.Path;
1788
+ const current = pipe(scripts, Array.map(({ name }) => name));
1789
+ const stale = Array.difference(generatedNames(exclude), current);
1790
+ yield* Effect.forEach(stale, (name) => fs.remove(path.join(directory, name), { force: true }), {
1791
+ concurrency: 1,
1792
+ discard: true
1793
+ });
1794
+ });
1795
+ const updateExclude = (excludeFile, exclude, scripts) => Effect.gen(function* update() {
1796
+ const fs = yield* FileSystem.FileSystem;
1797
+ const path = yield* Path.Path;
1798
+ yield* fs.makeDirectory(path.dirname(excludeFile), { recursive: true });
1799
+ yield* fs.writeFileString(excludeFile, `${String$1.trimEnd(withoutBlock(exclude))}\n${blockOf(scripts)}\n`);
1800
+ });
1801
+ const syncScripts = (root, scripts) => Effect.gen(function* sync() {
1802
+ const fs = yield* FileSystem.FileSystem;
1803
+ const path = yield* Path.Path;
1804
+ const directory = path.join(root, HOOKS_DIRECTORY);
1805
+ const excludeFile = yield* excludeFileOf(root);
1806
+ const read = yield* readIfPresent(fs, excludeFile);
1807
+ const exclude = Option.getOrElse(read, () => "");
1808
+ yield* removeStale(directory, exclude, scripts);
1809
+ const written = yield* Effect.forEach(scripts, writeScript(fs, directory, path), { concurrency: 1 });
1810
+ yield* updateExclude(excludeFile, exclude, scripts);
1811
+ return pipe(written, Array.filter(Boolean), Array.length);
1812
+ });
1813
+ /** @internal */
1814
+ const writeGitHooks = (root) => Effect.gen(function* write() {
1815
+ const fs = yield* FileSystem.FileSystem;
1816
+ const path = yield* Path.Path;
1817
+ if (!(yield* fs.exists(path.join(root, HOOKS_DIRECTORY)))) return NONE$1;
1818
+ const scripts = yield* sectionOf(root);
1819
+ return yield* syncScripts(root, scripts);
1820
+ });
1637
1821
  // src/app/prepare.ts
1822
+ const NONE = 0;
1638
1823
  const reportLinked = (what, destination) => (count) => Option.match(count, {
1639
1824
  onNone: () => Effect.void,
1640
1825
  onSome: (linked) => writeTo("stdout", `Linked ${linked} ${what} into ${destination}\n`)
@@ -1645,6 +1830,8 @@ const prepare = (root) => Layer.build(FetchHttpClient.layer).pipe(Effect.flatMap
1645
1830
  yield* reportLinked("skills", ".agents/skills")(skills);
1646
1831
  const tools = yield* installTools(root);
1647
1832
  yield* reportLinked("tools", "node_modules/.bin")(tools);
1833
+ const hooks = yield* writeGitHooks(root);
1834
+ yield* reportLinked("git hooks", ".vite-hooks")(Option.liftPredicate(hooks, (count) => count > NONE));
1648
1835
  }), context)), Effect.scoped);
1649
1836
  // src/app/hooks.ts
1650
1837
  const USAGE = pipe([
@@ -1682,7 +1869,7 @@ const HOOKS = {
1682
1869
  "--staged": stagedSecrets,
1683
1870
  "--commit-msg": withArgument(lintMessageFile),
1684
1871
  "--message": withArgument(lintMessageText),
1685
- "--pre-push": checkPushedRefs
1872
+ "--pre-push": prePush
1686
1873
  };
1687
1874
  // src/shared/lib/workspace.ts
1688
1875
  const MANIFEST_FILE = "package.json";
@@ -1925,6 +2112,6 @@ const runAllChecks = (root) => Effect.gen(function* all() {
1925
2112
  onNonEmpty: (failed) => Effect.fail(checksFailed(`Failed: ${Array.join(failed, ", ")}`))
1926
2113
  }));
1927
2114
  });
1928
- export { stagedSecrets as a, runCi as c, checkPushedRefs as d, loadViteConfig as f, lintMessageText as i, version as l, HOOKS as n, usage as o, VpToolsError as p, lintMessageFile as r, prepare as s, runAllChecks as t, findCiDrift as u };
2115
+ export { stagedSecrets as a, prePush as c, findCiDrift as d, loadViteConfig as f, lintMessageText as i, runCi as l, HOOKS as n, usage as o, VpToolsError as p, lintMessageFile as r, prepare as s, runAllChecks as t, version as u };
1929
2116
 
1930
- //# sourceMappingURL=run-checks-CD8YZNJq.mjs.map
2117
+ //# sourceMappingURL=run-checks-BCW3_df1.mjs.map