arktype 3.0.0-beta.1 → 3.0.0-rc.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 +48 -144
- package/out/_internal/regex/charset.d.ts +24 -0
- package/out/_internal/regex/escape.d.ts +29 -0
- package/out/_internal/regex/execArray.d.ts +24 -0
- package/out/_internal/regex/group.d.ts +34 -0
- package/out/_internal/regex/index.d.ts +2 -0
- package/out/_internal/regex/internal.d.ts +9 -0
- package/out/_internal/regex/parse.d.ts +10 -0
- package/out/_internal/regex/quantify.d.ts +59 -0
- package/out/_internal/regex/regex.d.ts +38 -0
- package/out/_internal/regex/state.d.ts +383 -0
- package/out/_internal/schema/codecs.d.ts +2 -0
- package/out/_internal/schema/config.d.ts +103 -0
- package/out/_internal/schema/constraint.d.ts +78 -0
- package/out/_internal/schema/errors.d.ts +1 -0
- package/out/_internal/schema/generic.d.ts +85 -0
- package/out/_internal/schema/i18n.d.ts +3 -0
- package/out/_internal/schema/index.d.ts +54 -0
- package/out/_internal/schema/internal.d.ts +15 -0
- package/out/_internal/schema/intrinsic.d.ts +28 -0
- package/out/_internal/schema/kinds.d.ts +76 -0
- package/out/_internal/schema/module.d.ts +23 -0
- package/out/_internal/schema/mutatesInput.d.ts +2 -0
- package/out/_internal/schema/node.d.ts +349 -0
- package/out/_internal/schema/parse.d.ts +77 -0
- package/out/_internal/schema/parseSchema.d.ts +116 -0
- package/out/_internal/schema/predicate.d.ts +46 -0
- package/out/_internal/schema/refinements/after.d.ts +32 -0
- package/out/_internal/schema/refinements/before.d.ts +32 -0
- package/out/_internal/schema/refinements/divisor.d.ts +41 -0
- package/out/_internal/schema/refinements/exactLength.d.ts +43 -0
- package/out/_internal/schema/refinements/kinds.d.ts +40 -0
- package/out/_internal/schema/refinements/max.d.ts +33 -0
- package/out/_internal/schema/refinements/maxLength.d.ts +32 -0
- package/out/_internal/schema/refinements/min.d.ts +33 -0
- package/out/_internal/schema/refinements/minLength.d.ts +32 -0
- package/out/_internal/schema/refinements/notEqual.d.ts +38 -0
- package/out/_internal/schema/refinements/notEqualLength.d.ts +38 -0
- package/out/_internal/schema/refinements/pattern.d.ts +43 -0
- package/out/_internal/schema/refinements/range.d.ts +101 -0
- package/out/_internal/schema/roots/alias.d.ts +49 -0
- package/out/_internal/schema/roots/basis.d.ts +12 -0
- package/out/_internal/schema/roots/domain.d.ts +45 -0
- package/out/_internal/schema/roots/intersection.d.ts +72 -0
- package/out/_internal/schema/roots/morph.d.ts +59 -0
- package/out/_internal/schema/roots/proto.d.ts +42 -0
- package/out/_internal/schema/roots/root.d.ts +163 -0
- package/out/_internal/schema/roots/union.d.ts +146 -0
- package/out/_internal/schema/roots/unit.d.ts +36 -0
- package/out/_internal/schema/runtime.d.ts +29 -0
- package/out/_internal/schema/runtimeLean.d.ts +2 -0
- package/out/_internal/schema/runtimeNone.d.ts +2 -0
- package/out/_internal/schema/runtimeNoneLean.d.ts +2 -0
- package/out/_internal/schema/scope.d.ts +203 -0
- package/out/_internal/schema/shared/codecs.d.ts +5 -0
- package/out/_internal/schema/shared/compile.d.ts +144 -0
- package/out/_internal/schema/shared/configured.d.ts +14 -0
- package/out/_internal/schema/shared/declare.d.ts +100 -0
- package/out/_internal/schema/shared/disjoint.d.ts +45 -0
- package/out/_internal/schema/shared/enWriters.d.ts +30 -0
- package/out/_internal/schema/shared/errorModes.d.ts +25 -0
- package/out/_internal/schema/shared/errorWriters.d.ts +34 -0
- package/out/_internal/schema/shared/errors.d.ts +264 -0
- package/out/_internal/schema/shared/implement.d.ts +154 -0
- package/out/_internal/schema/shared/inPlace.d.ts +8 -0
- package/out/_internal/schema/shared/issueFeatures.d.ts +38 -0
- package/out/_internal/schema/shared/issues.d.ts +261 -0
- package/out/_internal/schema/shared/issuesLean.d.ts +80 -0
- package/out/_internal/schema/shared/issuesNone.d.ts +22 -0
- package/out/_internal/schema/shared/issuesNoneLean.d.ts +20 -0
- package/out/_internal/schema/shared/issuesUndetailed.d.ts +25 -0
- package/out/_internal/schema/shared/jsonSchema.d.ts +153 -0
- package/out/_internal/schema/shared/listed.d.ts +15 -0
- package/out/_internal/schema/shared/locale.d.ts +149 -0
- package/out/_internal/schema/shared/registry.d.ts +16 -0
- package/out/_internal/schema/shared/render.d.ts +3 -0
- package/out/_internal/schema/shared/rootApply.d.ts +19 -0
- package/out/_internal/schema/shared/sets.d.ts +26 -0
- package/out/_internal/schema/shared/standardFailure.d.ts +22 -0
- package/out/_internal/schema/shared/standardSchema.d.ts +124 -0
- package/out/_internal/schema/shared/toJsonSchema.d.ts +229 -0
- package/out/_internal/schema/shared/transform.d.ts +35 -0
- package/out/_internal/schema/shared/traversal.d.ts +288 -0
- package/out/_internal/schema/shared/utils.d.ts +59 -0
- package/out/_internal/schema/structure/index.d.ts +43 -0
- package/out/_internal/schema/structure/optional.d.ts +61 -0
- package/out/_internal/schema/structure/prop.d.ts +45 -0
- package/out/_internal/schema/structure/required.d.ts +49 -0
- package/out/_internal/schema/structure/sequence.d.ts +127 -0
- package/out/_internal/schema/structure/shared.d.ts +3 -0
- package/out/_internal/schema/structure/structure.d.ts +178 -0
- package/out/_internal/schema/units.d.ts +123 -0
- package/out/_internal/sets/algebra.d.ts +26 -0
- package/out/_internal/sets/constraint.d.ts +19 -0
- package/out/_internal/sets/engine.d.ts +2 -0
- package/out/_internal/sets/formats.d.ts +23 -0
- package/out/_internal/sets/fromJsonSchema.d.ts +15 -0
- package/out/_internal/sets/implement.d.ts +16 -0
- package/out/_internal/sets/index.d.ts +2 -0
- package/out/_internal/sets/internal.d.ts +20 -0
- package/out/_internal/sets/intersections.d.ts +5 -0
- package/out/_internal/sets/kinds.d.ts +3 -0
- package/out/_internal/sets/refinements.d.ts +14 -0
- package/out/_internal/sets/roots/alias.d.ts +3 -0
- package/out/_internal/sets/roots/domain.d.ts +3 -0
- package/out/_internal/sets/roots/intersection.d.ts +4 -0
- package/out/_internal/sets/roots/morph.d.ts +4 -0
- package/out/_internal/sets/roots/proto.d.ts +3 -0
- package/out/_internal/sets/roots/union.d.ts +16 -0
- package/out/_internal/sets/roots/unit.d.ts +3 -0
- package/out/_internal/sets/structure/index.d.ts +3 -0
- package/out/_internal/sets/structure/prop.d.ts +8 -0
- package/out/_internal/sets/structure/sequence.d.ts +3 -0
- package/out/_internal/sets/structure/structure.d.ts +3 -0
- package/out/_internal/sets/toJsonSchema.d.ts +25 -0
- package/out/_internal/util/arrays.d.ts +130 -0
- package/out/_internal/util/clone.d.ts +4 -0
- package/out/_internal/util/describe.d.ts +25 -0
- package/out/_internal/util/domain.d.ts +49 -0
- package/out/_internal/util/errors.d.ts +29 -0
- package/out/_internal/util/facts.d.ts +22 -0
- package/out/_internal/util/flatMorph.d.ts +41 -0
- package/out/_internal/util/formats.d.ts +8 -0
- package/out/_internal/util/functions.d.ts +33 -0
- package/out/_internal/util/generics.d.ts +65 -0
- package/out/_internal/util/get.d.ts +9 -0
- package/out/_internal/util/hkt.d.ts +27 -0
- package/out/_internal/util/i18n.d.ts +12 -0
- package/out/_internal/util/index.d.ts +28 -0
- package/out/_internal/util/internal.d.ts +2 -0
- package/out/_internal/util/intersections.d.ts +50 -0
- package/out/_internal/util/isomorphic.d.ts +8 -0
- package/out/_internal/util/keys.d.ts +18 -0
- package/out/_internal/util/lazily.d.ts +7 -0
- package/out/_internal/util/numbers.d.ts +82 -0
- package/out/_internal/util/objectKinds.d.ts +157 -0
- package/out/_internal/util/path.d.ts +16 -0
- package/out/_internal/util/primitive.d.ts +16 -0
- package/out/_internal/util/records.d.ts +173 -0
- package/out/_internal/util/registry.d.ts +13 -0
- package/out/_internal/util/scanner.d.ts +110 -0
- package/out/_internal/util/serialize.d.ts +40 -0
- package/out/_internal/util/strings.d.ts +35 -0
- package/out/_internal/util/traits.d.ts +89 -0
- package/out/_internal/util/unionToTuple.d.ts +14 -0
- package/out/_internal/util/weak.d.ts +8 -0
- package/out/attributes.d.ts +15 -11
- package/out/checkers.d.ts +1 -1
- package/out/chunk-22RQSVV3.js +0 -0
- package/out/chunk-3HZC67MT.js +965 -0
- package/out/chunk-3KBOPH3J.js +1564 -0
- package/out/chunk-3SH2BQ4T.js +15 -0
- package/out/chunk-46PLKNON.js +126 -0
- package/out/{chunk-G45P2CLE.js → chunk-4FTHWK63.js} +6 -1
- package/out/{chunk-UK5UGFOX.js → chunk-4HREHNIV.js} +23 -11
- package/out/chunk-4NZCLVBD.js +14 -0
- package/out/chunk-6FMBO47M.js +7 -0
- package/out/chunk-7TALAWYX.js +10 -0
- package/out/{chunk-DLWCO4RV.js → chunk-BCYKO54Z.js} +11 -2
- package/out/chunk-BDJVONP7.js +168 -0
- package/out/{chunk-E3DZXEZK.js → chunk-C2JOL5M2.js} +4 -2
- package/out/{chunk-2U2AWCI3.js → chunk-C2V6QPE3.js} +126 -97
- package/out/chunk-C3B4IFQL.js +6408 -0
- package/out/chunk-CWSF57VM.js +10 -0
- package/out/chunk-F5BACUJS.js +7 -0
- package/out/{chunk-EVCML554.js → chunk-FWRSDUJ2.js} +14 -5
- package/out/chunk-GID3FSQA.js +161 -0
- package/out/chunk-I2KLQ2HA.js +22 -0
- package/out/chunk-K7SLP5D2.js +84 -0
- package/out/chunk-KQPSKGUI.js +9 -0
- package/out/chunk-KXOC3JEX.js +8234 -0
- package/out/chunk-KXOSUYRA.js +405 -0
- package/out/chunk-LHNEY6QW.js +0 -0
- package/out/chunk-MTWKGAGO.js +323 -0
- package/out/chunk-NU73GNCX.js +170 -0
- package/out/{chunk-RAZ3TXOE.js → chunk-P5W67FQH.js} +34 -19
- package/out/chunk-PDLTEX6Z.js +1118 -0
- package/out/{chunk-VV6YDN2D.js → chunk-QUS4IAXJ.js} +304 -263
- package/out/chunk-R7WXIH5P.js +94 -0
- package/out/chunk-TACLEIDM.js +95 -0
- package/out/chunk-UJJGG4VQ.js +71 -0
- package/out/chunk-US6BWOGJ.js +109 -0
- package/out/chunk-VMMMOO4R.js +945 -0
- package/out/chunk-VYMXHSFR.js +439 -0
- package/out/chunk-W2XOI5DY.js +141 -0
- package/out/chunk-WC5L5YRP.js +25 -0
- package/out/{chunk-NRIGTMPM.js → chunk-WKOSL2G6.js} +4 -1
- package/out/chunk-XLG66ZDF.js +0 -0
- package/out/{chunk-5U2ZMDNI.js → chunk-XNUAQSJ4.js} +52 -30
- package/out/chunk-ZRYEHGSG.js +79 -0
- package/out/cli.d.ts +28 -0
- package/out/cli.js +636 -0
- package/out/codecs.d.ts +6 -5
- package/out/codecs.js +23 -7
- package/out/config.d.ts +5 -17
- package/out/config.js +11 -2
- package/out/declare.d.ts +40 -12
- package/out/deferred.d.ts +2 -2
- package/out/errors.d.ts +1 -1
- package/out/errors.js +10 -2
- package/out/fn.d.ts +20 -13
- package/out/fromJsonSchema.d.ts +18 -0
- package/out/generic.d.ts +9 -6
- package/out/i18n.d.ts +2 -2
- package/out/i18n.js +9 -2
- package/out/index.d.ts +16 -7
- package/out/index.js +25 -8
- package/out/internal.d.ts +4 -0
- package/out/internal.js +41 -17
- package/out/island.js +22 -6
- package/out/islandDependency.js +42 -18
- package/out/jsonSchema/infer.d.ts +805 -0
- package/out/jsonSchema/validate.d.ts +416 -0
- package/out/keywords/Array.d.ts +2 -2
- package/out/keywords/builtins.d.ts +3 -3
- package/out/keywords/constructors.d.ts +1 -1
- package/out/keywords/functions.d.ts +5 -192
- package/out/keywords/keywords.d.ts +3 -3
- package/out/keywords/number.d.ts +2 -2
- package/out/keywords/phrases.d.ts +4 -191
- package/out/keywords/string.d.ts +3 -3
- package/out/keywords/ts.d.ts +18 -18
- package/out/keywords/ts.js +19 -4
- package/out/locale.d.ts +6 -2
- package/out/locales/de.js +9 -2
- package/out/locales/en.js +21 -5
- package/out/match.d.ts +13 -10
- package/out/module.d.ts +2 -2
- package/out/mutatesInput.js +18 -3
- package/out/nary.d.ts +220 -194
- package/out/parser/ast/bounds.d.ts +2 -2
- package/out/parser/ast/default.d.ts +2 -2
- package/out/parser/ast/divisor.d.ts +2 -2
- package/out/parser/ast/generic.d.ts +2 -2
- package/out/parser/ast/infer.d.ts +1 -1
- package/out/parser/ast/keyof.d.ts +2 -2
- package/out/parser/ast/utils.d.ts +1 -1
- package/out/parser/ast/validate.d.ts +2 -2
- package/out/parser/definition.d.ts +4 -4
- package/out/parser/objectLiteral.d.ts +2 -2
- package/out/parser/property.d.ts +2 -2
- package/out/parser/reduce/dynamic.d.ts +2 -2
- package/out/parser/reduce/shared.d.ts +1 -1
- package/out/parser/reduce/static.d.ts +1 -1
- package/out/parser/shift/operand/enclosed.d.ts +2 -2
- package/out/parser/shift/operand/genericArgs.d.ts +2 -2
- package/out/parser/shift/operand/operand.d.ts +1 -1
- package/out/parser/shift/operand/unenclosed.d.ts +2 -2
- package/out/parser/shift/operand/unresolvable.d.ts +2 -2
- package/out/parser/shift/operator/bounds.d.ts +2 -2
- package/out/parser/shift/operator/brand.d.ts +2 -2
- package/out/parser/shift/operator/default.d.ts +4 -4
- package/out/parser/shift/operator/divisor.d.ts +1 -1
- package/out/parser/shift/operator/operator.d.ts +1 -1
- package/out/parser/shift/tokens.d.ts +1 -1
- package/out/parser/string.d.ts +2 -2
- package/out/parser/tupleExpressions.d.ts +6 -8
- package/out/parser/tupleLiteral.d.ts +2 -2
- package/out/precompiled.d.ts +1 -1
- package/out/precompiled.js +16 -2
- package/out/regex.d.ts +1 -0
- package/out/regex.js +2 -0
- package/out/runtime.d.ts +10 -8
- package/out/runtime.js +6 -4
- package/out/runtimeDevelopment.js +70 -52
- package/out/schema.d.ts +1 -0
- package/out/schema.js +15 -0
- package/out/schemaInternal.d.ts +1 -0
- package/out/schemaInternal.js +1401 -0
- package/out/schemaIssueFeatures.d.ts +1 -0
- package/out/schemaRuntime.d.ts +1 -0
- package/out/schemaRuntime.js +7 -0
- package/out/schemaRuntimeLean.d.ts +1 -0
- package/out/schemaRuntimeLean.js +1870 -0
- package/out/schemaRuntimeNone.d.ts +1 -0
- package/out/schemaRuntimeNone.js +1774 -0
- package/out/schemaRuntimeNoneLean.d.ts +1 -0
- package/out/schemaRuntimeNoneLean.js +1767 -0
- package/out/scope.d.ts +3 -4
- package/out/shared/issueFeatures.d.ts +38 -0
- package/out/shared/issueFeatures.js +40 -0
- package/out/standalone/artifact.d.ts +6 -6
- package/out/standalone/baking.d.ts +2 -2
- package/out/standalone/combinators.d.ts +1 -1
- package/out/standalone/compilers.d.ts +1 -1
- package/out/standalone/fallbacks.d.ts +1 -1
- package/out/standalone/keys.d.ts +1 -1
- package/out/standalone/sites.d.ts +3 -3
- package/out/standalone/units.d.ts +1 -1
- package/out/standalone/values.d.ts +1 -1
- package/out/type.d.ts +6 -6
- package/out/util.d.ts +1 -0
- package/out/util.js +137 -0
- package/out/variants/array.d.ts +6 -6
- package/out/variants/base.d.ts +61 -10
- package/out/variants/date.d.ts +5 -5
- package/out/variants/instantiate.d.ts +1 -1
- package/out/variants/number.d.ts +6 -6
- package/out/variants/object.d.ts +25 -12
- package/out/variants/string.d.ts +8 -8
- package/package.json +183 -8
- package/skills/arktype/SKILL.md +93 -93
- package/skills/arktype/references/migrating.md +144 -158
- package/skills/arktype/references/precompile.md +7 -7
- package/out/chunk-4CUA5XIP.js +0 -7
- package/out/chunk-GPNK5353.js +0 -2529
- package/out/chunk-MLKGABMK.js +0 -9
- package/out/chunk-PRTMQCHS.js +0 -3
- package/out/chunk-R5G57XC7.js +0 -7
- package/out/chunk-SWOOCAHN.js +0 -4
- package/out/chunk-TAHPKDNM.js +0 -3
- package/out/chunk-UETB6YE2.js +0 -14
package/out/cli.js
ADDED
|
@@ -0,0 +1,636 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { spawnSync } from "node:child_process";
|
|
3
|
+
import { constants, copyFileSync, existsSync, lstatSync, mkdirSync, readdirSync, readFileSync, realpathSync, statSync, unlinkSync, writeFileSync } from "node:fs";
|
|
4
|
+
import { createRequire } from "node:module";
|
|
5
|
+
import { basename, dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
6
|
+
import { fileURLToPath } from "node:url";
|
|
7
|
+
import { parseArgs } from "node:util";
|
|
8
|
+
const here = dirname(fileURLToPath(import.meta.url));
|
|
9
|
+
// works both from source (ark/type/cli.ts) and built (ark/type/out/cli.js)
|
|
10
|
+
const arktypeRoot = existsSync(join(here, "package.json")) ? here : dirname(here);
|
|
11
|
+
const arktypeManifest = JSON.parse(readFileSync(join(arktypeRoot, "package.json"), "utf8"));
|
|
12
|
+
export const bundledSkillPath = () => join(arktypeRoot, "skills", "arktype");
|
|
13
|
+
const readManifest = (dir) => {
|
|
14
|
+
const path = join(dir, "package.json");
|
|
15
|
+
if (!existsSync(path))
|
|
16
|
+
return undefined;
|
|
17
|
+
try {
|
|
18
|
+
return JSON.parse(readFileSync(path, "utf8").replace(/^\uFEFF/, ""));
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
const findProjectRoot = (startDir) => {
|
|
25
|
+
for (let dir = resolve(startDir);; dir = dirname(dir)) {
|
|
26
|
+
if (existsSync(join(dir, "package.json")))
|
|
27
|
+
return dir;
|
|
28
|
+
const parent = dirname(dir);
|
|
29
|
+
if (parent === dir)
|
|
30
|
+
return resolve(startDir);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
export const detectPackageManager = (startDir) => {
|
|
34
|
+
for (let dir = resolve(startDir);; dir = dirname(dir)) {
|
|
35
|
+
if (existsSync(join(dir, "pnpm-lock.yaml")))
|
|
36
|
+
return "pnpm";
|
|
37
|
+
if (existsSync(join(dir, "bun.lock")) || existsSync(join(dir, "bun.lockb")))
|
|
38
|
+
return "bun";
|
|
39
|
+
if (existsSync(join(dir, "yarn.lock")))
|
|
40
|
+
return "yarn";
|
|
41
|
+
if (existsSync(join(dir, "package-lock.json")))
|
|
42
|
+
return "npm";
|
|
43
|
+
const parent = dirname(dir);
|
|
44
|
+
if (parent === dir)
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
const ua = process.env.npm_config_user_agent ?? "";
|
|
48
|
+
if (ua.startsWith("pnpm/"))
|
|
49
|
+
return "pnpm";
|
|
50
|
+
if (ua.startsWith("bun/"))
|
|
51
|
+
return "bun";
|
|
52
|
+
if (ua.startsWith("yarn/"))
|
|
53
|
+
return "yarn";
|
|
54
|
+
return "npm";
|
|
55
|
+
};
|
|
56
|
+
export const installDevCommand = (pm, pkg) => pm === "pnpm" ? `pnpm add -D ${pkg}`
|
|
57
|
+
: pm === "bun" ? `bun add -d ${pkg}`
|
|
58
|
+
: pm === "yarn" ? `yarn add -D ${pkg}`
|
|
59
|
+
: `npm i -D ${pkg}`;
|
|
60
|
+
const detectedToolsOf = (manifest, projectRoot) => {
|
|
61
|
+
const deps = { ...manifest?.dependencies, ...manifest?.devDependencies };
|
|
62
|
+
const tools = [];
|
|
63
|
+
for (const name of [
|
|
64
|
+
"next",
|
|
65
|
+
"vite",
|
|
66
|
+
"vitest",
|
|
67
|
+
"webpack",
|
|
68
|
+
"esbuild",
|
|
69
|
+
"rollup",
|
|
70
|
+
"rspack",
|
|
71
|
+
"tsup",
|
|
72
|
+
"tsdown"
|
|
73
|
+
])
|
|
74
|
+
if (name in deps)
|
|
75
|
+
tools.push(name);
|
|
76
|
+
if ("bun" in deps ||
|
|
77
|
+
existsSync(join(projectRoot, "bun.lock")) ||
|
|
78
|
+
existsSync(join(projectRoot, "bun.lockb")) ||
|
|
79
|
+
existsSync(join(projectRoot, "bunfig.toml")))
|
|
80
|
+
tools.push("bun");
|
|
81
|
+
return tools;
|
|
82
|
+
};
|
|
83
|
+
const migrationSources = [
|
|
84
|
+
"zod",
|
|
85
|
+
"valibot",
|
|
86
|
+
"yup",
|
|
87
|
+
"joi",
|
|
88
|
+
"typebox",
|
|
89
|
+
"v2"
|
|
90
|
+
];
|
|
91
|
+
export const detectMigrationSource = (manifest) => {
|
|
92
|
+
const deps = { ...manifest?.dependencies, ...manifest?.devDependencies };
|
|
93
|
+
if ("zod" in deps)
|
|
94
|
+
return "zod";
|
|
95
|
+
if ("valibot" in deps)
|
|
96
|
+
return "valibot";
|
|
97
|
+
if ("yup" in deps)
|
|
98
|
+
return "yup";
|
|
99
|
+
if ("joi" in deps)
|
|
100
|
+
return "joi";
|
|
101
|
+
if ("@sinclair/typebox" in deps || "typebox" in deps)
|
|
102
|
+
return "typebox";
|
|
103
|
+
const arkVer = deps.arktype;
|
|
104
|
+
if (arkVer && /(?:^|[\s<=>^~])2\./.test(arkVer))
|
|
105
|
+
return "v2";
|
|
106
|
+
return undefined;
|
|
107
|
+
};
|
|
108
|
+
const defaultSkillTarget = (projectRoot) => {
|
|
109
|
+
if (existsSync(join(projectRoot, ".claude")) &&
|
|
110
|
+
!existsSync(join(projectRoot, ".agents")))
|
|
111
|
+
return join(projectRoot, ".claude", "skills", "arktype");
|
|
112
|
+
return join(projectRoot, ".agents", "skills", "arktype");
|
|
113
|
+
};
|
|
114
|
+
const lstatIfExists = (path) => {
|
|
115
|
+
try {
|
|
116
|
+
return lstatSync(path);
|
|
117
|
+
}
|
|
118
|
+
catch (e) {
|
|
119
|
+
if (e.code === "ENOENT")
|
|
120
|
+
return undefined;
|
|
121
|
+
throw e;
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
const isWithinDir = (root, target) => {
|
|
125
|
+
const rel = relative(root, target);
|
|
126
|
+
return (rel === "" ||
|
|
127
|
+
(rel !== ".." &&
|
|
128
|
+
!rel.startsWith(`..${sep}`) &&
|
|
129
|
+
!rel.startsWith("../") &&
|
|
130
|
+
!isAbsolute(rel)));
|
|
131
|
+
};
|
|
132
|
+
const resolveSafeSkillDir = (projectRoot, dest, explicitDir, allowOutside) => {
|
|
133
|
+
const realRoot = realpathSync(projectRoot);
|
|
134
|
+
// walk up via lstat so dangling symlinks are detected instead of skipped
|
|
135
|
+
let cur = dest;
|
|
136
|
+
let stat = lstatIfExists(cur);
|
|
137
|
+
while (!stat) {
|
|
138
|
+
const parent = dirname(cur);
|
|
139
|
+
if (parent === cur)
|
|
140
|
+
break;
|
|
141
|
+
cur = parent;
|
|
142
|
+
stat = lstatIfExists(cur);
|
|
143
|
+
}
|
|
144
|
+
let resolvedAncestor;
|
|
145
|
+
if (stat?.isSymbolicLink()) {
|
|
146
|
+
try {
|
|
147
|
+
resolvedAncestor = realpathSync(cur);
|
|
148
|
+
}
|
|
149
|
+
catch {
|
|
150
|
+
throw new Error(`Refusing to install skill through dangling symlink ${cur}`);
|
|
151
|
+
}
|
|
152
|
+
if (!statSync(resolvedAncestor).isDirectory()) {
|
|
153
|
+
throw new Error(`Cannot install skill to ${dest}: ${cur} resolves to ${resolvedAncestor}, which is not a directory`);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
else if (stat && !stat.isDirectory()) {
|
|
157
|
+
throw new Error(`Cannot install skill to ${dest}: ${cur} is not a directory`);
|
|
158
|
+
}
|
|
159
|
+
else
|
|
160
|
+
resolvedAncestor = realpathSync(cur);
|
|
161
|
+
const resolvedDest = join(resolvedAncestor, relative(cur, dest));
|
|
162
|
+
if (!explicitDir && !allowOutside && !isWithinDir(realRoot, resolvedDest)) {
|
|
163
|
+
throw new Error(`Refusing to install skill to ${dest}: resolves to ${resolvedDest}, outside project root ${realRoot} (pass --allow-outside to allow)`);
|
|
164
|
+
}
|
|
165
|
+
return resolvedDest;
|
|
166
|
+
};
|
|
167
|
+
const validateSkillTree = (srcDir, destDir) => {
|
|
168
|
+
for (const entry of readdirSync(srcDir, { withFileTypes: true })) {
|
|
169
|
+
const srcPath = join(srcDir, entry.name);
|
|
170
|
+
const destPath = join(destDir, entry.name);
|
|
171
|
+
const destStat = lstatIfExists(destPath);
|
|
172
|
+
if (destStat?.isSymbolicLink())
|
|
173
|
+
throw new Error(`Refusing to write through symlink at ${destPath}`);
|
|
174
|
+
if (entry.isDirectory()) {
|
|
175
|
+
if (destStat && !destStat.isDirectory()) {
|
|
176
|
+
throw new Error(`Cannot create directory at ${destPath}: path exists and is not a directory`);
|
|
177
|
+
}
|
|
178
|
+
validateSkillTree(srcPath, destPath);
|
|
179
|
+
}
|
|
180
|
+
else if (entry.isFile() && destStat && !destStat.isFile()) {
|
|
181
|
+
throw new Error(`Cannot write file at ${destPath}: path exists and is not a regular file`);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
const copySkillTree = (srcDir, destDir) => {
|
|
186
|
+
for (const entry of readdirSync(srcDir, { withFileTypes: true })) {
|
|
187
|
+
const srcPath = join(srcDir, entry.name);
|
|
188
|
+
const destPath = join(destDir, entry.name);
|
|
189
|
+
const destStat = lstatIfExists(destPath);
|
|
190
|
+
if (destStat?.isSymbolicLink())
|
|
191
|
+
throw new Error(`Refusing to write through symlink at ${destPath}`);
|
|
192
|
+
if (entry.isDirectory()) {
|
|
193
|
+
if (destStat && !destStat.isDirectory()) {
|
|
194
|
+
throw new Error(`Cannot create directory at ${destPath}: path exists and is not a directory`);
|
|
195
|
+
}
|
|
196
|
+
if (!destStat)
|
|
197
|
+
mkdirSync(destPath);
|
|
198
|
+
copySkillTree(srcPath, destPath);
|
|
199
|
+
}
|
|
200
|
+
else if (entry.isFile()) {
|
|
201
|
+
if (destStat) {
|
|
202
|
+
if (!destStat.isFile()) {
|
|
203
|
+
throw new Error(`Cannot write file at ${destPath}: path exists and is not a regular file`);
|
|
204
|
+
}
|
|
205
|
+
unlinkSync(destPath);
|
|
206
|
+
}
|
|
207
|
+
copyFileSync(srcPath, destPath, constants.COPYFILE_EXCL);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
const resolveExplicitSkillTarget = (cwd, targetDir) => {
|
|
212
|
+
const resolved = resolve(cwd, targetDir);
|
|
213
|
+
return basename(resolved) === "arktype" ? resolved : join(resolved, "arktype");
|
|
214
|
+
};
|
|
215
|
+
const prepareSkillInstall = (projectRoot, targetDir, opts) => {
|
|
216
|
+
const src = bundledSkillPath();
|
|
217
|
+
const dest = targetDir !== undefined ?
|
|
218
|
+
resolveExplicitSkillTarget(opts?.cwd ?? process.cwd(), targetDir)
|
|
219
|
+
: defaultSkillTarget(projectRoot);
|
|
220
|
+
const resolvedDest = resolveSafeSkillDir(projectRoot, dest, targetDir !== undefined, Boolean(opts?.allowOutside));
|
|
221
|
+
const realSrc = realpathSync(src);
|
|
222
|
+
if (isWithinDir(realSrc, resolvedDest) ||
|
|
223
|
+
isWithinDir(resolvedDest, realSrc)) {
|
|
224
|
+
throw new Error(`Refusing to install skill to ${dest}: destination overlaps bundled skill source ${realSrc}`);
|
|
225
|
+
}
|
|
226
|
+
validateSkillTree(realSrc, resolvedDest);
|
|
227
|
+
return { dest, realSrc, resolvedDest };
|
|
228
|
+
};
|
|
229
|
+
const applySkillInstall = ({ dest, realSrc, resolvedDest }) => {
|
|
230
|
+
mkdirSync(resolvedDest, { recursive: true });
|
|
231
|
+
copySkillTree(realSrc, resolvedDest);
|
|
232
|
+
return dest;
|
|
233
|
+
};
|
|
234
|
+
export const installBundledSkill = (projectRoot, targetDir, opts) => applySkillInstall(prepareSkillInstall(projectRoot, targetDir, opts));
|
|
235
|
+
const findAotManifest = (startDir) => {
|
|
236
|
+
for (let dir = startDir;; dir = dirname(dir)) {
|
|
237
|
+
const manifest = readManifest(dir);
|
|
238
|
+
if (manifest?.name === "@ark/aot")
|
|
239
|
+
return { pkgDir: dir, manifest };
|
|
240
|
+
const parent = dirname(dir);
|
|
241
|
+
if (parent === dir)
|
|
242
|
+
return undefined;
|
|
243
|
+
}
|
|
244
|
+
};
|
|
245
|
+
const findAotInNodeModules = (cwd) => {
|
|
246
|
+
for (let dir = resolve(cwd);; dir = dirname(dir)) {
|
|
247
|
+
const pkgDir = join(dir, "node_modules", "@ark", "aot");
|
|
248
|
+
const manifest = readManifest(pkgDir);
|
|
249
|
+
if (manifest?.name === "@ark/aot")
|
|
250
|
+
return { pkgDir, manifest };
|
|
251
|
+
const parent = dirname(dir);
|
|
252
|
+
if (parent === dir)
|
|
253
|
+
return undefined;
|
|
254
|
+
}
|
|
255
|
+
};
|
|
256
|
+
const findAotViaRequire = (cwd) => {
|
|
257
|
+
const req = createRequire(join(resolve(cwd), "package.json"));
|
|
258
|
+
try {
|
|
259
|
+
const found = findAotManifest(dirname(req.resolve("@ark/aot")));
|
|
260
|
+
if (found)
|
|
261
|
+
return found;
|
|
262
|
+
}
|
|
263
|
+
catch {
|
|
264
|
+
// fall back to resolving package.json directly when root entry isn't available
|
|
265
|
+
}
|
|
266
|
+
try {
|
|
267
|
+
const pkgPath = req.resolve("@ark/aot/package.json");
|
|
268
|
+
const pkgDir = dirname(pkgPath);
|
|
269
|
+
const manifest = readManifest(pkgDir);
|
|
270
|
+
if (manifest)
|
|
271
|
+
return { pkgDir, manifest };
|
|
272
|
+
}
|
|
273
|
+
catch {
|
|
274
|
+
return undefined;
|
|
275
|
+
}
|
|
276
|
+
return undefined;
|
|
277
|
+
};
|
|
278
|
+
const resolveAotCli = (cwd) => {
|
|
279
|
+
// Yarn PnP has no node_modules on disk; resolve through Node's module hooks
|
|
280
|
+
// (avoiding NODE_PATH leaks from pnpm bin shims in non-PnP environments)
|
|
281
|
+
const found = findAotInNodeModules(cwd) ??
|
|
282
|
+
("pnp" in process.versions ? findAotViaRequire(cwd) : undefined);
|
|
283
|
+
if (!found)
|
|
284
|
+
return undefined;
|
|
285
|
+
const { pkgDir, manifest } = found;
|
|
286
|
+
const bin = typeof manifest.bin === "string" ?
|
|
287
|
+
manifest.bin
|
|
288
|
+
: manifest.bin?.["arktype-precompile"];
|
|
289
|
+
if (bin && existsSync(join(pkgDir, bin)))
|
|
290
|
+
return join(pkgDir, bin);
|
|
291
|
+
const srcCli = join(pkgDir, "cli.ts");
|
|
292
|
+
if (existsSync(srcCli))
|
|
293
|
+
return srcCli;
|
|
294
|
+
return undefined;
|
|
295
|
+
};
|
|
296
|
+
const aotSubcommands = new Set(["check", "emit", "declare"]);
|
|
297
|
+
const runAot = (subcommand, rest, cwd, stderr) => {
|
|
298
|
+
const cliPath = resolveAotCli(cwd);
|
|
299
|
+
if (!cliPath) {
|
|
300
|
+
const pm = detectPackageManager(cwd);
|
|
301
|
+
const spec = arktypeManifest.arkAotVersion ?
|
|
302
|
+
`@ark/aot@${arktypeManifest.arkAotVersion}`
|
|
303
|
+
: "@ark/aot";
|
|
304
|
+
stderr(`@ark/aot is not installed. Install it to run \`ark ${subcommand}\`:\n\n ${installDevCommand(pm, spec)}\n`);
|
|
305
|
+
return 1;
|
|
306
|
+
}
|
|
307
|
+
const result = spawnSync(process.execPath, [cliPath, `--${subcommand}`, ...rest], { cwd, stdio: "inherit" });
|
|
308
|
+
return result.status ?? 1;
|
|
309
|
+
};
|
|
310
|
+
const hasArkPrecompileSetting = (manifest) => typeof manifest?.ark === "object" &&
|
|
311
|
+
manifest.ark !== null &&
|
|
312
|
+
Object.prototype.hasOwnProperty.call(manifest.ark, "precompile");
|
|
313
|
+
const runInit = (args, cwd, stdout, stderr) => {
|
|
314
|
+
let parsed;
|
|
315
|
+
try {
|
|
316
|
+
parsed = parseArgs({
|
|
317
|
+
args,
|
|
318
|
+
options: {
|
|
319
|
+
force: { type: "boolean", default: false },
|
|
320
|
+
"no-skill": { type: "boolean", default: false },
|
|
321
|
+
"allow-outside": { type: "boolean", default: false },
|
|
322
|
+
help: { type: "boolean", short: "h", default: false }
|
|
323
|
+
},
|
|
324
|
+
allowPositionals: false
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
catch (e) {
|
|
328
|
+
stderr(`${e.message}\n`);
|
|
329
|
+
return 1;
|
|
330
|
+
}
|
|
331
|
+
if (parsed.values.help) {
|
|
332
|
+
stdout("Usage: ark init [--force] [--no-skill] [--allow-outside]\n\nDetects your bundler/test runner, writes ark.json, and installs the bundled ArkType skill.\n");
|
|
333
|
+
return 0;
|
|
334
|
+
}
|
|
335
|
+
const projectRoot = findProjectRoot(cwd);
|
|
336
|
+
const manifest = readManifest(projectRoot);
|
|
337
|
+
const tools = detectedToolsOf(manifest, projectRoot);
|
|
338
|
+
const settingsPath = join(projectRoot, "ark.json");
|
|
339
|
+
const settingsContent = `${JSON.stringify({ precompile: {} }, null, "\t")}\n`;
|
|
340
|
+
const hasSettings = hasArkPrecompileSetting(manifest);
|
|
341
|
+
let existingSettings;
|
|
342
|
+
if (!hasSettings && parsed.values.force) {
|
|
343
|
+
existingSettings = lstatIfExists(settingsPath);
|
|
344
|
+
if (existingSettings?.isSymbolicLink()) {
|
|
345
|
+
stderr(`Refusing to overwrite symlink at ${settingsPath}.\n`);
|
|
346
|
+
return 1;
|
|
347
|
+
}
|
|
348
|
+
if (existingSettings && !existingSettings.isFile()) {
|
|
349
|
+
stderr(`Cannot write ${settingsPath}: path is not a regular file.\n`);
|
|
350
|
+
return 1;
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
let preparedSkill;
|
|
354
|
+
if (!parsed.values["no-skill"]) {
|
|
355
|
+
try {
|
|
356
|
+
preparedSkill = prepareSkillInstall(projectRoot, undefined, {
|
|
357
|
+
allowOutside: Boolean(parsed.values["allow-outside"])
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
catch (e) {
|
|
361
|
+
stderr(`${e.message}\n`);
|
|
362
|
+
return 1;
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
if (hasSettings) {
|
|
366
|
+
stdout(`Found existing "ark" settings in ${join(projectRoot, "package.json")}; leaving ark.json untouched.\n`);
|
|
367
|
+
}
|
|
368
|
+
else if (parsed.values.force) {
|
|
369
|
+
try {
|
|
370
|
+
if (existingSettings)
|
|
371
|
+
unlinkSync(settingsPath);
|
|
372
|
+
writeFileSync(settingsPath, settingsContent, { flag: "wx" });
|
|
373
|
+
}
|
|
374
|
+
catch (e) {
|
|
375
|
+
stderr(`Failed to write ${settingsPath}: ${e.message}\n`);
|
|
376
|
+
return 1;
|
|
377
|
+
}
|
|
378
|
+
stdout(`Created ${settingsPath}\n`);
|
|
379
|
+
}
|
|
380
|
+
else {
|
|
381
|
+
// lstat before writing: on Windows, the "wx" flag follows a dangling
|
|
382
|
+
// symlink and creates its target (possibly outside the project) instead
|
|
383
|
+
// of failing with EEXIST as POSIX does. "wx" stays as the defense
|
|
384
|
+
// against a file appearing between the lstat and the write.
|
|
385
|
+
const reportExisting = (stat) => {
|
|
386
|
+
const detail = stat?.isSymbolicLink() ? "symlink"
|
|
387
|
+
: stat?.isDirectory() ? "directory"
|
|
388
|
+
: stat && !stat.isFile() ? "not a regular file"
|
|
389
|
+
: "pass --force to overwrite";
|
|
390
|
+
stdout(`ark.json already exists at ${settingsPath} (${detail}).\n`);
|
|
391
|
+
};
|
|
392
|
+
const stat = lstatIfExists(settingsPath);
|
|
393
|
+
if (stat)
|
|
394
|
+
reportExisting(stat);
|
|
395
|
+
else {
|
|
396
|
+
try {
|
|
397
|
+
writeFileSync(settingsPath, settingsContent, { flag: "wx" });
|
|
398
|
+
stdout(`Created ${settingsPath}\n`);
|
|
399
|
+
}
|
|
400
|
+
catch (e) {
|
|
401
|
+
const code = e.code;
|
|
402
|
+
if (code === "EEXIST" || code === "EISDIR")
|
|
403
|
+
reportExisting(lstatIfExists(settingsPath));
|
|
404
|
+
else {
|
|
405
|
+
stderr(`Failed to write ${settingsPath}: ${e.message}\n`);
|
|
406
|
+
return 1;
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
if (preparedSkill) {
|
|
412
|
+
try {
|
|
413
|
+
const dest = applySkillInstall(preparedSkill);
|
|
414
|
+
stdout(`Installed ArkType skill to ${dest}\n`);
|
|
415
|
+
}
|
|
416
|
+
catch (e) {
|
|
417
|
+
stderr(`${e.message}\n`);
|
|
418
|
+
return 1;
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
if (tools.length)
|
|
422
|
+
stdout(`Detected tools: ${tools.join(", ")}\n`);
|
|
423
|
+
if (!resolveAotCli(projectRoot)) {
|
|
424
|
+
const pm = detectPackageManager(projectRoot);
|
|
425
|
+
const spec = arktypeManifest.arkAotVersion ?
|
|
426
|
+
`@ark/aot@${arktypeManifest.arkAotVersion}`
|
|
427
|
+
: "@ark/aot";
|
|
428
|
+
stdout(`To precompile Types at build time, install @ark/aot:\n ${installDevCommand(pm, spec)}\n`);
|
|
429
|
+
}
|
|
430
|
+
return 0;
|
|
431
|
+
};
|
|
432
|
+
const buildMigrationPrompt = (source, skillDir) => {
|
|
433
|
+
const skillFile = join(skillDir, "SKILL.md");
|
|
434
|
+
if (source === "v2") {
|
|
435
|
+
return [
|
|
436
|
+
"Migrate this codebase from ArkType 2.x to ArkType 3.",
|
|
437
|
+
`Read the "Upgrading from ArkType 2" section of ${skillFile} and https://arktype.io/docs/upgrading.md first, then upgrade schemas, types, and error handling incrementally while keeping typecheck and tests green.`
|
|
438
|
+
].join("\n");
|
|
439
|
+
}
|
|
440
|
+
const fromLabel = source ?? "the existing validation library";
|
|
441
|
+
const migratingFile = join(skillDir, "references", "migrating.md");
|
|
442
|
+
return [
|
|
443
|
+
`Migrate this codebase from ${fromLabel} to ArkType 3.`,
|
|
444
|
+
`Read ${skillFile} and ${migratingFile} first, then convert schemas, types, and error handling incrementally while keeping typecheck and tests green.`
|
|
445
|
+
].join("\n");
|
|
446
|
+
};
|
|
447
|
+
const findAgentBinary = (preferred) => {
|
|
448
|
+
const candidates = preferred ? [preferred] : ["claude", "codex"];
|
|
449
|
+
for (const cmd of candidates) {
|
|
450
|
+
const probe = spawnSync(cmd, ["--version"], { stdio: "ignore" });
|
|
451
|
+
if (probe.status === 0)
|
|
452
|
+
return cmd;
|
|
453
|
+
}
|
|
454
|
+
return undefined;
|
|
455
|
+
};
|
|
456
|
+
const runMigrate = (args, cwd, stdout, stderr) => {
|
|
457
|
+
let parsed;
|
|
458
|
+
try {
|
|
459
|
+
parsed = parseArgs({
|
|
460
|
+
args,
|
|
461
|
+
options: {
|
|
462
|
+
run: { type: "boolean", default: false },
|
|
463
|
+
agent: { type: "string" },
|
|
464
|
+
"no-skill": { type: "boolean", default: false },
|
|
465
|
+
"allow-outside": { type: "boolean", default: false },
|
|
466
|
+
help: { type: "boolean", short: "h", default: false }
|
|
467
|
+
},
|
|
468
|
+
allowPositionals: true
|
|
469
|
+
});
|
|
470
|
+
}
|
|
471
|
+
catch (e) {
|
|
472
|
+
stderr(`${e.message}\n`);
|
|
473
|
+
return 1;
|
|
474
|
+
}
|
|
475
|
+
if (parsed.values.help) {
|
|
476
|
+
stdout(`Usage: ark migrate [${migrationSources.join("|")}] [--run] [--agent claude|codex] [--no-skill] [--allow-outside]\n\nDetects your existing validator, installs the bundled ArkType skill, and prints (or launches) a migration prompt.\n`);
|
|
477
|
+
return 0;
|
|
478
|
+
}
|
|
479
|
+
const projectRoot = findProjectRoot(cwd);
|
|
480
|
+
const manifest = readManifest(projectRoot);
|
|
481
|
+
const argSource = parsed.positionals[0];
|
|
482
|
+
let source;
|
|
483
|
+
if (argSource !== undefined) {
|
|
484
|
+
if (!migrationSources.includes(argSource)) {
|
|
485
|
+
stderr(`Unknown migration source "${argSource}". Expected one of: ${migrationSources.join(", ")}\n`);
|
|
486
|
+
return 1;
|
|
487
|
+
}
|
|
488
|
+
source = argSource;
|
|
489
|
+
}
|
|
490
|
+
else
|
|
491
|
+
source = detectMigrationSource(manifest);
|
|
492
|
+
let skillDir;
|
|
493
|
+
if (parsed.values["no-skill"])
|
|
494
|
+
skillDir = bundledSkillPath();
|
|
495
|
+
else {
|
|
496
|
+
try {
|
|
497
|
+
skillDir = installBundledSkill(projectRoot, undefined, {
|
|
498
|
+
allowOutside: Boolean(parsed.values["allow-outside"])
|
|
499
|
+
});
|
|
500
|
+
}
|
|
501
|
+
catch (e) {
|
|
502
|
+
stderr(`${e.message}\n`);
|
|
503
|
+
return 1;
|
|
504
|
+
}
|
|
505
|
+
stdout(`Installed ArkType skill to ${skillDir}\n`);
|
|
506
|
+
}
|
|
507
|
+
const prompt = buildMigrationPrompt(source, skillDir);
|
|
508
|
+
if (parsed.values.run || parsed.values.agent) {
|
|
509
|
+
const requested = typeof parsed.values.agent === "string" ? parsed.values.agent : undefined;
|
|
510
|
+
const bin = findAgentBinary(requested);
|
|
511
|
+
if (!bin) {
|
|
512
|
+
stderr(requested ?
|
|
513
|
+
`Agent CLI "${requested}" not found on PATH.\n`
|
|
514
|
+
: `Neither "claude" nor "codex" was found on PATH. Run the prompt below in your coding agent:\n\n${prompt}\n`);
|
|
515
|
+
return 1;
|
|
516
|
+
}
|
|
517
|
+
const result = spawnSync(bin, [prompt], {
|
|
518
|
+
cwd: projectRoot,
|
|
519
|
+
stdio: "inherit"
|
|
520
|
+
});
|
|
521
|
+
return result.status ?? 1;
|
|
522
|
+
}
|
|
523
|
+
stdout(`\n${prompt}\n`);
|
|
524
|
+
return 0;
|
|
525
|
+
};
|
|
526
|
+
const runSkill = (args, cwd, stdout, stderr) => {
|
|
527
|
+
let parsed;
|
|
528
|
+
try {
|
|
529
|
+
parsed = parseArgs({
|
|
530
|
+
args,
|
|
531
|
+
options: {
|
|
532
|
+
dir: { type: "string" },
|
|
533
|
+
"allow-outside": { type: "boolean", default: false },
|
|
534
|
+
help: { type: "boolean", short: "h", default: false }
|
|
535
|
+
},
|
|
536
|
+
allowPositionals: true
|
|
537
|
+
});
|
|
538
|
+
}
|
|
539
|
+
catch (e) {
|
|
540
|
+
stderr(`${e.message}\n`);
|
|
541
|
+
return 1;
|
|
542
|
+
}
|
|
543
|
+
if (parsed.values.help) {
|
|
544
|
+
stdout("Usage: ark skill [path|install] [--dir <path>] [--allow-outside]\n\nPrints the path to the bundled ArkType skill or installs it into your project. With --dir <path> (resolved from cwd), installs to <path>/arktype unless <path> already ends in arktype.\n");
|
|
545
|
+
return 0;
|
|
546
|
+
}
|
|
547
|
+
const action = parsed.positionals[0] ?? "path";
|
|
548
|
+
if (action === "path") {
|
|
549
|
+
stdout(`${bundledSkillPath()}\n`);
|
|
550
|
+
return 0;
|
|
551
|
+
}
|
|
552
|
+
if (action === "install") {
|
|
553
|
+
const projectRoot = findProjectRoot(cwd);
|
|
554
|
+
const target = typeof parsed.values.dir === "string" ? parsed.values.dir : undefined;
|
|
555
|
+
try {
|
|
556
|
+
const dest = installBundledSkill(projectRoot, target, {
|
|
557
|
+
allowOutside: Boolean(parsed.values["allow-outside"]),
|
|
558
|
+
cwd
|
|
559
|
+
});
|
|
560
|
+
stdout(`Installed ArkType skill to ${dest}\n`);
|
|
561
|
+
return 0;
|
|
562
|
+
}
|
|
563
|
+
catch (e) {
|
|
564
|
+
stderr(`${e.message}\n`);
|
|
565
|
+
return 1;
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
stderr(`Unknown skill action "${action}". Expected "path" or "install".\n`);
|
|
569
|
+
return 1;
|
|
570
|
+
};
|
|
571
|
+
const usage = `Usage: ark <command> [options]
|
|
572
|
+
|
|
573
|
+
Commands:
|
|
574
|
+
aot <check|emit|declare> [...flags] Run @ark/aot precompiler commands
|
|
575
|
+
check [...flags] Shortcut for \`ark aot check\`
|
|
576
|
+
emit [...flags] Shortcut for \`ark aot emit\`
|
|
577
|
+
declare [...flags] Shortcut for \`ark aot declare\`
|
|
578
|
+
init [--force] [--no-skill] [--allow-outside] Detect setup, write ark.json, install skill
|
|
579
|
+
migrate [source] [--run] [--agent <cli>] Generate or launch a migration prompt
|
|
580
|
+
[--no-skill] [--allow-outside]
|
|
581
|
+
skill [path|install] [--dir <path>] Print path to or install the bundled skill
|
|
582
|
+
[--allow-outside]
|
|
583
|
+
|
|
584
|
+
Options:
|
|
585
|
+
-h, --help Show help
|
|
586
|
+
-v, --version Show version
|
|
587
|
+
`;
|
|
588
|
+
export const runCli = (argv, ctx = {}) => {
|
|
589
|
+
const cwd = ctx.cwd ?? process.cwd();
|
|
590
|
+
const stdout = ctx.stdout ?? (text => process.stdout.write(text));
|
|
591
|
+
const stderr = ctx.stderr ?? (text => process.stderr.write(text));
|
|
592
|
+
const [cmd, ...rest] = argv;
|
|
593
|
+
if (!cmd || cmd === "-h" || cmd === "--help") {
|
|
594
|
+
stdout(usage);
|
|
595
|
+
return 0;
|
|
596
|
+
}
|
|
597
|
+
if (cmd === "-v" || cmd === "--version") {
|
|
598
|
+
stdout(`${arktypeManifest.version ?? "unknown"}\n`);
|
|
599
|
+
return 0;
|
|
600
|
+
}
|
|
601
|
+
if (aotSubcommands.has(cmd))
|
|
602
|
+
return runAot(cmd, rest, cwd, stderr);
|
|
603
|
+
if (cmd === "aot") {
|
|
604
|
+
const [sub, ...subRest] = rest;
|
|
605
|
+
if (!sub || sub === "-h" || sub === "--help") {
|
|
606
|
+
stdout("Usage: ark aot <check|emit|declare> [...flags]\n");
|
|
607
|
+
return 0;
|
|
608
|
+
}
|
|
609
|
+
if (!aotSubcommands.has(sub)) {
|
|
610
|
+
stderr(`Unknown aot subcommand "${sub}". Expected check, emit, or declare.\n`);
|
|
611
|
+
return 1;
|
|
612
|
+
}
|
|
613
|
+
return runAot(sub, subRest, cwd, stderr);
|
|
614
|
+
}
|
|
615
|
+
if (cmd === "init")
|
|
616
|
+
return runInit(rest, cwd, stdout, stderr);
|
|
617
|
+
if (cmd === "migrate")
|
|
618
|
+
return runMigrate(rest, cwd, stdout, stderr);
|
|
619
|
+
if (cmd === "skill")
|
|
620
|
+
return runSkill(rest, cwd, stdout, stderr);
|
|
621
|
+
stderr(`Unknown command "${cmd}".\n\n${usage}`);
|
|
622
|
+
return 1;
|
|
623
|
+
};
|
|
624
|
+
const isMain = () => {
|
|
625
|
+
const entry = process.argv[1];
|
|
626
|
+
if (!entry)
|
|
627
|
+
return false;
|
|
628
|
+
try {
|
|
629
|
+
return realpathSync(entry) === realpathSync(fileURLToPath(import.meta.url));
|
|
630
|
+
}
|
|
631
|
+
catch {
|
|
632
|
+
return false;
|
|
633
|
+
}
|
|
634
|
+
};
|
|
635
|
+
if (isMain())
|
|
636
|
+
process.exit(runCli(process.argv.slice(2)));
|
package/out/codecs.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import type { ArkError, ArkErrors, Morph } from "
|
|
2
|
-
import type { noInfer } from "
|
|
1
|
+
import type { ArkError, ArkErrors, Morph } from "./_internal/schema/index.js";
|
|
2
|
+
import type { noInfer } from "./_internal/util/index.js";
|
|
3
3
|
import type { distill, inferPipe, Out } from "./attributes.ts";
|
|
4
4
|
import { type } from "./keywords/keywords.ts";
|
|
5
|
+
import type { inferDefinition } from "./parser/definition.ts";
|
|
5
6
|
import type { instantiateType } from "./variants/instantiate.ts";
|
|
6
7
|
/**
|
|
7
8
|
* Create a {@link Type} from a morph and its inverse
|
|
@@ -15,7 +16,7 @@ import type { instantiateType } from "./variants/instantiate.ts";
|
|
|
15
16
|
* // 0
|
|
16
17
|
* const ms = EpochMs.encode(date)
|
|
17
18
|
*/
|
|
18
|
-
export declare const codec: <const i, const o, r = instantiateType<inferPipe<(In: distill.In<
|
|
19
|
-
decode: Morph<distill.Out<
|
|
20
|
-
encode: Morph<distill.In<
|
|
19
|
+
export declare const codec: <const i, const o, r = instantiateType<inferPipe<(In: distill.In<inferDefinition<i>>) => Out<distill.In<inferDefinition<o>>>, inferDefinition<o>>, {}>>(i: type.validate<i>, o: type.validate<o>, { decode, encode }: noInfer<{
|
|
20
|
+
decode: Morph<distill.Out<inferDefinition<i>>, distill.In<inferDefinition<o>> | ArkError | ArkErrors>;
|
|
21
|
+
encode: Morph<distill.In<inferDefinition<o>>, distill.Out<inferDefinition<i>> | ArkError | ArkErrors>;
|
|
21
22
|
}, i | o>) => r extends infer _ ? _ : never;
|
package/out/codecs.js
CHANGED
|
@@ -1,7 +1,23 @@
|
|
|
1
|
-
export { codec } from "./chunk-
|
|
2
|
-
import "./chunk-
|
|
3
|
-
import "./chunk-
|
|
4
|
-
import "./chunk-
|
|
5
|
-
import "./chunk-
|
|
6
|
-
import "./chunk-
|
|
7
|
-
import "./chunk-
|
|
1
|
+
export { codec } from "./chunk-FWRSDUJ2.js";
|
|
2
|
+
import "./chunk-GID3FSQA.js";
|
|
3
|
+
import "./chunk-C2V6QPE3.js";
|
|
4
|
+
import "./chunk-C3B4IFQL.js";
|
|
5
|
+
import "./chunk-4FTHWK63.js";
|
|
6
|
+
import "./chunk-BDJVONP7.js";
|
|
7
|
+
import "./chunk-C2JOL5M2.js";
|
|
8
|
+
import "./chunk-4HREHNIV.js";
|
|
9
|
+
import "./chunk-KXOC3JEX.js";
|
|
10
|
+
import "./chunk-CWSF57VM.js";
|
|
11
|
+
import "./chunk-UJJGG4VQ.js";
|
|
12
|
+
import "./chunk-US6BWOGJ.js";
|
|
13
|
+
import "./chunk-KXOSUYRA.js";
|
|
14
|
+
import "./chunk-W2XOI5DY.js";
|
|
15
|
+
import "./chunk-TACLEIDM.js";
|
|
16
|
+
import "./chunk-K7SLP5D2.js";
|
|
17
|
+
import "./chunk-VYMXHSFR.js";
|
|
18
|
+
import "./chunk-PDLTEX6Z.js";
|
|
19
|
+
import "./chunk-3KBOPH3J.js";
|
|
20
|
+
import "./chunk-ZRYEHGSG.js";
|
|
21
|
+
import "./chunk-3SH2BQ4T.js";
|
|
22
|
+
import "./chunk-3HZC67MT.js";
|
|
23
|
+
import "./chunk-I2KLQ2HA.js";
|