@seasb/metafab 0.0.0-stage → 1.0.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 +47 -2
- package/dist/cli.d.ts +11 -0
- package/dist/cli.js +317 -0
- package/dist/cli.js.map +1 -0
- package/dist/commands/build.d.ts +2 -0
- package/dist/commands/build.js +70 -0
- package/dist/commands/build.js.map +1 -0
- package/dist/commands/check.d.ts +2 -0
- package/dist/commands/check.js +41 -0
- package/dist/commands/check.js.map +1 -0
- package/dist/commands/create.d.ts +2 -0
- package/dist/commands/create.js +74 -0
- package/dist/commands/create.js.map +1 -0
- package/dist/commands/detach.d.ts +2 -0
- package/dist/commands/detach.js +24 -0
- package/dist/commands/detach.js.map +1 -0
- package/dist/commands/diff.d.ts +2 -0
- package/dist/commands/diff.js +35 -0
- package/dist/commands/diff.js.map +1 -0
- package/dist/commands/import.d.ts +2 -0
- package/dist/commands/import.js +107 -0
- package/dist/commands/import.js.map +1 -0
- package/dist/commands/init.d.ts +2 -0
- package/dist/commands/init.js +77 -0
- package/dist/commands/init.js.map +1 -0
- package/dist/commands/map.d.ts +2 -0
- package/dist/commands/map.js +43 -0
- package/dist/commands/map.js.map +1 -0
- package/dist/commands/not-implemented.d.ts +2 -0
- package/dist/commands/not-implemented.js +19 -0
- package/dist/commands/not-implemented.js.map +1 -0
- package/dist/commands/pipeline-add.d.ts +2 -0
- package/dist/commands/pipeline-add.js +67 -0
- package/dist/commands/pipeline-add.js.map +1 -0
- package/dist/commands/pipeline-remove.d.ts +2 -0
- package/dist/commands/pipeline-remove.js +44 -0
- package/dist/commands/pipeline-remove.js.map +1 -0
- package/dist/commands/publish.d.ts +2 -0
- package/dist/commands/publish.js +147 -0
- package/dist/commands/publish.js.map +1 -0
- package/dist/commands/types.d.ts +45 -0
- package/dist/commands/types.js +2 -0
- package/dist/commands/types.js.map +1 -0
- package/dist/commands/update.d.ts +2 -0
- package/dist/commands/update.js +97 -0
- package/dist/commands/update.js.map +1 -0
- package/dist/core/adopt.d.ts +53 -0
- package/dist/core/adopt.js +676 -0
- package/dist/core/adopt.js.map +1 -0
- package/dist/core/build/agents.d.ts +23 -0
- package/dist/core/build/agents.js +60 -0
- package/dist/core/build/agents.js.map +1 -0
- package/dist/core/build/index.d.ts +4 -0
- package/dist/core/build/index.js +5 -0
- package/dist/core/build/index.js.map +1 -0
- package/dist/core/build/markers.d.ts +34 -0
- package/dist/core/build/markers.js +97 -0
- package/dist/core/build/markers.js.map +1 -0
- package/dist/core/build/plan.d.ts +48 -0
- package/dist/core/build/plan.js +792 -0
- package/dist/core/build/plan.js.map +1 -0
- package/dist/core/build/skill.d.ts +60 -0
- package/dist/core/build/skill.js +275 -0
- package/dist/core/build/skill.js.map +1 -0
- package/dist/core/check/drift.d.ts +13 -0
- package/dist/core/check/drift.js +205 -0
- package/dist/core/check/drift.js.map +1 -0
- package/dist/core/check/index.d.ts +12 -0
- package/dist/core/check/index.js +78 -0
- package/dist/core/check/index.js.map +1 -0
- package/dist/core/check/markers.d.ts +9 -0
- package/dist/core/check/markers.js +220 -0
- package/dist/core/check/markers.js.map +1 -0
- package/dist/core/config/destinations.d.ts +5 -0
- package/dist/core/config/destinations.js +20 -0
- package/dist/core/config/destinations.js.map +1 -0
- package/dist/core/config/load.d.ts +4 -0
- package/dist/core/config/load.js +41 -0
- package/dist/core/config/load.js.map +1 -0
- package/dist/core/config/parse.d.ts +8 -0
- package/dist/core/config/parse.js +198 -0
- package/dist/core/config/parse.js.map +1 -0
- package/dist/core/config/source.d.ts +14 -0
- package/dist/core/config/source.js +44 -0
- package/dist/core/config/source.js.map +1 -0
- package/dist/core/config/types.d.ts +48 -0
- package/dist/core/config/types.js +2 -0
- package/dist/core/config/types.js.map +1 -0
- package/dist/core/config/validate.d.ts +11 -0
- package/dist/core/config/validate.js +351 -0
- package/dist/core/config/validate.js.map +1 -0
- package/dist/core/config/writers.d.ts +14 -0
- package/dist/core/config/writers.js +261 -0
- package/dist/core/config/writers.js.map +1 -0
- package/dist/core/config.d.ts +7 -0
- package/dist/core/config.js +8 -0
- package/dist/core/config.js.map +1 -0
- package/dist/core/discovery.d.ts +34 -0
- package/dist/core/discovery.js +272 -0
- package/dist/core/discovery.js.map +1 -0
- package/dist/core/edit/create.d.ts +18 -0
- package/dist/core/edit/create.js +190 -0
- package/dist/core/edit/create.js.map +1 -0
- package/dist/core/edit/document.d.ts +4 -0
- package/dist/core/edit/document.js +16 -0
- package/dist/core/edit/document.js.map +1 -0
- package/dist/core/edit/factory-yaml.d.ts +17 -0
- package/dist/core/edit/factory-yaml.js +211 -0
- package/dist/core/edit/factory-yaml.js.map +1 -0
- package/dist/core/edit/files.d.ts +6 -0
- package/dist/core/edit/files.js +47 -0
- package/dist/core/edit/files.js.map +1 -0
- package/dist/core/edit/index.d.ts +9 -0
- package/dist/core/edit/index.js +10 -0
- package/dist/core/edit/index.js.map +1 -0
- package/dist/core/edit/map.d.ts +24 -0
- package/dist/core/edit/map.js +82 -0
- package/dist/core/edit/map.js.map +1 -0
- package/dist/core/edit/names.d.ts +2 -0
- package/dist/core/edit/names.js +17 -0
- package/dist/core/edit/names.js.map +1 -0
- package/dist/core/edit/paths.d.ts +8 -0
- package/dist/core/edit/paths.js +76 -0
- package/dist/core/edit/paths.js.map +1 -0
- package/dist/core/edit/pipeline.d.ts +19 -0
- package/dist/core/edit/pipeline.js +146 -0
- package/dist/core/edit/pipeline.js.map +1 -0
- package/dist/core/edit/skill.d.ts +1 -0
- package/dist/core/edit/skill.js +10 -0
- package/dist/core/edit/skill.js.map +1 -0
- package/dist/core/factory/discovery.d.ts +9 -0
- package/dist/core/factory/discovery.js +139 -0
- package/dist/core/factory/discovery.js.map +1 -0
- package/dist/core/factory/factory-yaml.d.ts +16 -0
- package/dist/core/factory/factory-yaml.js +375 -0
- package/dist/core/factory/factory-yaml.js.map +1 -0
- package/dist/core/factory/index.d.ts +5 -0
- package/dist/core/factory/index.js +6 -0
- package/dist/core/factory/index.js.map +1 -0
- package/dist/core/factory/lines.d.ts +8 -0
- package/dist/core/factory/lines.js +11 -0
- package/dist/core/factory/lines.js.map +1 -0
- package/dist/core/factory/load.d.ts +4 -0
- package/dist/core/factory/load.js +81 -0
- package/dist/core/factory/load.js.map +1 -0
- package/dist/core/factory/requires.d.ts +9 -0
- package/dist/core/factory/requires.js +123 -0
- package/dist/core/factory/requires.js.map +1 -0
- package/dist/core/factory/types.d.ts +45 -0
- package/dist/core/factory/types.js +2 -0
- package/dist/core/factory/types.js.map +1 -0
- package/dist/core/factory/validate.d.ts +41 -0
- package/dist/core/factory/validate.js +441 -0
- package/dist/core/factory/validate.js.map +1 -0
- package/dist/core/hooks/index.d.ts +8 -0
- package/dist/core/hooks/index.js +15 -0
- package/dist/core/hooks/index.js.map +1 -0
- package/dist/core/hooks/script.d.ts +21 -0
- package/dist/core/hooks/script.js +34 -0
- package/dist/core/hooks/script.js.map +1 -0
- package/dist/core/hooks/sync.d.ts +17 -0
- package/dist/core/hooks/sync.js +262 -0
- package/dist/core/hooks/sync.js.map +1 -0
- package/dist/core/import/conflicts.d.ts +82 -0
- package/dist/core/import/conflicts.js +256 -0
- package/dist/core/import/conflicts.js.map +1 -0
- package/dist/core/import/copy.d.ts +10 -0
- package/dist/core/import/copy.js +76 -0
- package/dist/core/import/copy.js.map +1 -0
- package/dist/core/import/file-tree.d.ts +43 -0
- package/dist/core/import/file-tree.js +107 -0
- package/dist/core/import/file-tree.js.map +1 -0
- package/dist/core/import/index.d.ts +5 -0
- package/dist/core/import/index.js +6 -0
- package/dist/core/import/index.js.map +1 -0
- package/dist/core/import/pipeline-changes.d.ts +8 -0
- package/dist/core/import/pipeline-changes.js +89 -0
- package/dist/core/import/pipeline-changes.js.map +1 -0
- package/dist/core/import/run.d.ts +76 -0
- package/dist/core/import/run.js +258 -0
- package/dist/core/import/run.js.map +1 -0
- package/dist/core/init/gitattributes.d.ts +20 -0
- package/dist/core/init/gitattributes.js +89 -0
- package/dist/core/init/gitattributes.js.map +1 -0
- package/dist/core/init/index.d.ts +4 -0
- package/dist/core/init/index.js +5 -0
- package/dist/core/init/index.js.map +1 -0
- package/dist/core/init/name.d.ts +1 -0
- package/dist/core/init/name.js +4 -0
- package/dist/core/init/name.js.map +1 -0
- package/dist/core/init/run.d.ts +51 -0
- package/dist/core/init/run.js +261 -0
- package/dist/core/init/run.js.map +1 -0
- package/dist/core/init/targets.d.ts +17 -0
- package/dist/core/init/targets.js +87 -0
- package/dist/core/init/targets.js.map +1 -0
- package/dist/core/merge.d.ts +88 -0
- package/dist/core/merge.js +239 -0
- package/dist/core/merge.js.map +1 -0
- package/dist/core/publish/exclude.d.ts +9 -0
- package/dist/core/publish/exclude.js +32 -0
- package/dist/core/publish/exclude.js.map +1 -0
- package/dist/core/publish/git-target.d.ts +32 -0
- package/dist/core/publish/git-target.js +447 -0
- package/dist/core/publish/git-target.js.map +1 -0
- package/dist/core/publish/index.d.ts +10 -0
- package/dist/core/publish/index.js +11 -0
- package/dist/core/publish/index.js.map +1 -0
- package/dist/core/publish/npm-target.d.ts +15 -0
- package/dist/core/publish/npm-target.js +170 -0
- package/dist/core/publish/npm-target.js.map +1 -0
- package/dist/core/publish/package-json.d.ts +31 -0
- package/dist/core/publish/package-json.js +74 -0
- package/dist/core/publish/package-json.js.map +1 -0
- package/dist/core/publish/prepare.d.ts +24 -0
- package/dist/core/publish/prepare.js +93 -0
- package/dist/core/publish/prepare.js.map +1 -0
- package/dist/core/publish/provenance.d.ts +1 -0
- package/dist/core/publish/provenance.js +20 -0
- package/dist/core/publish/provenance.js.map +1 -0
- package/dist/core/publish/publish.d.ts +13 -0
- package/dist/core/publish/publish.js +130 -0
- package/dist/core/publish/publish.js.map +1 -0
- package/dist/core/publish/readme.d.ts +22 -0
- package/dist/core/publish/readme.js +112 -0
- package/dist/core/publish/readme.js.map +1 -0
- package/dist/core/publish/stage.d.ts +19 -0
- package/dist/core/publish/stage.js +333 -0
- package/dist/core/publish/stage.js.map +1 -0
- package/dist/core/publish/types.d.ts +71 -0
- package/dist/core/publish/types.js +2 -0
- package/dist/core/publish/types.js.map +1 -0
- package/dist/core/requires/check.d.ts +15 -0
- package/dist/core/requires/check.js +83 -0
- package/dist/core/requires/check.js.map +1 -0
- package/dist/core/requires/index.d.ts +4 -0
- package/dist/core/requires/index.js +5 -0
- package/dist/core/requires/index.js.map +1 -0
- package/dist/core/requires/inspect.d.ts +44 -0
- package/dist/core/requires/inspect.js +114 -0
- package/dist/core/requires/inspect.js.map +1 -0
- package/dist/core/requires/paths.d.ts +29 -0
- package/dist/core/requires/paths.js +83 -0
- package/dist/core/requires/paths.js.map +1 -0
- package/dist/core/requires/setup.d.ts +37 -0
- package/dist/core/requires/setup.js +147 -0
- package/dist/core/requires/setup.js.map +1 -0
- package/dist/core/setup.d.ts +27 -0
- package/dist/core/setup.js +84 -0
- package/dist/core/setup.js.map +1 -0
- package/dist/core/sources/cache.d.ts +38 -0
- package/dist/core/sources/cache.js +200 -0
- package/dist/core/sources/cache.js.map +1 -0
- package/dist/core/sources/containment.d.ts +21 -0
- package/dist/core/sources/containment.js +50 -0
- package/dist/core/sources/containment.js.map +1 -0
- package/dist/core/sources/env.d.ts +12 -0
- package/dist/core/sources/env.js +28 -0
- package/dist/core/sources/env.js.map +1 -0
- package/dist/core/sources/extract.d.ts +25 -0
- package/dist/core/sources/extract.js +676 -0
- package/dist/core/sources/extract.js.map +1 -0
- package/dist/core/sources/git-process.d.ts +26 -0
- package/dist/core/sources/git-process.js +51 -0
- package/dist/core/sources/git-process.js.map +1 -0
- package/dist/core/sources/git.d.ts +41 -0
- package/dist/core/sources/git.js +511 -0
- package/dist/core/sources/git.js.map +1 -0
- package/dist/core/sources/https.d.ts +21 -0
- package/dist/core/sources/https.js +208 -0
- package/dist/core/sources/https.js.map +1 -0
- package/dist/core/sources/index.d.ts +13 -0
- package/dist/core/sources/index.js +14 -0
- package/dist/core/sources/index.js.map +1 -0
- package/dist/core/sources/npm-cli.d.ts +19 -0
- package/dist/core/sources/npm-cli.js +43 -0
- package/dist/core/sources/npm-cli.js.map +1 -0
- package/dist/core/sources/npm.d.ts +29 -0
- package/dist/core/sources/npm.js +386 -0
- package/dist/core/sources/npm.js.map +1 -0
- package/dist/core/sources/parse.d.ts +32 -0
- package/dist/core/sources/parse.js +389 -0
- package/dist/core/sources/parse.js.map +1 -0
- package/dist/core/sources/path.d.ts +10 -0
- package/dist/core/sources/path.js +316 -0
- package/dist/core/sources/path.js.map +1 -0
- package/dist/core/sources/redact.d.ts +2 -0
- package/dist/core/sources/redact.js +70 -0
- package/dist/core/sources/redact.js.map +1 -0
- package/dist/core/sources/resolve.d.ts +9 -0
- package/dist/core/sources/resolve.js +29 -0
- package/dist/core/sources/resolve.js.map +1 -0
- package/dist/core/sources/types.d.ts +86 -0
- package/dist/core/sources/types.js +2 -0
- package/dist/core/sources/types.js.map +1 -0
- package/dist/core/sources/validate.d.ts +9 -0
- package/dist/core/sources/validate.js +111 -0
- package/dist/core/sources/validate.js.map +1 -0
- package/dist/core/summary.d.ts +77 -0
- package/dist/core/summary.js +405 -0
- package/dist/core/summary.js.map +1 -0
- package/dist/core/update/clashes.d.ts +63 -0
- package/dist/core/update/clashes.js +192 -0
- package/dist/core/update/clashes.js.map +1 -0
- package/dist/core/update/detach.d.ts +21 -0
- package/dist/core/update/detach.js +38 -0
- package/dist/core/update/detach.js.map +1 -0
- package/dist/core/update/diff.d.ts +58 -0
- package/dist/core/update/diff.js +180 -0
- package/dist/core/update/diff.js.map +1 -0
- package/dist/core/update/fetch.d.ts +34 -0
- package/dist/core/update/fetch.js +73 -0
- package/dist/core/update/fetch.js.map +1 -0
- package/dist/core/update/index.d.ts +6 -0
- package/dist/core/update/index.js +7 -0
- package/dist/core/update/index.js.map +1 -0
- package/dist/core/update/restore.d.ts +20 -0
- package/dist/core/update/restore.js +195 -0
- package/dist/core/update/restore.js.map +1 -0
- package/dist/core/update/run.d.ts +113 -0
- package/dist/core/update/run.js +1132 -0
- package/dist/core/update/run.js.map +1 -0
- package/dist/core/update/select.d.ts +39 -0
- package/dist/core/update/select.js +157 -0
- package/dist/core/update/select.js.map +1 -0
- package/dist/core/update/spelling.d.ts +51 -0
- package/dist/core/update/spelling.js +185 -0
- package/dist/core/update/spelling.js.map +1 -0
- package/dist/core/update/trees.d.ts +24 -0
- package/dist/core/update/trees.js +72 -0
- package/dist/core/update/trees.js.map +1 -0
- package/dist/errors.d.ts +29 -0
- package/dist/errors.js +24 -0
- package/dist/errors.js.map +1 -0
- package/dist/help.d.ts +46 -0
- package/dist/help.js +103 -0
- package/dist/help.js.map +1 -0
- package/dist/input.d.ts +25 -0
- package/dist/input.js +173 -0
- package/dist/input.js.map +1 -0
- package/dist/output.d.ts +21 -0
- package/dist/output.js +37 -0
- package/dist/output.js.map +1 -0
- package/dist/util/frontmatter.d.ts +12 -0
- package/dist/util/frontmatter.js +58 -0
- package/dist/util/frontmatter.js.map +1 -0
- package/dist/util/fs.d.ts +32 -0
- package/dist/util/fs.js +126 -0
- package/dist/util/fs.js.map +1 -0
- package/dist/util/git-names.d.ts +8 -0
- package/dist/util/git-names.js +25 -0
- package/dist/util/git-names.js.map +1 -0
- package/dist/util/git.d.ts +12 -0
- package/dist/util/git.js +33 -0
- package/dist/util/git.js.map +1 -0
- package/dist/util/suggest.d.ts +6 -0
- package/dist/util/suggest.js +48 -0
- package/dist/util/suggest.js.map +1 -0
- package/dist/util/text.d.ts +8 -0
- package/dist/util/text.js +19 -0
- package/dist/util/text.js.map +1 -0
- package/dist/util/version.d.ts +7 -0
- package/dist/util/version.js +13 -0
- package/dist/util/version.js.map +1 -0
- package/dist/util/yaml.d.ts +30 -0
- package/dist/util/yaml.js +201 -0
- package/dist/util/yaml.js.map +1 -0
- package/package.json +51 -4
- package/resources/metafab-skill/SKILL.md +99 -0
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
import { lstat, mkdir, readFile, writeFile } from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { ExitCode, MetafabError } from "../../errors.js";
|
|
4
|
+
import { confirm, NeedsInput } from "../../input.js";
|
|
5
|
+
import { isDirectory, pathExists } from "../../util/fs.js";
|
|
6
|
+
import { cliVersion } from "../../util/version.js";
|
|
7
|
+
import { ADOPTION_QUESTION, adoptionRequired, applyAdoption, assertAdoptionAllowed, planAdoption, } from "../adopt.js";
|
|
8
|
+
import { applyBuild, planBuild } from "../build/index.js";
|
|
9
|
+
import { CONFIG_FILENAME } from "../config/parse.js";
|
|
10
|
+
import { destinations } from "../config/destinations.js";
|
|
11
|
+
import { createConfig, setGitHooks } from "../config/writers.js";
|
|
12
|
+
import { createFactoryYamlText } from "../edit/factory-yaml.js";
|
|
13
|
+
import { loadFactory } from "../factory/load.js";
|
|
14
|
+
import { hookChangeLines } from "../hooks/index.js";
|
|
15
|
+
import { assertFactoryDirectoryUsable, preflightBuild, readConfig, selectedTargets, unreadableFactory } from "../setup.js";
|
|
16
|
+
import { assertGitattributesWritable, ensureGitattributes } from "./gitattributes.js";
|
|
17
|
+
import { deriveFactoryName } from "./name.js";
|
|
18
|
+
import { selectTargets } from "./targets.js";
|
|
19
|
+
const AGENTS_FILE = ".factory/AGENTS.md";
|
|
20
|
+
const GIT_HOOKS_QUESTION = "Run metafab build automatically after checkout, merge, and rebase?";
|
|
21
|
+
const ORCA_SUGGESTION = 'Add "npx --yes @seasb/metafab build" to scripts.setup in orca.yaml so new Orca worktrees get the factory skills.';
|
|
22
|
+
/**
|
|
23
|
+
* The one wording for a `.factory/factory.yaml` that exists but cannot be read,
|
|
24
|
+
* shared by the `lstat` and the `readFile` failures.
|
|
25
|
+
*/
|
|
26
|
+
function unreadableFactoryFile() {
|
|
27
|
+
return unreadableFactory(".factory/factory.yaml", "Cannot read .factory/factory.yaml", "Check its permissions or restore the file");
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Refuses a `.factory/factory.yaml` that exists but cannot be read before
|
|
31
|
+
* anything is written. A file that is readable but invalid is left for the
|
|
32
|
+
* closing build to report.
|
|
33
|
+
*
|
|
34
|
+
* The entry is found with `lstat`, not `stat`: a dangling symlink is an entry
|
|
35
|
+
* too, and reading through it would create the target outside `.factory/`
|
|
36
|
+
* instead of failing.
|
|
37
|
+
*/
|
|
38
|
+
async function assertFactoryFileReadable(factoryDir) {
|
|
39
|
+
const file = path.join(factoryDir, "factory.yaml");
|
|
40
|
+
try {
|
|
41
|
+
await lstat(file);
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
if (error.code === "ENOENT")
|
|
45
|
+
return;
|
|
46
|
+
throw unreadableFactoryFile();
|
|
47
|
+
}
|
|
48
|
+
try {
|
|
49
|
+
await readFile(file, "utf8");
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
throw unreadableFactoryFile();
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Refuses a `.factory/AGENTS.md` that is a symbolic link `init` would write
|
|
57
|
+
* through. `ensureFactoryFiles` writes the file only when it does not resolve
|
|
58
|
+
* to a file, so a link to an existing file is left alone.
|
|
59
|
+
*/
|
|
60
|
+
async function assertAgentsFileWritable(factoryDir) {
|
|
61
|
+
const file = path.join(factoryDir, "AGENTS.md");
|
|
62
|
+
let info;
|
|
63
|
+
try {
|
|
64
|
+
info = await lstat(file);
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
if (error.code === "ENOENT")
|
|
68
|
+
return;
|
|
69
|
+
throw unreadableFactory(AGENTS_FILE, `Cannot read ${AGENTS_FILE}`, "Check its permissions or restore the file");
|
|
70
|
+
}
|
|
71
|
+
if (!info.isSymbolicLink())
|
|
72
|
+
return;
|
|
73
|
+
if (await pathExists(file))
|
|
74
|
+
return;
|
|
75
|
+
throw unreadableFactory(AGENTS_FILE, `${AGENTS_FILE} is a symbolic link, so metafab init will not write through it`, "Replace it with a regular file, then run metafab init again");
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Refuses every entry `init` would write through a symbolic link, before it
|
|
79
|
+
* writes anything. A dangling link would otherwise create its target, possibly
|
|
80
|
+
* outside the repository.
|
|
81
|
+
*/
|
|
82
|
+
async function assertWritableEntries(root, factoryDir) {
|
|
83
|
+
await assertGitattributesWritable(root, "init");
|
|
84
|
+
await assertAgentsFileWritable(factoryDir);
|
|
85
|
+
}
|
|
86
|
+
/** The Orca setup suggestion, when this run created the config and Orca is used. */
|
|
87
|
+
async function orcaSuggestions(root, created) {
|
|
88
|
+
if (!created.includes(`.factory/${CONFIG_FILENAME}`))
|
|
89
|
+
return [];
|
|
90
|
+
let text;
|
|
91
|
+
try {
|
|
92
|
+
text = await readFile(path.join(root, "orca.yaml"), "utf8");
|
|
93
|
+
}
|
|
94
|
+
catch {
|
|
95
|
+
return [];
|
|
96
|
+
}
|
|
97
|
+
return text.includes("metafab build") ? [] : [ORCA_SUGGESTION];
|
|
98
|
+
}
|
|
99
|
+
async function ensureFactoryFiles(root, factoryDir, selection, gitHooks) {
|
|
100
|
+
const created = [];
|
|
101
|
+
await mkdir(factoryDir, { recursive: true });
|
|
102
|
+
const factoryFile = path.join(factoryDir, "factory.yaml");
|
|
103
|
+
if (!(await pathExists(factoryFile))) {
|
|
104
|
+
const name = deriveFactoryName(path.basename(root));
|
|
105
|
+
await writeFile(factoryFile, createFactoryYamlText(name), "utf8");
|
|
106
|
+
created.push(".factory/factory.yaml");
|
|
107
|
+
}
|
|
108
|
+
const agentsFile = path.join(factoryDir, "AGENTS.md");
|
|
109
|
+
if (!(await pathExists(agentsFile))) {
|
|
110
|
+
await writeFile(agentsFile, "", "utf8");
|
|
111
|
+
created.push(".factory/AGENTS.md");
|
|
112
|
+
}
|
|
113
|
+
const config = { agents: selection };
|
|
114
|
+
if (gitHooks !== undefined)
|
|
115
|
+
config.gitHooks = gitHooks;
|
|
116
|
+
if (await createConfig(factoryDir, config)) {
|
|
117
|
+
created.push(`.factory/${CONFIG_FILENAME}`);
|
|
118
|
+
}
|
|
119
|
+
return created;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Runs the `init` sequence: resolve targets, preflight adoption and collect consent,
|
|
123
|
+
* create missing factory files, add `.gitattributes` lines, apply adoption, then build.
|
|
124
|
+
* Nothing is written before the adoption preflight and consent are complete.
|
|
125
|
+
*/
|
|
126
|
+
export async function runInit(options) {
|
|
127
|
+
const root = path.resolve(options.root);
|
|
128
|
+
const factoryDir = path.join(root, ".factory");
|
|
129
|
+
const io = options.io ?? {};
|
|
130
|
+
const tty = io.tty ?? process.stdin.isTTY === true;
|
|
131
|
+
await assertFactoryDirectoryUsable(factoryDir, "init");
|
|
132
|
+
const hasFactory = await isDirectory(factoryDir);
|
|
133
|
+
const existingConfig = await readConfig(factoryDir, "init");
|
|
134
|
+
const configExists = hasFactory && (await pathExists(path.join(factoryDir, CONFIG_FILENAME)));
|
|
135
|
+
const selection = await selectTargets({
|
|
136
|
+
...(options.agents === undefined ? {} : { agents: options.agents }),
|
|
137
|
+
...(hasFactory ? { existing: existingConfig.agentsRaw ?? "all" } : {}),
|
|
138
|
+
io,
|
|
139
|
+
...(options.prompt === undefined ? {} : { prompt: options.prompt }),
|
|
140
|
+
});
|
|
141
|
+
const targets = selectedTargets(selection);
|
|
142
|
+
const factory = hasFactory ? await loadFactory(root) : undefined;
|
|
143
|
+
const plan = await planAdoption(root, destinations(targets).map((destination) => destination.directory), factory);
|
|
144
|
+
assertAdoptionAllowed(plan);
|
|
145
|
+
let declined = false;
|
|
146
|
+
if (plan.moves.length > 0 && options.adopt !== true) {
|
|
147
|
+
if (!tty)
|
|
148
|
+
throw new NeedsInput([adoptionRequired(plan)]);
|
|
149
|
+
const accepted = await confirm({ name: "adopt", flag: "--adopt", description: ADOPTION_QUESTION }, {}, { ...io, tty });
|
|
150
|
+
declined = !accepted;
|
|
151
|
+
}
|
|
152
|
+
if (declined) {
|
|
153
|
+
return {
|
|
154
|
+
root,
|
|
155
|
+
created: [],
|
|
156
|
+
updated: [],
|
|
157
|
+
gitattributes: [],
|
|
158
|
+
moved: [],
|
|
159
|
+
changed: [],
|
|
160
|
+
hooks: [],
|
|
161
|
+
problems: [],
|
|
162
|
+
declined: true,
|
|
163
|
+
notes: [],
|
|
164
|
+
suggestions: [],
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
const notes = [];
|
|
168
|
+
let hooksValue;
|
|
169
|
+
const hooksKeyPresent = configExists && existingConfig.gitHooksPresent;
|
|
170
|
+
if (hooksKeyPresent) {
|
|
171
|
+
// A value that is present but not a boolean is left for the closing build
|
|
172
|
+
// to report as a configuration error; `init` must not overwrite it.
|
|
173
|
+
if (existingConfig.gitHooksRaw !== undefined) {
|
|
174
|
+
notes.push(`git-hooks is already ${String(existingConfig.gitHooks)} in .factory/${CONFIG_FILENAME}`);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
else if (options.gitHooks !== undefined) {
|
|
178
|
+
hooksValue = options.gitHooks;
|
|
179
|
+
}
|
|
180
|
+
else if (tty) {
|
|
181
|
+
hooksValue = await confirm({ name: "git-hooks", flag: "--git-hooks", description: GIT_HOOKS_QUESTION }, { default: true }, { ...io, tty });
|
|
182
|
+
}
|
|
183
|
+
await preflightBuild(root, existingConfig, selection, configExists, plan.moves);
|
|
184
|
+
await assertFactoryFileReadable(factoryDir);
|
|
185
|
+
await assertWritableEntries(root, factoryDir);
|
|
186
|
+
const created = await ensureFactoryFiles(root, factoryDir, selection, hooksValue);
|
|
187
|
+
const updated = [];
|
|
188
|
+
if (configExists && hooksValue !== undefined) {
|
|
189
|
+
await setGitHooks(factoryDir, hooksValue);
|
|
190
|
+
updated.push(`.factory/${CONFIG_FILENAME}`);
|
|
191
|
+
}
|
|
192
|
+
const gitattributesExisted = await pathExists(path.join(root, ".gitattributes"));
|
|
193
|
+
const gitattributes = await ensureGitattributes(root);
|
|
194
|
+
if (gitattributes.changed) {
|
|
195
|
+
if (gitattributesExisted)
|
|
196
|
+
updated.push(".gitattributes");
|
|
197
|
+
else
|
|
198
|
+
created.push(".gitattributes");
|
|
199
|
+
}
|
|
200
|
+
if (plan.moves.length > 0)
|
|
201
|
+
await applyAdoption(plan);
|
|
202
|
+
const suggestions = await orcaSuggestions(root, created);
|
|
203
|
+
const builtFactory = await loadFactory(root);
|
|
204
|
+
const config = await readConfig(factoryDir, "init");
|
|
205
|
+
const loadedProblems = [...builtFactory.problems, ...config.problems];
|
|
206
|
+
const loadedWarnings = loadedProblems.filter((problem) => problem.level === "warning");
|
|
207
|
+
const buildPlan = await planBuild(builtFactory, config, cliVersion());
|
|
208
|
+
const allWarnings = [...loadedWarnings, ...buildPlan.warnings];
|
|
209
|
+
if (buildPlan.conflicts.length > 0) {
|
|
210
|
+
throw new MetafabError("Build stopped because the repository contains output that Metafab does not own.", {
|
|
211
|
+
exitCode: ExitCode.NotOwned,
|
|
212
|
+
code: "build-conflict",
|
|
213
|
+
problems: [...buildPlan.conflicts, ...buildPlan.errors, ...allWarnings],
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
if (buildPlan.errors.length > 0) {
|
|
217
|
+
throw new MetafabError("Build failed after init.", {
|
|
218
|
+
exitCode: ExitCode.Failed,
|
|
219
|
+
code: "build-failed",
|
|
220
|
+
problems: [...buildPlan.errors, ...allWarnings],
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
const report = await applyBuild(buildPlan);
|
|
224
|
+
return {
|
|
225
|
+
root,
|
|
226
|
+
created,
|
|
227
|
+
updated,
|
|
228
|
+
gitattributes: [...gitattributes.added],
|
|
229
|
+
moved: plan.moves.map((move) => ({ ...move, from: [...move.from] })),
|
|
230
|
+
changed: report.changed,
|
|
231
|
+
hooks: report.hooks,
|
|
232
|
+
problems: [...allWarnings, ...report.hookWarnings],
|
|
233
|
+
declined: false,
|
|
234
|
+
notes,
|
|
235
|
+
suggestions,
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
/** Human-readable report for `init`, or `Already initialised` when nothing needed changing. */
|
|
239
|
+
export function describeInit(report) {
|
|
240
|
+
if (report.declined)
|
|
241
|
+
return "Adoption declined. Nothing changed.";
|
|
242
|
+
const seemsComplete = report.created.length === 0 &&
|
|
243
|
+
report.updated.length === 0 &&
|
|
244
|
+
report.gitattributes.length === 0 &&
|
|
245
|
+
report.moved.length === 0 &&
|
|
246
|
+
report.changed.length === 0 &&
|
|
247
|
+
report.hooks.length === 0;
|
|
248
|
+
const marks = { created: "+", updated: "~", removed: "-" };
|
|
249
|
+
const lines = [];
|
|
250
|
+
if (seemsComplete) {
|
|
251
|
+
lines.push("Already initialised");
|
|
252
|
+
}
|
|
253
|
+
else {
|
|
254
|
+
const gitattributesUpdated = report.updated.includes(".gitattributes");
|
|
255
|
+
lines.push(...report.created.map((file) => `Created ${file}`), ...report.updated.map((file) => `Updated ${file}`), ...(gitattributesUpdated
|
|
256
|
+
? report.gitattributes.map((line) => `Added .gitattributes line: ${line}`)
|
|
257
|
+
: []), ...report.moved.map((move) => `Moved ${move.from.join(", ")} -> ${move.to}`), ...report.changed.map((change) => `${marks[change.action]} ${change.path}`), ...hookChangeLines(report.hooks));
|
|
258
|
+
}
|
|
259
|
+
return [...lines, ...report.notes, ...report.suggestions].join("\n");
|
|
260
|
+
}
|
|
261
|
+
//# sourceMappingURL=run.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run.js","sourceRoot":"","sources":["../../../src/core/init/run.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACrE,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAEzD,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAErD,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAC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AG,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,MAAM,CAAC,IAAI,EAAE,CAAC,EAC3E,GAAG,eAAe,CAAC,MAAM,CAAC,KAAK,CAAC,CACjC,CAAC;IACJ,CAAC;IAED,OAAO,CAAC,GAAG,KAAK,EAAE,GAAG,MAAM,CAAC,KAAK,EAAE,GAAG,MAAM,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACvE,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { InputIO } from "../../input.js";
|
|
2
|
+
import type { Target } from "../config/types.js";
|
|
3
|
+
export type TargetSelection = "all" | Target[];
|
|
4
|
+
export type TargetPrompt = (targets: readonly Target[], io: InputIO) => Promise<TargetSelection>;
|
|
5
|
+
export interface SelectTargetsOptions {
|
|
6
|
+
/** Raw `--agents` value. */
|
|
7
|
+
agents?: string;
|
|
8
|
+
/** The `agents` value from an existing metafab.yaml, if any. */
|
|
9
|
+
existing?: TargetSelection;
|
|
10
|
+
/** Injected input and output; production uses the process streams. */
|
|
11
|
+
io?: InputIO;
|
|
12
|
+
/** Injected terminal prompt, so tests do not need a terminal. */
|
|
13
|
+
prompt?: TargetPrompt;
|
|
14
|
+
}
|
|
15
|
+
export declare function parseAgentsFlag(value: string): TargetSelection;
|
|
16
|
+
export declare const promptForTargets: TargetPrompt;
|
|
17
|
+
export declare function selectTargets(options?: SelectTargetsOptions): Promise<TargetSelection>;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { MetafabError } from "../../errors.js";
|
|
2
|
+
import { ask } from "../../input.js";
|
|
3
|
+
import { normalizeProblemPath } from "../../util/fs.js";
|
|
4
|
+
import { TARGETS } from "../config/types.js";
|
|
5
|
+
function agentsError(message) {
|
|
6
|
+
const fix = `Use a comma-separated list of ${TARGETS.join(", ")}, or all.`;
|
|
7
|
+
return new MetafabError(message, {
|
|
8
|
+
code: "invalid-agents",
|
|
9
|
+
problems: [
|
|
10
|
+
{
|
|
11
|
+
level: "error",
|
|
12
|
+
file: normalizeProblemPath("metafab"),
|
|
13
|
+
message,
|
|
14
|
+
fix,
|
|
15
|
+
},
|
|
16
|
+
],
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
function unique(targets) {
|
|
20
|
+
return [...new Set(targets)];
|
|
21
|
+
}
|
|
22
|
+
export function parseAgentsFlag(value) {
|
|
23
|
+
const list = value.trim();
|
|
24
|
+
if (list === "")
|
|
25
|
+
throw agentsError("--agents requires at least one target.");
|
|
26
|
+
if (list === "all")
|
|
27
|
+
return "all";
|
|
28
|
+
const names = list.split(",").map((name) => name.trim());
|
|
29
|
+
const targets = [];
|
|
30
|
+
for (const name of names) {
|
|
31
|
+
if (name === "")
|
|
32
|
+
throw agentsError(`Invalid value for --agents: "${value}".`);
|
|
33
|
+
if (!TARGETS.includes(name)) {
|
|
34
|
+
throw agentsError(`Unknown agent target "${name}" in --agents.`);
|
|
35
|
+
}
|
|
36
|
+
targets.push(name);
|
|
37
|
+
}
|
|
38
|
+
return unique(targets);
|
|
39
|
+
}
|
|
40
|
+
function parseAnswer(answer, targets) {
|
|
41
|
+
const value = answer.trim();
|
|
42
|
+
if (value === "" || value.toLowerCase() === "all")
|
|
43
|
+
return "all";
|
|
44
|
+
const selected = [];
|
|
45
|
+
for (const part of value.split(",")) {
|
|
46
|
+
const item = part.trim();
|
|
47
|
+
if (item === "")
|
|
48
|
+
return undefined;
|
|
49
|
+
const position = Number(item);
|
|
50
|
+
const target = Number.isInteger(position) && position >= 1 && position <= targets.length
|
|
51
|
+
? targets[position - 1]
|
|
52
|
+
: targets.find((candidate) => candidate === item.toLowerCase());
|
|
53
|
+
if (target === undefined)
|
|
54
|
+
return undefined;
|
|
55
|
+
selected.push(target);
|
|
56
|
+
}
|
|
57
|
+
return selected.length === 0 ? undefined : unique(selected);
|
|
58
|
+
}
|
|
59
|
+
export const promptForTargets = async (targets, io) => {
|
|
60
|
+
const list = targets.map((target, index) => ` ${index + 1}. ${target}`).join("\n");
|
|
61
|
+
io.stderr?.(`Agent targets:\n${list}\n`);
|
|
62
|
+
for (;;) {
|
|
63
|
+
const answer = await ask({
|
|
64
|
+
name: "agents",
|
|
65
|
+
flag: "--agents",
|
|
66
|
+
description: "Agent targets (numbers or names, comma-separated, or all)",
|
|
67
|
+
}, io);
|
|
68
|
+
const selected = parseAnswer(answer, targets);
|
|
69
|
+
if (selected !== undefined)
|
|
70
|
+
return selected;
|
|
71
|
+
io.stderr?.(`Choose from: ${targets.join(", ")}, or all.\n`);
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
export async function selectTargets(options = {}) {
|
|
75
|
+
if (options.agents !== undefined)
|
|
76
|
+
return parseAgentsFlag(options.agents);
|
|
77
|
+
if (options.existing !== undefined) {
|
|
78
|
+
return options.existing === "all" ? "all" : unique(options.existing);
|
|
79
|
+
}
|
|
80
|
+
const io = options.io ?? {};
|
|
81
|
+
const tty = io.tty ?? process.stdin.isTTY === true;
|
|
82
|
+
if (!tty)
|
|
83
|
+
return "all";
|
|
84
|
+
const prompt = options.prompt ?? promptForTargets;
|
|
85
|
+
return prompt([...TARGETS], io);
|
|
86
|
+
}
|
|
87
|
+
//# sourceMappingURL=targets.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"targets.js","sourceRoot":"","sources":["../../../src/core/init/targets.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AAErC,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AACxD,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAkB7C,SAAS,WAAW,CAAC,OAAe;IAClC,MAAM,GAAG,GAAG,iCAAiC,OAAO,CAAC,IAAI,CAAC,I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+
export interface MergeInput {
|
|
3
|
+
content: Buffer;
|
|
4
|
+
/** Permission bits, such as 0o644 or 0o755. */
|
|
5
|
+
mode: number;
|
|
6
|
+
/** The target of a symbolic link, when this side is a link rather than a file. */
|
|
7
|
+
link?: string;
|
|
8
|
+
}
|
|
9
|
+
/** Versions printed in conflict markers. */
|
|
10
|
+
export interface MergeLabels {
|
|
11
|
+
/** The recorded upstream version, printed after `base`. */
|
|
12
|
+
base: string;
|
|
13
|
+
/** The selected upstream version, printed after `upstream`. */
|
|
14
|
+
upstream: string;
|
|
15
|
+
}
|
|
16
|
+
export interface MergeOptions {
|
|
17
|
+
/**
|
|
18
|
+
* True when the recorded base could not be fetched. Every path both sides
|
|
19
|
+
* have with different content then counts as a conflict, and a text conflict
|
|
20
|
+
* has no base section. A path only upstream has goes to a side file, a path
|
|
21
|
+
* only you have is kept, and so is a path whose content matches but whose
|
|
22
|
+
* permission bits differ.
|
|
23
|
+
*/
|
|
24
|
+
baseUnavailable?: boolean;
|
|
25
|
+
}
|
|
26
|
+
export type MergeNote = "upstream-removed" | "upstream-changed-removed" | "base-unavailable" | "base-unavailable-mode";
|
|
27
|
+
/**
|
|
28
|
+
* Why a conflict keeps yours and writes theirs to `<file>.upstream`: a binary
|
|
29
|
+
* file that both sides changed, a new local file that differs from the new
|
|
30
|
+
* upstream file, or a path only upstream has while the base is unavailable.
|
|
31
|
+
*/
|
|
32
|
+
export type SideFileReason = "binary" | "new-local" | "base-unavailable" | "link";
|
|
33
|
+
/**
|
|
34
|
+
* One outcome of the merge table.
|
|
35
|
+
*
|
|
36
|
+
* `keep` leaves the local file untouched; its note reports an upstream removal
|
|
37
|
+
* of a changed file, that the base is unavailable, or that the permission bits
|
|
38
|
+
* differ from upstream while the base is unavailable. `remove` deletes the
|
|
39
|
+
* local path; its note reports an upstream change to a file that was already
|
|
40
|
+
* removed locally. `take-theirs`, `add`, `write` and `conflict` carry the
|
|
41
|
+
* content and the mode the merge decided to write: only the executable bit
|
|
42
|
+
* counts as a permission change, so a side that differs in other bits leaves
|
|
43
|
+
* the local mode alone. `side-file` keeps yours and writes
|
|
44
|
+
* `upstream` to `<file>.upstream`, and its reason says whether that is a binary
|
|
45
|
+
* conflict, a new local file that differs from the new upstream file, or a path
|
|
46
|
+
* only upstream has while the base is unavailable.
|
|
47
|
+
*/
|
|
48
|
+
export type MergeResult = {
|
|
49
|
+
action: "keep";
|
|
50
|
+
note?: MergeNote;
|
|
51
|
+
} | {
|
|
52
|
+
action: "remove";
|
|
53
|
+
note?: MergeNote;
|
|
54
|
+
} | {
|
|
55
|
+
action: "take-theirs";
|
|
56
|
+
content: Buffer;
|
|
57
|
+
mode: number;
|
|
58
|
+
} | {
|
|
59
|
+
action: "add";
|
|
60
|
+
content: Buffer;
|
|
61
|
+
mode: number;
|
|
62
|
+
} | {
|
|
63
|
+
action: "write";
|
|
64
|
+
content: Buffer;
|
|
65
|
+
mode: number;
|
|
66
|
+
} | {
|
|
67
|
+
action: "conflict";
|
|
68
|
+
content: Buffer;
|
|
69
|
+
mode: number;
|
|
70
|
+
} | {
|
|
71
|
+
action: "side-file";
|
|
72
|
+
upstream: Buffer;
|
|
73
|
+
upstreamMode: number;
|
|
74
|
+
reason: SideFileReason;
|
|
75
|
+
/** The target of your link, when yours is a link. */
|
|
76
|
+
yoursLink?: string;
|
|
77
|
+
/** The target of upstream's link, when upstream is a link. */
|
|
78
|
+
upstreamLink?: string;
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
* Applies the merge table to one path.
|
|
82
|
+
*
|
|
83
|
+
* `base`, `yours` and `theirs` are absent when the path does not exist on that
|
|
84
|
+
* side. Text is merged line by line; a binary conflict keeps yours and returns
|
|
85
|
+
* theirs for a `<file>.upstream` side file. A change to the executable bit
|
|
86
|
+
* alone counts as a change.
|
|
87
|
+
*/
|
|
88
|
+
export declare function mergePath(base: MergeInput | undefined, yours: MergeInput | undefined, theirs: MergeInput | undefined, labels: MergeLabels, options?: MergeOptions): MergeResult;
|