@taskless/cli 0.10.2 → 0.11.1

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.
@@ -0,0 +1,113 @@
1
+ /**
2
+ * Resolving a prebuilt binary that ships as a per-platform npm package.
3
+ *
4
+ * This was ast-grep's resolver in `scan.ts`, generalized when Vale became a
5
+ * second engine that needs the same treatment. Both depend on per-platform
6
+ * packages directly and exec by path, because neither can rely on an
7
+ * install-time step: `@ast-grep/cli`'s postinstall hardlink fails under pnpm
8
+ * dlx's strict isolation, and the `@taskless/vale-*` packages deliberately ship
9
+ * no `bin` and no scripts at all.
10
+ *
11
+ * WHAT IS PARAMETERIZED, and why each field exists rather than being derived:
12
+ *
13
+ * - `toolchainSuffix` is the one that bites. ast-grep publishes
14
+ * `@ast-grep/cli-linux-x64-gnu` and `-win32-x64-msvc`; the Vale packages are
15
+ * `@taskless/vale-linux-x64` with **no libc suffix at all**. Reusing
16
+ * ast-grep's naming for Vale would look up `@taskless/vale-linux-x64-gnu` and
17
+ * miss on every Linux host — a resolution failure that reads as "Vale is not
18
+ * installed" rather than as a naming bug.
19
+ * - `identity` exists because existence is not proof. A file can sit exactly
20
+ * where the binary belongs and not be the binary: ast-grep's failed hardlink
21
+ * leaves a placeholder text file there. Asking a candidate to identify itself
22
+ * is the only check that tells the two apart.
23
+ */
24
+ export interface PlatformBinarySpec {
25
+ /** Name used in error messages, e.g. `ast-grep`. */
26
+ label: string;
27
+ /** Package name up to the platform suffix, e.g. `@ast-grep/cli`. */
28
+ packagePrefix: string;
29
+ /**
30
+ * Append the platform's toolchain suffix (`-gnu` on Linux, `-msvc` on
31
+ * Windows). True for ast-grep, false for the Vale packages.
32
+ */
33
+ toolchainSuffix: boolean;
34
+ /**
35
+ * Executable names to try, in confidence order, spelled for unix. `.exe` is
36
+ * appended on Windows. More than one because ast-grep declares both
37
+ * `ast-grep` and `sg` for the same target.
38
+ *
39
+ * The first name is the canonical one: it is the only spelling probed inside
40
+ * the platform package, and it is the name error messages tell the user to put
41
+ * on PATH. The rest are alternative link names, tried *first* at the
42
+ * link-based tiers — see {@link resolvePlatformBinary}.
43
+ */
44
+ binaryNames: string[];
45
+ /** Pattern the candidate's own `--version` output must match. */
46
+ identity: RegExp;
47
+ }
48
+ /** The npm package carrying this host's prebuilt binary. */
49
+ export declare function platformPackageName(spec: PlatformBinarySpec): string;
50
+ /**
51
+ * The command name to tell a user to put on PATH, spelled for this platform
52
+ * (`sg.exe` on Windows). It is the first spelling the PATH search itself tries,
53
+ * so the advice and the search cannot drift apart.
54
+ */
55
+ export declare function pathCommandName(spec: PlatformBinarySpec): string;
56
+ /** First entry on PATH that holds a file named `command`. */
57
+ export declare function findOnPath(command: string): string | undefined;
58
+ /**
59
+ * Whether `path` is really this binary, established by running it.
60
+ *
61
+ * See {@link PlatformBinarySpec.identity} — existence is not enough, because a
62
+ * placeholder file left by a failed install sits at exactly the right path and
63
+ * satisfies `existsSync` happily.
64
+ */
65
+ export declare function isPlatformBinary(spec: PlatformBinarySpec, path: string): boolean;
66
+ /**
67
+ * Which tier produced a resolution.
68
+ *
69
+ * `platform-package` is the version this CLI pins and installs. The other two
70
+ * are whatever the host happens to carry, and can be any version.
71
+ */
72
+ export type PlatformBinarySource = "platform-package" | "node_modules/.bin" | "PATH";
73
+ export interface PlatformBinaryResolution {
74
+ /** Absolute path to the verified binary, or `undefined` when none resolved. */
75
+ path: string | undefined;
76
+ /**
77
+ * Which tier the path came from, or `undefined` when nothing resolved.
78
+ *
79
+ * **Identity is not provenance.** Resolution proves the file exists and
80
+ * answered `--version` as the right tool; it proves nothing about the
81
+ * version. Only `platform-package` is the pinned install, so only that tier
82
+ * entitles a caller to {@link AST_GREP_VERSION}-style constants without
83
+ * running the binary.
84
+ *
85
+ * Reported rather than left to be re-derived. A caller that needs the pinned
86
+ * engine would otherwise compare the returned path against a package root it
87
+ * reconstructs itself, which is this resolver's own search order copied into
88
+ * a consumer, and copies drift.
89
+ */
90
+ source: PlatformBinarySource | undefined;
91
+ /** Locations searched, in order, for an actionable failure message. */
92
+ tried: string[];
93
+ }
94
+ /**
95
+ * Search every place the binary could reasonably live, verifying each.
96
+ *
97
+ * Candidates are ordered by confidence rather than by convenience — the
98
+ * platform package first because it is the version we pinned, then a locally
99
+ * linked binary, then whatever the host provides on PATH.
100
+ *
101
+ * The platform package is probed under one name only. Its contents are ours to
102
+ * predict — the package ships the binary under its canonical name — so trying
103
+ * the alternative spellings there buys nothing but an extra `require.resolve`
104
+ * and a duplicate entry in `tried`, which reads to the user as the same
105
+ * location searched twice. The link-based tiers do try every spelling, because
106
+ * which one exists there is the installer's choice, not ours.
107
+ *
108
+ * Returns rather than throws. The two callers want different things from a
109
+ * miss: ast-grep cannot run at all without it, while a missing Vale binary
110
+ * makes one engine unavailable and must not abort the others (D6b). Encoding
111
+ * "not found" as a value rather than an exception is what lets each decide.
112
+ */
113
+ export declare function resolvePlatformBinary(spec: PlatformBinarySpec): PlatformBinaryResolution;
@@ -0,0 +1,35 @@
1
+ import { type PlatformBinaryResolution, type PlatformBinarySpec } from "../platform-binary";
2
+ /**
3
+ * Vale's per-platform packaging.
4
+ *
5
+ * `toolchainSuffix: false` is the whole reason this spec exists separately from
6
+ * ast-grep's. `add-vale-binary-packages` publishes `@taskless/vale-<os>-<cpu>`
7
+ * — `@taskless/vale-linux-x64`, not `-linux-x64-gnu`. ast-grep's resolver
8
+ * appends `-gnu` on every Linux, so reusing its naming here would resolve
9
+ * nothing on Linux while reporting the ordinary "Vale is unavailable" message,
10
+ * making a naming bug indistinguishable from a host without the binary.
11
+ *
12
+ * One binary name, unlike ast-grep's two: these packages ship `vale` (or
13
+ * `vale.exe`) as pure payload, with no `bin` entry and no lifecycle script, so
14
+ * there is no wrapper spelling to also try.
15
+ */
16
+ export declare const VALE_BINARY: PlatformBinarySpec;
17
+ /**
18
+ * Locate the Vale binary, or report that it is unavailable.
19
+ *
20
+ * Returns `undefined` rather than throwing, per D6b: a missing Vale binary
21
+ * makes the Vale engine unavailable and must not abort the other engines. The
22
+ * caller turns that into a reported-but-not-fatal outcome; ast-grep's resolver
23
+ * throws instead, because it has no degraded mode.
24
+ */
25
+ export declare function findValeBinary(): PlatformBinaryResolution;
26
+ /** Reset the process cache. Tests only. */
27
+ export declare function resetValeBinaryCache(): void;
28
+ /**
29
+ * An actionable message naming where we looked.
30
+ *
31
+ * The PATH advice is spelled for the platform — `vale.exe` on Windows — rather
32
+ * than hardcoded, so a Windows user is not told to install a name that the
33
+ * resolver would not find there.
34
+ */
35
+ export declare function valeUnavailableMessage(tried: string[]): string;
@@ -0,0 +1,93 @@
1
+ /**
2
+ * Public entry for `@taskless/cli/schemas`.
3
+ *
4
+ * The shapes this CLI's `--json` output is produced from, as data. A consumer
5
+ * parsing `taskless verify --json` validates against the schema the CLI emits
6
+ * from, rather than against an interface it hand-wrote by reading our output
7
+ * once.
8
+ *
9
+ * ## Why this is published
10
+ *
11
+ * This is `@taskless/cli/layout`'s argument applied to the other half of the
12
+ * contract. A hand-written interface is a copy that nothing checks: the CLI can
13
+ * add a field, change what one means, or extend an enum, and the copy stays
14
+ * confidently wrong until something downstream misbehaves. The Cloud eval team
15
+ * is doing exactly that today against the `verify` envelope.
16
+ *
17
+ * ## What this is NOT
18
+ *
19
+ * Not an SDK. Nothing here performs verification, and no `verify()` or `test()`
20
+ * is exported. Both spawn a vendored platform binary — ast-grep or Vale — so
21
+ * anywhere a function call could run them, `npx @taskless/cli verify --json`
22
+ * runs too: the export would buy a call site, not a capability, while making
23
+ * internal signatures public. The CLI stays the execution surface; this
24
+ * describes what it says.
25
+ *
26
+ * Nothing here reaches the filesystem, a process, the network or the command
27
+ * tree, so a Worker can import it — and the build fails rather than emitting an
28
+ * entry whose graph reaches a host capability. `writeJsonError` is deliberately
29
+ * absent for that reason: it writes to stdout, and a consumer asking what shape
30
+ * an error takes should not thereby acquire something that emits one.
31
+ *
32
+ * ## Zod is bundled, and that is the point
33
+ *
34
+ * This entry ships its own copy of zod rather than resolving the consumer's.
35
+ * That follows from the build's standing rule for library entries — everything
36
+ * but node builtins is bundled — but it is also the behaviour we want, so do
37
+ * not "fix" it by making zod external.
38
+ *
39
+ * **A consumer's zod is not ours.** Marking it external would make validation
40
+ * depend on whichever version resolved on the other side, so the same payload
41
+ * could parse there and not here, and the schema would stop being a statement
42
+ * about what this CLI emits. Bundling makes `parse()` answer with our zod's
43
+ * semantics wherever it runs.
44
+ *
45
+ * **And `parse()` is stronger than a JSON Schema of the same shape.** It
46
+ * strips: `parse({ ok: true, rules: [], surprise: 1 })` returns
47
+ * `{ ok: true, rules: [] }`, where a JSON Schema validator hands back the
48
+ * object it was given, unknown keys included. Every schema here is plain today
49
+ * — objects, enums, arrays, optionals — so a JSON Schema rendering would lose
50
+ * little beyond that. It is the moment we add a refinement that the difference
51
+ * bites, and it would bite silently: the rendering would go on validating a
52
+ * weaker shape while claiming to describe this one.
53
+ *
54
+ * `z.toJSONSchema()` therefore stays unexported, and the criterion is the
55
+ * TRANSPORT rather than the consumer's language. JSON Schema is what you reach
56
+ * for when the schema itself has to travel — when the far side can receive JSON
57
+ * and nothing else, so a description of the shape is the most that fits. That
58
+ * is not this boundary. A consumer here takes a dependency on our schema files,
59
+ * which means it can assert the payload rather than assert against a
60
+ * description of the payload, and rendering ours down to what a JSON transport
61
+ * could carry would give that up in exchange for nothing.
62
+ */
63
+ export {
64
+ /**
65
+ * `taskless verify --json` and `taskless test --json`.
66
+ *
67
+ * One envelope for both, because the commands share an implementation and
68
+ * differ only in what they run against each rule.
69
+ */
70
+ outputSchema as verifyTestOutputSchema, } from "./verify-test.js";
71
+ export {
72
+ /** `taskless rule verify <id> --json`, for an ast-grep rule. */
73
+ verifyOutputSchema,
74
+ /** The same, for a Vale rule — a different shape, discriminated on `engine`. */
75
+ valeVerifyOutputSchema, } from "./rules-verify.js";
76
+ export type {
77
+ /**
78
+ * A constraint `verify` or `test` enforces beyond an engine's own schema.
79
+ *
80
+ * The type of the entries in `@taskless/cli/reference.json`'s
81
+ * `constraints[]`, so a consumer reading the corpus and a consumer reading a
82
+ * rejection are working from one definition.
83
+ */
84
+ RuleConstraint,
85
+ /** One constraint a rule broke, as `violations[]` carries it. */
86
+ RuleViolation,
87
+ /** The id of a constraint this CLI publishes. */
88
+ RuleConstraintId, } from "../rules/constraints.js";
89
+ export type {
90
+ /** The stable code an error envelope carries under `--json`. */
91
+ CLIErrorCode,
92
+ /** The envelope itself. Not every `--json` failure is a rule result. */
93
+ CLIErrorEnvelope, } from "../types/errors.js";
@@ -0,0 +1,19 @@
1
+ import { z } from "zod";
2
+ /** Input schema for `taskless rule create --from` JSON file */
3
+ export declare const inputSchema: z.ZodObject<{
4
+ prompt: z.ZodString;
5
+ successCases: z.ZodOptional<z.ZodArray<z.ZodString>>;
6
+ failureCases: z.ZodOptional<z.ZodArray<z.ZodString>>;
7
+ }, z.core.$strip>;
8
+ /** Output schema for `taskless rule create --json` on success */
9
+ export declare const outputSchema: z.ZodObject<{
10
+ success: z.ZodLiteral<true>;
11
+ ruleId: z.ZodString;
12
+ rules: z.ZodArray<z.ZodString>;
13
+ files: z.ZodArray<z.ZodString>;
14
+ notices: z.ZodOptional<z.ZodArray<z.ZodString>>;
15
+ }, z.core.$strip>;
16
+ /** Error schema for `taskless rule create --json` on failure */
17
+ export declare const errorSchema: z.ZodObject<{
18
+ error: z.ZodString;
19
+ }, z.core.$strip>;
@@ -0,0 +1,22 @@
1
+ import { z } from "zod";
2
+ /** Input schema for `taskless rule improve --from` JSON file */
3
+ export declare const inputSchema: z.ZodObject<{
4
+ ruleId: z.ZodString;
5
+ guidance: z.ZodString;
6
+ references: z.ZodOptional<z.ZodArray<z.ZodObject<{
7
+ filename: z.ZodString;
8
+ content: z.ZodString;
9
+ }, z.core.$strip>>>;
10
+ }, z.core.$strip>;
11
+ /** Output schema for `taskless rule improve --json` on success */
12
+ export declare const outputSchema: z.ZodObject<{
13
+ success: z.ZodLiteral<true>;
14
+ requestId: z.ZodString;
15
+ rules: z.ZodArray<z.ZodString>;
16
+ files: z.ZodArray<z.ZodString>;
17
+ notices: z.ZodOptional<z.ZodArray<z.ZodString>>;
18
+ }, z.core.$strip>;
19
+ /** Error schema for `taskless rule improve --json` on failure */
20
+ export declare const errorSchema: z.ZodObject<{
21
+ error: z.ZodString;
22
+ }, z.core.$strip>;
@@ -0,0 +1,67 @@
1
+ import { z } from "zod";
2
+ export declare const schemaOutputSchema: z.ZodObject<{
3
+ astGrepSchema: z.ZodRecord<z.ZodString, z.ZodUnknown>;
4
+ tasklessRequirements: z.ZodObject<{
5
+ requiredFields: z.ZodArray<z.ZodString>;
6
+ rules: z.ZodArray<z.ZodObject<{
7
+ name: z.ZodString;
8
+ description: z.ZodString;
9
+ }, z.core.$strip>>;
10
+ }, z.core.$strip>;
11
+ examples: z.ZodArray<z.ZodObject<{
12
+ description: z.ZodString;
13
+ rule: z.ZodRecord<z.ZodString, z.ZodUnknown>;
14
+ }, z.core.$strip>>;
15
+ }, z.core.$strip>;
16
+ export declare const verifyOutputSchema: z.ZodObject<{
17
+ engine: z.ZodLiteral<"sg">;
18
+ success: z.ZodBoolean;
19
+ ruleId: z.ZodString;
20
+ schema: z.ZodObject<{
21
+ valid: z.ZodBoolean;
22
+ errors: z.ZodArray<z.ZodString>;
23
+ notice: z.ZodOptional<z.ZodString>;
24
+ }, z.core.$strip>;
25
+ requirements: z.ZodObject<{
26
+ valid: z.ZodBoolean;
27
+ errors: z.ZodArray<z.ZodString>;
28
+ }, z.core.$strip>;
29
+ tests: z.ZodObject<{
30
+ valid: z.ZodBoolean;
31
+ errors: z.ZodArray<z.ZodString>;
32
+ passed: z.ZodNumber;
33
+ failed: z.ZodNumber;
34
+ }, z.core.$strip>;
35
+ }, z.core.$strip>;
36
+ /**
37
+ * Vale verification output.
38
+ *
39
+ * Deliberately not squeezed into the ast-grep shape. `sg` verification is three
40
+ * layers over a rule file and its test cases; Vale verification is one question
41
+ * asked of two fixture buckets — did every `fail/` document fire, did every
42
+ * `pass/` document stay quiet. Mapping the second onto `schema`/`requirements`/
43
+ * `tests` would invent two empty layers and lose the fixture coverage, which is
44
+ * the part that catches a rule that was never really verified.
45
+ *
46
+ * `engine` is the discriminant. A consumer branches on it before reading
47
+ * anything else, and adding an engine cannot silently change the meaning of a
48
+ * field another engine already emits.
49
+ */
50
+ export declare const valeVerifyOutputSchema: z.ZodObject<{
51
+ engine: z.ZodLiteral<"vale">;
52
+ success: z.ZodBoolean;
53
+ ruleId: z.ZodString;
54
+ fixtures: z.ZodEnum<{
55
+ both: "both";
56
+ "pass-only": "pass-only";
57
+ "fail-only": "fail-only";
58
+ none: "none";
59
+ }>;
60
+ missingFailures: z.ZodArray<z.ZodString>;
61
+ unexpectedFindings: z.ZodArray<z.ZodString>;
62
+ notice: z.ZodOptional<z.ZodString>;
63
+ }, z.core.$strip>;
64
+ export declare const verifyErrorSchema: z.ZodObject<{
65
+ success: z.ZodLiteral<false>;
66
+ error: z.ZodString;
67
+ }, z.core.$strip>;
@@ -0,0 +1,22 @@
1
+ import { z } from "zod";
2
+ /** Output schema for `taskless verify --json` and `taskless test --json`. */
3
+ export declare const outputSchema: z.ZodObject<{
4
+ ok: z.ZodBoolean;
5
+ rules: z.ZodArray<z.ZodObject<{
6
+ engine: z.ZodEnum<{
7
+ sg: "sg";
8
+ vale: "vale";
9
+ runtime: "runtime";
10
+ }>;
11
+ ruleId: z.ZodString;
12
+ ok: z.ZodBoolean;
13
+ errors: z.ZodArray<z.ZodString>;
14
+ violations: z.ZodArray<z.ZodObject<{
15
+ constraintId: z.ZodString;
16
+ message: z.ZodString;
17
+ }, z.core.$strip>>;
18
+ ran: z.ZodOptional<z.ZodBoolean>;
19
+ refused: z.ZodOptional<z.ZodString>;
20
+ notice: z.ZodOptional<z.ZodString>;
21
+ }, z.core.$strip>>;
22
+ }, z.core.$strip>;