@aid-framework/cli 0.0.0 → 0.1.48
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/LICENSE +201 -0
- package/README.md +225 -0
- package/dist/.tsbuildinfo +1 -0
- package/dist/args.d.ts +37 -0
- package/dist/args.d.ts.map +1 -0
- package/dist/args.js +74 -0
- package/dist/args.js.map +1 -0
- package/dist/cli.d.ts +17 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +26 -0
- package/dist/cli.js.map +1 -0
- package/dist/commands/eval.d.ts +44 -0
- package/dist/commands/eval.d.ts.map +1 -0
- package/dist/commands/eval.js +257 -0
- package/dist/commands/eval.js.map +1 -0
- package/dist/commands/gen.d.ts +42 -0
- package/dist/commands/gen.d.ts.map +1 -0
- package/dist/commands/gen.js +138 -0
- package/dist/commands/gen.js.map +1 -0
- package/dist/commands/ingest.d.ts +44 -0
- package/dist/commands/ingest.d.ts.map +1 -0
- package/dist/commands/ingest.js +238 -0
- package/dist/commands/ingest.js.map +1 -0
- package/dist/commands/init.d.ts +38 -0
- package/dist/commands/init.d.ts.map +1 -0
- package/dist/commands/init.js +203 -0
- package/dist/commands/init.js.map +1 -0
- package/dist/commands/validate.d.ts +22 -0
- package/dist/commands/validate.d.ts.map +1 -0
- package/dist/commands/validate.js +53 -0
- package/dist/commands/validate.js.map +1 -0
- package/dist/context.d.ts +37 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +36 -0
- package/dist/context.js.map +1 -0
- package/dist/diagnostics.d.ts +42 -0
- package/dist/diagnostics.d.ts.map +1 -0
- package/dist/diagnostics.js +47 -0
- package/dist/diagnostics.js.map +1 -0
- package/dist/exit.d.ts +16 -0
- package/dist/exit.d.ts.map +1 -0
- package/dist/exit.js +15 -0
- package/dist/exit.js.map +1 -0
- package/dist/index.d.ts +42 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +29 -0
- package/dist/index.js.map +1 -0
- package/dist/main.d.ts +25 -0
- package/dist/main.d.ts.map +1 -0
- package/dist/main.js +155 -0
- package/dist/main.js.map +1 -0
- package/dist/output.d.ts +48 -0
- package/dist/output.d.ts.map +1 -0
- package/dist/output.js +50 -0
- package/dist/output.js.map +1 -0
- package/dist/paths.d.ts +21 -0
- package/dist/paths.d.ts.map +1 -0
- package/dist/paths.js +31 -0
- package/dist/paths.js.map +1 -0
- package/dist/pipeline.d.ts +74 -0
- package/dist/pipeline.d.ts.map +1 -0
- package/dist/pipeline.js +113 -0
- package/dist/pipeline.js.map +1 -0
- package/dist/python.d.ts +30 -0
- package/dist/python.d.ts.map +1 -0
- package/dist/python.js +57 -0
- package/dist/python.js.map +1 -0
- package/dist/targets.d.ts +75 -0
- package/dist/targets.d.ts.map +1 -0
- package/dist/targets.js +136 -0
- package/dist/targets.js.map +1 -0
- package/dist/usage.d.ts +20 -0
- package/dist/usage.d.ts.map +1 -0
- package/dist/usage.js +49 -0
- package/dist/usage.js.map +1 -0
- package/package.json +49 -14
package/dist/context.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Everything the CLI touches outside of itself, behind one injectable object.
|
|
3
|
+
*
|
|
4
|
+
* A CLI is mostly side effects, and side effects are what makes a command hard to test.
|
|
5
|
+
* Naming them in one place keeps every command a pure function of its arguments and
|
|
6
|
+
* this context, so a test can run a whole command against a temporary directory and
|
|
7
|
+
* assert on what it printed, what it wrote, and what it exited with -- without a
|
|
8
|
+
* subprocess, and without a mock for the parts that are not I/O.
|
|
9
|
+
*/
|
|
10
|
+
import { spawnSync } from 'node:child_process';
|
|
11
|
+
function spawnWith(command, args, options) {
|
|
12
|
+
const result = spawnSync(command, [...args], {
|
|
13
|
+
cwd: options.cwd,
|
|
14
|
+
env: { ...options.env },
|
|
15
|
+
stdio: options.stdio === 'pipe' ? ['pipe', 'pipe', 'pipe'] : 'inherit',
|
|
16
|
+
encoding: 'utf8',
|
|
17
|
+
...(options.stdin === undefined ? {} : { input: options.stdin }),
|
|
18
|
+
});
|
|
19
|
+
return {
|
|
20
|
+
status: result.status,
|
|
21
|
+
stdout: result.stdout ?? '',
|
|
22
|
+
stderr: result.stderr ?? '',
|
|
23
|
+
...(result.error === undefined ? {} : { error: result.error }),
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
/** The real world: the process streams, the process environment, and real children. */
|
|
27
|
+
export function createContext(overrides = {}) {
|
|
28
|
+
return {
|
|
29
|
+
cwd: overrides.cwd ?? process.cwd(),
|
|
30
|
+
env: overrides.env ?? process.env,
|
|
31
|
+
stdout: overrides.stdout ?? ((text) => process.stdout.write(text)),
|
|
32
|
+
stderr: overrides.stderr ?? ((text) => process.stderr.write(text)),
|
|
33
|
+
spawn: overrides.spawn ?? spawnWith,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAmC/C,SAAS,SAAS,CAAC,OAAe,EAAE,IAAuB,EAAE,OAAqB;IAChF,MAAM,MAAM,GAAG,SAAS,CAAC,OAAO,EAAE,CAAC,GAAG,IAAI,CAAC,EAAE;QAC3C,GAAG,EAAE,OAAO,CAAC,GAAG;QAChB,GAAG,EAAE,EAAE,GAAG,OAAO,CAAC,GAAG,EAAuB;QAC5C,KAAK,EAAE,OAAO,CAAC,KAAK,KAAK,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,SAAS;QACtE,QAAQ,EAAE,MAAM;QAChB,GAAG,CAAC,OAAO,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,CAAC;KACjE,CAAC,CAAC;IACH,OAAO;QACL,MAAM,EAAE,MAAM,CAAC,MAAM;QACrB,MAAM,EAAE,MAAM,CAAC,MAAM,IAAI,EAAE;QAC3B,MAAM,EAAE,MAAM,CAAC,MAAM,IAAI,EAAE;QAC3B,GAAG,CAAC,MAAM,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,CAAC;KAC/D,CAAC;AACJ,CAAC;AAED,uFAAuF;AACvF,MAAM,UAAU,aAAa,CAAC,SAAS,GAAwB,EAAE;IAC/D,OAAO;QACL,GAAG,EAAE,SAAS,CAAC,GAAG,IAAI,OAAO,CAAC,GAAG,EAAE;QACnC,GAAG,EAAE,SAAS,CAAC,GAAG,IAAI,OAAO,CAAC,GAAG;QACjC,MAAM,EAAE,SAAS,CAAC,MAAM,IAAI,CAAC,CAAC,IAAY,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAC1E,MAAM,EAAE,SAAS,CAAC,MAAM,IAAI,CAAC,CAAC,IAAY,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAC1E,KAAK,EAAE,SAAS,CAAC,KAAK,IAAI,SAAS;KACpC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Diagnostics, the one currency every layer already speaks.
|
|
3
|
+
*
|
|
4
|
+
* `@aid-framework/spec` defines the shape and the renderer, and `@aid-framework/ir` and
|
|
5
|
+
* `@aid-framework/generator-sdk` re-declare the same shape nominally with their own closed code
|
|
6
|
+
* unions. The CLI reads all of them through the widened `Diagnostic<string>` view and
|
|
7
|
+
* renders them with the spec package's renderer: it renames no code, re-ranks no
|
|
8
|
+
* severity, and re-checks nothing a gate already decided.
|
|
9
|
+
*
|
|
10
|
+
* The codes below are the ones *this* layer originates -- a file that could not be
|
|
11
|
+
* read, a target that does not exist, a Python interpreter that is not there. They
|
|
12
|
+
* follow the same `<layer>/<slug>` convention so that a reader cannot tell which layer
|
|
13
|
+
* produced a code from its shape, which is the point.
|
|
14
|
+
*/
|
|
15
|
+
import type { Diagnostic } from '@aid-framework/spec';
|
|
16
|
+
/** The shared diagnostic shape, widened over the code union. */
|
|
17
|
+
export type CliDiagnostic = Diagnostic<string>;
|
|
18
|
+
export declare const CLI_DIAGNOSTIC_CODES: {
|
|
19
|
+
readonly specUnreadable: 'cli/spec-unreadable';
|
|
20
|
+
readonly unknownTarget: 'cli/unknown-target';
|
|
21
|
+
readonly refusingToOverwrite: 'cli/refusing-to-overwrite';
|
|
22
|
+
readonly pythonMissing: 'cli/python-missing';
|
|
23
|
+
readonly suiteNotFound: 'cli/suite-not-found';
|
|
24
|
+
readonly evalModulesMissing: 'cli/eval-modules-missing';
|
|
25
|
+
readonly retrieverRequired: 'cli/retriever-required';
|
|
26
|
+
readonly retrieverConflict: 'cli/retriever-conflict';
|
|
27
|
+
readonly retrieverNotFound: 'cli/retriever-not-found';
|
|
28
|
+
readonly ingestModulesMissing: 'cli/ingest-modules-missing';
|
|
29
|
+
readonly runnerUnsupported: 'cli/runner-unsupported';
|
|
30
|
+
readonly runnerFailed: 'cli/runner-failed';
|
|
31
|
+
readonly runnerWarned: 'cli/runner-warned';
|
|
32
|
+
};
|
|
33
|
+
export type CliDiagnosticCode = (typeof CLI_DIAGNOSTIC_CODES)[keyof typeof CLI_DIAGNOSTIC_CODES];
|
|
34
|
+
export interface CliDiagnosticInit {
|
|
35
|
+
readonly code: CliDiagnosticCode;
|
|
36
|
+
readonly message: string;
|
|
37
|
+
readonly path?: readonly string[];
|
|
38
|
+
readonly hint?: string;
|
|
39
|
+
}
|
|
40
|
+
export declare function cliError(init: CliDiagnosticInit): CliDiagnostic;
|
|
41
|
+
export declare function cliWarning(init: CliDiagnosticInit): CliDiagnostic;
|
|
42
|
+
//# sourceMappingURL=diagnostics.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"diagnostics.d.ts","sourceRoot":"","sources":["../src/diagnostics.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAGtD,gEAAgE;AAChE,MAAM,MAAM,aAAa,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC;AAE/C,eAAO,MAAM,oBAAoB;aAC/B,cAAc,EAAE,qBAAqB;aACrC,aAAa,EAAE,oBAAoB;aACnC,mBAAmB,EAAE,2BAA2B;aAChD,aAAa,EAAE,oBAAoB;aACnC,aAAa,EAAE,qBAAqB;aACpC,kBAAkB,EAAE,0BAA0B;aAC9C,iBAAiB,EAAE,wBAAwB;aAC3C,iBAAiB,EAAE,wBAAwB;aAC3C,iBAAiB,EAAE,yBAAyB;aAC5C,oBAAoB,EAAE,4BAA4B;aAClD,iBAAiB,EAAE,wBAAwB;aAC3C,YAAY,EAAE,mBAAmB;aACjC,YAAY,EAAE,mBAAmB;CACzB,CAAC;AAEX,MAAM,MAAM,iBAAiB,GAAG,CAAC,OAAO,oBAAoB,CAAC,CAAC,MAAM,OAAO,oBAAoB,CAAC,CAAC;AAEjG,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,IAAI,EAAE,iBAAiB,CAAC;IACjC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,IAAI,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAClC,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,wBAAgB,QAAQ,CAAC,IAAI,EAAE,iBAAiB,GAAG,aAAa,CAO/D;AAED,wBAAgB,UAAU,CAAC,IAAI,EAAE,iBAAiB,GAAG,aAAa,CAOjE"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Diagnostics, the one currency every layer already speaks.
|
|
3
|
+
*
|
|
4
|
+
* `@aid-framework/spec` defines the shape and the renderer, and `@aid-framework/ir` and
|
|
5
|
+
* `@aid-framework/generator-sdk` re-declare the same shape nominally with their own closed code
|
|
6
|
+
* unions. The CLI reads all of them through the widened `Diagnostic<string>` view and
|
|
7
|
+
* renders them with the spec package's renderer: it renames no code, re-ranks no
|
|
8
|
+
* severity, and re-checks nothing a gate already decided.
|
|
9
|
+
*
|
|
10
|
+
* The codes below are the ones *this* layer originates -- a file that could not be
|
|
11
|
+
* read, a target that does not exist, a Python interpreter that is not there. They
|
|
12
|
+
* follow the same `<layer>/<slug>` convention so that a reader cannot tell which layer
|
|
13
|
+
* produced a code from its shape, which is the point.
|
|
14
|
+
*/
|
|
15
|
+
import { errorDiagnostic, warningDiagnostic } from '@aid-framework/spec';
|
|
16
|
+
export const CLI_DIAGNOSTIC_CODES = {
|
|
17
|
+
specUnreadable: 'cli/spec-unreadable',
|
|
18
|
+
unknownTarget: 'cli/unknown-target',
|
|
19
|
+
refusingToOverwrite: 'cli/refusing-to-overwrite',
|
|
20
|
+
pythonMissing: 'cli/python-missing',
|
|
21
|
+
suiteNotFound: 'cli/suite-not-found',
|
|
22
|
+
evalModulesMissing: 'cli/eval-modules-missing',
|
|
23
|
+
retrieverRequired: 'cli/retriever-required',
|
|
24
|
+
retrieverConflict: 'cli/retriever-conflict',
|
|
25
|
+
retrieverNotFound: 'cli/retriever-not-found',
|
|
26
|
+
ingestModulesMissing: 'cli/ingest-modules-missing',
|
|
27
|
+
runnerUnsupported: 'cli/runner-unsupported',
|
|
28
|
+
runnerFailed: 'cli/runner-failed',
|
|
29
|
+
runnerWarned: 'cli/runner-warned',
|
|
30
|
+
};
|
|
31
|
+
export function cliError(init) {
|
|
32
|
+
return errorDiagnostic({
|
|
33
|
+
code: init.code,
|
|
34
|
+
message: init.message,
|
|
35
|
+
path: init.path ?? [],
|
|
36
|
+
...(init.hint === undefined ? {} : { hint: init.hint }),
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
export function cliWarning(init) {
|
|
40
|
+
return warningDiagnostic({
|
|
41
|
+
code: init.code,
|
|
42
|
+
message: init.message,
|
|
43
|
+
path: init.path ?? [],
|
|
44
|
+
...(init.hint === undefined ? {} : { hint: init.hint }),
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=diagnostics.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"diagnostics.js","sourceRoot":"","sources":["../src/diagnostics.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAGH,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAKzE,MAAM,CAAC,MAAM,oBAAoB,GAAG;IAClC,cAAc,EAAE,qBAAqB;IACrC,aAAa,EAAE,oBAAoB;IACnC,mBAAmB,EAAE,2BAA2B;IAChD,aAAa,EAAE,oBAAoB;IACnC,aAAa,EAAE,qBAAqB;IACpC,kBAAkB,EAAE,0BAA0B;IAC9C,iBAAiB,EAAE,wBAAwB;IAC3C,iBAAiB,EAAE,wBAAwB;IAC3C,iBAAiB,EAAE,yBAAyB;IAC5C,oBAAoB,EAAE,4BAA4B;IAClD,iBAAiB,EAAE,wBAAwB;IAC3C,YAAY,EAAE,mBAAmB;IACjC,YAAY,EAAE,mBAAmB;CACzB,CAAC;AAWX,MAAM,UAAU,QAAQ,CAAC,IAAuB;IAC9C,OAAO,eAAe,CAAC;QACrB,IAAI,EAAE,IAAI,CAAC,IAAI;QACf,OAAO,EAAE,IAAI,CAAC,OAAO;QACrB,IAAI,EAAE,IAAI,CAAC,IAAI,IAAI,EAAE;QACrB,GAAG,CAAC,IAAI,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC;KACxD,CAAC,CAAC;AACL,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,IAAuB;IAChD,OAAO,iBAAiB,CAAC;QACvB,IAAI,EAAE,IAAI,CAAC,IAAI;QACf,OAAO,EAAE,IAAI,CAAC,OAAO;QACrB,IAAI,EAAE,IAAI,CAAC,IAAI,IAAI,EAAE;QACrB,GAAG,CAAC,IAAI,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC;KACxD,CAAC,CAAC;AACL,CAAC"}
|
package/dist/exit.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The CLI's exit-code taxonomy, which is a contract with CI rather than a convention.
|
|
3
|
+
*
|
|
4
|
+
* `0` means the command finished *and* the project is in the shape the command asked
|
|
5
|
+
* for; `1` means the command ran but the spec, a gate, the target's compiler or the
|
|
6
|
+
* working tree rejected it; `2` means the command line itself was wrong, or the CLI
|
|
7
|
+
* could not get far enough to judge the project at all. Nothing else is ever returned,
|
|
8
|
+
* and no command maps two different outcomes onto the same code.
|
|
9
|
+
*/
|
|
10
|
+
export declare const EXIT_OK = 0;
|
|
11
|
+
/** The spec, the gates, the target's plan, or the working tree said no. */
|
|
12
|
+
export declare const EXIT_FAILURE = 1;
|
|
13
|
+
/** The invocation was wrong, or the CLI hit an internal failure. */
|
|
14
|
+
export declare const EXIT_USAGE = 2;
|
|
15
|
+
export type ExitCode = typeof EXIT_OK | typeof EXIT_FAILURE | typeof EXIT_USAGE;
|
|
16
|
+
//# sourceMappingURL=exit.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exit.d.ts","sourceRoot":"","sources":["../src/exit.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,eAAO,MAAM,OAAO,IAAI,CAAC;AAEzB,2EAA2E;AAC3E,eAAO,MAAM,YAAY,IAAI,CAAC;AAE9B,oEAAoE;AACpE,eAAO,MAAM,UAAU,IAAI,CAAC;AAE5B,MAAM,MAAM,QAAQ,GAAG,OAAO,OAAO,GAAG,OAAO,YAAY,GAAG,OAAO,UAAU,CAAC"}
|
package/dist/exit.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The CLI's exit-code taxonomy, which is a contract with CI rather than a convention.
|
|
3
|
+
*
|
|
4
|
+
* `0` means the command finished *and* the project is in the shape the command asked
|
|
5
|
+
* for; `1` means the command ran but the spec, a gate, the target's compiler or the
|
|
6
|
+
* working tree rejected it; `2` means the command line itself was wrong, or the CLI
|
|
7
|
+
* could not get far enough to judge the project at all. Nothing else is ever returned,
|
|
8
|
+
* and no command maps two different outcomes onto the same code.
|
|
9
|
+
*/
|
|
10
|
+
export const EXIT_OK = 0;
|
|
11
|
+
/** The spec, the gates, the target's plan, or the working tree said no. */
|
|
12
|
+
export const EXIT_FAILURE = 1;
|
|
13
|
+
/** The invocation was wrong, or the CLI hit an internal failure. */
|
|
14
|
+
export const EXIT_USAGE = 2;
|
|
15
|
+
//# sourceMappingURL=exit.js.map
|
package/dist/exit.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exit.js","sourceRoot":"","sources":["../src/exit.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,CAAC;AAEzB,2EAA2E;AAC3E,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,CAAC;AAE9B,oEAAoE;AACpE,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@aid-framework/cli` - the `aid` command: init, validate, gen, ingest and eval.
|
|
3
|
+
*
|
|
4
|
+
* The CLI is glue. Every judgement it reports -- whether a spec parses, what the IR is,
|
|
5
|
+
* what a target can emit, which generated file was hand-edited, whether an eval regressed
|
|
6
|
+
* -- is made by a package below it, and this layer's job is to route arguments into those
|
|
7
|
+
* packages and their answers back out as text, JSON and an exit code. It reimplements no
|
|
8
|
+
* gate, no hash and no drift rule, because a second implementation of a rule is a defect:
|
|
9
|
+
* the two will disagree, and only one of them will be right.
|
|
10
|
+
*
|
|
11
|
+
* The layering is `spec <- ir <- generator-sdk <- generators <- cli`.
|
|
12
|
+
*/
|
|
13
|
+
export type { FlagSpec, ParsedArguments, ParseOutcome } from './args.js';
|
|
14
|
+
export { booleanFlag, JSON_FLAG, parseArguments, valueFlag } from './args.js';
|
|
15
|
+
export type { EvalOptions } from './commands/eval.js';
|
|
16
|
+
export { evaluate } from './commands/eval.js';
|
|
17
|
+
export type { GenerateOptions, GenerateSuccess } from './commands/gen.js';
|
|
18
|
+
export { generate } from './commands/gen.js';
|
|
19
|
+
export type { IngestOptions } from './commands/ingest.js';
|
|
20
|
+
export { ingest } from './commands/ingest.js';
|
|
21
|
+
export type { InitOptions } from './commands/init.js';
|
|
22
|
+
export { init, projectNameFor, starterSpec } from './commands/init.js';
|
|
23
|
+
export type { ValidateOptions } from './commands/validate.js';
|
|
24
|
+
export { validate } from './commands/validate.js';
|
|
25
|
+
export type { CliContext, Spawn, SpawnOptions, SpawnResult } from './context.js';
|
|
26
|
+
export { createContext } from './context.js';
|
|
27
|
+
export type { CliDiagnostic, CliDiagnosticCode, CliDiagnosticInit } from './diagnostics.js';
|
|
28
|
+
export { CLI_DIAGNOSTIC_CODES, cliError, cliWarning } from './diagnostics.js';
|
|
29
|
+
export type { ExitCode } from './exit.js';
|
|
30
|
+
export { EXIT_FAILURE, EXIT_OK, EXIT_USAGE } from './exit.js';
|
|
31
|
+
export { COMMANDS, run } from './main.js';
|
|
32
|
+
export type { CommandOutcome, OutcomeInit } from './output.js';
|
|
33
|
+
export { emit, outcome } from './output.js';
|
|
34
|
+
export { absolutePath, parentPath } from './paths.js';
|
|
35
|
+
export type { Compiled, CompileOutcome, Failed, Lowered, LowerOutcome, ManifestOutcome, ReadManifest, ReadSpec, } from './pipeline.js';
|
|
36
|
+
export { compile, lowerSpec, provenanceFor, readManifest, readSpec } from './pipeline.js';
|
|
37
|
+
export { discoverInterpreter, INTERPRETERS, interpreterCommand, invoke } from './python.js';
|
|
38
|
+
export type { Target } from './targets.js';
|
|
39
|
+
export { DEFAULT_SPEC_PATH, DEFAULT_TARGET, resolveTarget, TARGETS, targetCapabilities, targetNames, unknownTargetDiagnostic, } from './targets.js';
|
|
40
|
+
export type { CommandSpec } from './usage.js';
|
|
41
|
+
export { commandUsage, globalUsage } from './usage.js';
|
|
42
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,YAAY,EAAE,QAAQ,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzE,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAC9E,YAAY,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,YAAY,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAC1E,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,YAAY,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC9C,YAAY,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,IAAI,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACvE,YAAY,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAClD,YAAY,EAAE,UAAU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AC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@aid-framework/cli` - the `aid` command: init, validate, gen, ingest and eval.
|
|
3
|
+
*
|
|
4
|
+
* The CLI is glue. Every judgement it reports -- whether a spec parses, what the IR is,
|
|
5
|
+
* what a target can emit, which generated file was hand-edited, whether an eval regressed
|
|
6
|
+
* -- is made by a package below it, and this layer's job is to route arguments into those
|
|
7
|
+
* packages and their answers back out as text, JSON and an exit code. It reimplements no
|
|
8
|
+
* gate, no hash and no drift rule, because a second implementation of a rule is a defect:
|
|
9
|
+
* the two will disagree, and only one of them will be right.
|
|
10
|
+
*
|
|
11
|
+
* The layering is `spec <- ir <- generator-sdk <- generators <- cli`.
|
|
12
|
+
*/
|
|
13
|
+
export { booleanFlag, JSON_FLAG, parseArguments, valueFlag } from './args.js';
|
|
14
|
+
export { evaluate } from './commands/eval.js';
|
|
15
|
+
export { generate } from './commands/gen.js';
|
|
16
|
+
export { ingest } from './commands/ingest.js';
|
|
17
|
+
export { init, projectNameFor, starterSpec } from './commands/init.js';
|
|
18
|
+
export { validate } from './commands/validate.js';
|
|
19
|
+
export { createContext } from './context.js';
|
|
20
|
+
export { CLI_DIAGNOSTIC_CODES, cliError, cliWarning } from './diagnostics.js';
|
|
21
|
+
export { EXIT_FAILURE, EXIT_OK, EXIT_USAGE } from './exit.js';
|
|
22
|
+
export { COMMANDS, run } from './main.js';
|
|
23
|
+
export { emit, outcome } from './output.js';
|
|
24
|
+
export { absolutePath, parentPath } from './paths.js';
|
|
25
|
+
export { compile, lowerSpec, provenanceFor, readManifest, readSpec } from './pipeline.js';
|
|
26
|
+
export { discoverInterpreter, INTERPRETERS, interpreterCommand, invoke } from './python.js';
|
|
27
|
+
export { DEFAULT_SPEC_PATH, DEFAULT_TARGET, resolveTarget, TARGETS, targetCapabilities, targetNames, unknownTargetDiagnostic, } from './targets.js';
|
|
28
|
+
export { commandUsage, globalUsage } from './usage.js';
|
|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,YAAY,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/main.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The dispatcher: argv in, exit code out.
|
|
3
|
+
*
|
|
4
|
+
* It is a pure function of the argv and a `CliContext`, so the whole CLI can be driven in
|
|
5
|
+
* a test by calling `run([...], context)` against a temporary directory and asserting on
|
|
6
|
+
* the captured streams -- no subprocess, no `process.exit`, no spawning the built binary
|
|
7
|
+
* to find out what a flag does.
|
|
8
|
+
*
|
|
9
|
+
* `run` decides only what is genuinely global: which command, whether the invocation was
|
|
10
|
+
* well formed, whether help was asked for, and how an unforeseen exception maps onto an
|
|
11
|
+
* exit code. Everything else belongs to the command, which is why each entry in the table
|
|
12
|
+
* below is a two-line adapter and not a flag handler.
|
|
13
|
+
*/
|
|
14
|
+
import type { ParsedArguments } from './args.js';
|
|
15
|
+
import type { CliContext } from './context.js';
|
|
16
|
+
import type { ExitCode } from './exit.js';
|
|
17
|
+
import type { CommandOutcome } from './output.js';
|
|
18
|
+
import type { CommandSpec } from './usage.js';
|
|
19
|
+
interface Command extends CommandSpec {
|
|
20
|
+
readonly run: (context: CliContext, args: ParsedArguments) => CommandOutcome;
|
|
21
|
+
}
|
|
22
|
+
export declare const COMMANDS: readonly Command[];
|
|
23
|
+
export declare function run(argv: readonly string[], context: CliContext): ExitCode;
|
|
24
|
+
export {};
|
|
25
|
+
//# sourceMappingURL=main.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAOjD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAE1C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAGlD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAG9C,UAAU,OAAQ,SAAQ,WAAW;IACnC,QAAQ,CAAC,GAAG,EAAE,CAAC,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,eAAe,KAAK,cAAc,CAAC;CAC9E;AAQD,eAAO,MAAM,QAAQ,EAAE,SAAS,OAAO,EAoFtC,CAAC;AA0BF,wBAAgB,GAAG,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,EAAE,OAAO,EAAE,UAAU,GAAG,QAAQ,CAuC1E"}
|
package/dist/main.js
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The dispatcher: argv in, exit code out.
|
|
3
|
+
*
|
|
4
|
+
* It is a pure function of the argv and a `CliContext`, so the whole CLI can be driven in
|
|
5
|
+
* a test by calling `run([...], context)` against a temporary directory and asserting on
|
|
6
|
+
* the captured streams -- no subprocess, no `process.exit`, no spawning the built binary
|
|
7
|
+
* to find out what a flag does.
|
|
8
|
+
*
|
|
9
|
+
* `run` decides only what is genuinely global: which command, whether the invocation was
|
|
10
|
+
* well formed, whether help was asked for, and how an unforeseen exception maps onto an
|
|
11
|
+
* exit code. Everything else belongs to the command, which is why each entry in the table
|
|
12
|
+
* below is a two-line adapter and not a flag handler.
|
|
13
|
+
*/
|
|
14
|
+
import { booleanFlag, JSON_FLAG, parseArguments, valueFlag } from './args.js';
|
|
15
|
+
import { evaluate } from './commands/eval.js';
|
|
16
|
+
import { generate } from './commands/gen.js';
|
|
17
|
+
import { ingest } from './commands/ingest.js';
|
|
18
|
+
import { init } from './commands/init.js';
|
|
19
|
+
import { validate } from './commands/validate.js';
|
|
20
|
+
import { EXIT_OK, EXIT_USAGE } from './exit.js';
|
|
21
|
+
import { emit } from './output.js';
|
|
22
|
+
import { targetNames } from './targets.js';
|
|
23
|
+
import { commandUsage, globalUsage } from './usage.js';
|
|
24
|
+
const TARGET_FLAG = valueFlag('target', 'name', `generator target; one of ${targetNames().join(', ')}`);
|
|
25
|
+
export const COMMANDS = [
|
|
26
|
+
{
|
|
27
|
+
name: 'init',
|
|
28
|
+
summary: 'scaffold a project: a starter spec and a README',
|
|
29
|
+
usage: 'init [dir] [--from <spec>] [--target <name>] [--force] [--gen]',
|
|
30
|
+
flags: [
|
|
31
|
+
valueFlag('from', 'spec', 'import an existing spec instead of writing the starter'),
|
|
32
|
+
TARGET_FLAG,
|
|
33
|
+
booleanFlag('force', 'replace a spec or README that is already there'),
|
|
34
|
+
booleanFlag('gen', 'generate immediately after scaffolding'),
|
|
35
|
+
JSON_FLAG,
|
|
36
|
+
],
|
|
37
|
+
run: (context, args) => init(context, {
|
|
38
|
+
dir: args.positionals[0],
|
|
39
|
+
from: args.values.get('from'),
|
|
40
|
+
target: args.values.get('target'),
|
|
41
|
+
force: args.booleans.has('force'),
|
|
42
|
+
gen: args.booleans.has('gen'),
|
|
43
|
+
}),
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
name: 'validate',
|
|
47
|
+
summary: 'parse the spec, build the IR, and run every build-time gate',
|
|
48
|
+
usage: 'validate [spec]',
|
|
49
|
+
flags: [JSON_FLAG],
|
|
50
|
+
run: (context, args) => validate(context, { spec: args.positionals[0] }),
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
name: 'gen',
|
|
54
|
+
summary: 'compile the spec and reconcile the tree with it',
|
|
55
|
+
usage: 'gen [spec] [--target <name>] [--dry-run] [--force]',
|
|
56
|
+
flags: [
|
|
57
|
+
TARGET_FLAG,
|
|
58
|
+
booleanFlag('dry-run', 'report what would change, and write nothing'),
|
|
59
|
+
booleanFlag('force', 'overwrite generated files that were edited by hand'),
|
|
60
|
+
JSON_FLAG,
|
|
61
|
+
],
|
|
62
|
+
run: (context, args) => generate(context, {
|
|
63
|
+
spec: args.positionals[0],
|
|
64
|
+
target: args.values.get('target'),
|
|
65
|
+
dryRun: args.booleans.has('dry-run'),
|
|
66
|
+
force: args.booleans.has('force'),
|
|
67
|
+
}),
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
name: 'ingest',
|
|
71
|
+
summary: 'index a retriever corpus into the store the spec declares',
|
|
72
|
+
usage: 'ingest [spec] [--target <name>] [--retriever <id> | --all] [--dry-run]',
|
|
73
|
+
flags: [
|
|
74
|
+
valueFlag('retriever', 'id', 'ingest one declared retriever, by the id the spec used'),
|
|
75
|
+
booleanFlag('all', 'ingest every retriever the spec declares'),
|
|
76
|
+
booleanFlag('dry-run', 'report what a run would write, and write nothing'),
|
|
77
|
+
TARGET_FLAG,
|
|
78
|
+
JSON_FLAG,
|
|
79
|
+
],
|
|
80
|
+
run: (context, args) => ingest(context, {
|
|
81
|
+
spec: args.positionals[0],
|
|
82
|
+
target: args.values.get('target'),
|
|
83
|
+
retriever: args.values.get('retriever'),
|
|
84
|
+
all: args.booleans.has('all'),
|
|
85
|
+
dryRun: args.booleans.has('dry-run'),
|
|
86
|
+
}),
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
name: 'eval',
|
|
90
|
+
summary: 'run the eval gate, or record the baseline it measures against',
|
|
91
|
+
usage: 'eval [spec] [--target <name>] [--suite <id>] [--baseline]',
|
|
92
|
+
flags: [
|
|
93
|
+
valueFlag('suite', 'id', 'run one eval instead of all of them'),
|
|
94
|
+
TARGET_FLAG,
|
|
95
|
+
booleanFlag('baseline', 'record a fresh baseline instead of gating'),
|
|
96
|
+
JSON_FLAG,
|
|
97
|
+
],
|
|
98
|
+
run: (context, args) => evaluate(context, {
|
|
99
|
+
spec: args.positionals[0],
|
|
100
|
+
target: args.values.get('target'),
|
|
101
|
+
suite: args.values.get('suite'),
|
|
102
|
+
baseline: args.booleans.has('baseline'),
|
|
103
|
+
}),
|
|
104
|
+
},
|
|
105
|
+
];
|
|
106
|
+
function usageError(context, message, usage) {
|
|
107
|
+
context.stderr(`aid: ${message}\n\n${usage ?? globalUsage(COMMANDS)}`);
|
|
108
|
+
return EXIT_USAGE;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Map an unexpected throw onto exit 2. A command that crashed has not judged the project,
|
|
112
|
+
* so it must not report `1` -- that code means "the project is wrong", and a crash
|
|
113
|
+
* claiming it would send a reader looking for a spec problem that does not exist.
|
|
114
|
+
*/
|
|
115
|
+
function internalError(context, json, command, error) {
|
|
116
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
117
|
+
context.stderr(`aid: internal error in \`${command}\`: ${message}\n`);
|
|
118
|
+
if (json) {
|
|
119
|
+
context.stdout(`${JSON.stringify({ command, ok: false, diagnostics: [] }, null, 2)}\n`);
|
|
120
|
+
}
|
|
121
|
+
return EXIT_USAGE;
|
|
122
|
+
}
|
|
123
|
+
export function run(argv, context) {
|
|
124
|
+
const [name, ...rest] = argv;
|
|
125
|
+
if (name === undefined || name === '--help' || name === '-h' || name === 'help') {
|
|
126
|
+
context.stdout(globalUsage(COMMANDS));
|
|
127
|
+
// No command at all is a usage error; explicitly asking for help is not.
|
|
128
|
+
return name === undefined ? EXIT_USAGE : EXIT_OK;
|
|
129
|
+
}
|
|
130
|
+
const command = COMMANDS.find((candidate) => candidate.name === name);
|
|
131
|
+
if (command === undefined) {
|
|
132
|
+
return usageError(context, `unknown command \`${name}\``);
|
|
133
|
+
}
|
|
134
|
+
const parsed = parseArguments(rest, command.flags);
|
|
135
|
+
if (!parsed.ok) {
|
|
136
|
+
return usageError(context, parsed.message, commandUsage(command));
|
|
137
|
+
}
|
|
138
|
+
if (parsed.args.help) {
|
|
139
|
+
context.stdout(commandUsage(command));
|
|
140
|
+
return EXIT_OK;
|
|
141
|
+
}
|
|
142
|
+
// Every command takes at most one positional (a spec, or the directory to scaffold
|
|
143
|
+
// into), so the arity rule lives here rather than four times in four commands.
|
|
144
|
+
if (parsed.args.positionals.length > 1) {
|
|
145
|
+
return usageError(context, `\`aid ${command.name}\` takes at most one path, got ${parsed.args.positionals.length}`, commandUsage(command));
|
|
146
|
+
}
|
|
147
|
+
const json = parsed.args.booleans.has('json');
|
|
148
|
+
try {
|
|
149
|
+
return emit(context, json, command.run(context, parsed.args));
|
|
150
|
+
}
|
|
151
|
+
catch (error) {
|
|
152
|
+
return internalError(context, json, command.name, error);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
//# sourceMappingURL=main.js.map
|
package/dist/main.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"main.js","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAGH,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAC9E,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC9C,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAGlD,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAEhD,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AACnC,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3C,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAMvD,MAAM,WAAW,GAAG,SAAS,CAC3B,QAAQ,EACR,MAAM,EACN,4BAA4B,WAAW,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CACvD,CAAC;AAEF,MAAM,CAAC,MAAM,QAAQ,GAAuB;IAC1C;QACE,IAAI,EAAE,MAAM;QACZ,OAAO,EAAE,iDAAiD;QAC1D,KAAK,EAAE,gEAAgE;QACvE,KAAK,EAAE;YACL,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,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AO,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;IAChE,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,aAAa,CAAC,OAAO,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IAC3D,CAAC;AACH,CAAC"}
|
package/dist/output.d.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The command's whole result: what to print, what to embed in `--json`, and what to
|
|
3
|
+
* exit with.
|
|
4
|
+
*
|
|
5
|
+
* Commands return this instead of printing and exiting themselves, so that a command
|
|
6
|
+
* can be asserted on directly and so that `init --gen` can run the generation pipeline
|
|
7
|
+
* and fold its outcome into its own. `ok` is derived from the exit code rather than
|
|
8
|
+
* passed alongside it, because two fields that can disagree eventually will.
|
|
9
|
+
*/
|
|
10
|
+
import type { CliContext } from './context.js';
|
|
11
|
+
import type { CliDiagnostic } from './diagnostics.js';
|
|
12
|
+
import type { ExitCode } from './exit.js';
|
|
13
|
+
export interface CommandOutcome {
|
|
14
|
+
readonly exitCode: ExitCode;
|
|
15
|
+
/** The `--json` document. */
|
|
16
|
+
readonly report: Record<string, unknown>;
|
|
17
|
+
readonly diagnostics: readonly CliDiagnostic[];
|
|
18
|
+
/** The human rendering on stdout. Empty when there is nothing to say. */
|
|
19
|
+
readonly text: string;
|
|
20
|
+
/**
|
|
21
|
+
* Text a subprocess wrote to its own stderr, carried through to the CLI's stderr.
|
|
22
|
+
*
|
|
23
|
+
* `aid eval` is the only user. It cannot be folded into {@link text}: `--json` swaps
|
|
24
|
+
* stdout for a single JSON document, and an eval that explains on stderr why it could
|
|
25
|
+
* not measure something would have that explanation dropped by the one mode a machine
|
|
26
|
+
* reads.
|
|
27
|
+
*/
|
|
28
|
+
readonly stderr?: string;
|
|
29
|
+
}
|
|
30
|
+
export interface OutcomeInit {
|
|
31
|
+
readonly command: string;
|
|
32
|
+
readonly exitCode: ExitCode;
|
|
33
|
+
readonly fields?: Record<string, unknown>;
|
|
34
|
+
readonly diagnostics?: readonly CliDiagnostic[];
|
|
35
|
+
readonly text?: string;
|
|
36
|
+
readonly stderr?: string;
|
|
37
|
+
}
|
|
38
|
+
export declare function outcome(init: OutcomeInit): CommandOutcome;
|
|
39
|
+
/**
|
|
40
|
+
* Print an outcome and hand back its exit code.
|
|
41
|
+
*
|
|
42
|
+
* Diagnostics go to stderr in both modes. In `--json` mode stdout carries exactly one
|
|
43
|
+
* JSON document and nothing else, so that `aid ... --json | jq` is always well formed;
|
|
44
|
+
* the diagnostics are in that document *and* on stderr, which is what a caller piping
|
|
45
|
+
* stdout wants and what a human watching a terminal wants.
|
|
46
|
+
*/
|
|
47
|
+
export declare function emit(context: CliContext, json: boolean, command: CommandOutcome): ExitCode;
|
|
48
|
+
//# sourceMappingURL=output.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"output.d.ts","sourceRoot":"","sources":["../src/output.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAG1C,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAC5B,6BAA6B;IAC7B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACzC,QAAQ,CAAC,WAAW,EAAE,SAAS,aAAa,EAAE,CAAC;IAC/C,yEAAyE;IACzE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB;;;;;;;OAOG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAC5B,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC1C,QAAQ,CAAC,WAAW,CAAC,EAAE,SAAS,aAAa,EAAE,CAAC;IAChD,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,wBAAgB,OAAO,CAAC,IAAI,EAAE,WAAW,GAAG,cAAc,CAczD;AAED;;;;;;;GAOG;AACH,wBAAgB,IAAI,CAAC,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,cAAc,GAAG,QAAQ,CAa1F"}
|
package/dist/output.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The command's whole result: what to print, what to embed in `--json`, and what to
|
|
3
|
+
* exit with.
|
|
4
|
+
*
|
|
5
|
+
* Commands return this instead of printing and exiting themselves, so that a command
|
|
6
|
+
* can be asserted on directly and so that `init --gen` can run the generation pipeline
|
|
7
|
+
* and fold its outcome into its own. `ok` is derived from the exit code rather than
|
|
8
|
+
* passed alongside it, because two fields that can disagree eventually will.
|
|
9
|
+
*/
|
|
10
|
+
import { formatDiagnostics } from '@aid-framework/spec';
|
|
11
|
+
import { EXIT_OK } from './exit.js';
|
|
12
|
+
export function outcome(init) {
|
|
13
|
+
const diagnostics = init.diagnostics ?? [];
|
|
14
|
+
return {
|
|
15
|
+
exitCode: init.exitCode,
|
|
16
|
+
diagnostics,
|
|
17
|
+
text: init.text ?? '',
|
|
18
|
+
...(init.stderr === undefined ? {} : { stderr: init.stderr }),
|
|
19
|
+
report: {
|
|
20
|
+
command: init.command,
|
|
21
|
+
ok: init.exitCode === EXIT_OK,
|
|
22
|
+
...init.fields,
|
|
23
|
+
diagnostics,
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Print an outcome and hand back its exit code.
|
|
29
|
+
*
|
|
30
|
+
* Diagnostics go to stderr in both modes. In `--json` mode stdout carries exactly one
|
|
31
|
+
* JSON document and nothing else, so that `aid ... --json | jq` is always well formed;
|
|
32
|
+
* the diagnostics are in that document *and* on stderr, which is what a caller piping
|
|
33
|
+
* stdout wants and what a human watching a terminal wants.
|
|
34
|
+
*/
|
|
35
|
+
export function emit(context, json, command) {
|
|
36
|
+
if (json) {
|
|
37
|
+
context.stdout(`${JSON.stringify(command.report, null, 2)}\n`);
|
|
38
|
+
}
|
|
39
|
+
else if (command.text !== '') {
|
|
40
|
+
context.stdout(command.text.endsWith('\n') ? command.text : `${command.text}\n`);
|
|
41
|
+
}
|
|
42
|
+
if (command.stderr !== undefined && command.stderr !== '') {
|
|
43
|
+
context.stderr(command.stderr.endsWith('\n') ? command.stderr : `${command.stderr}\n`);
|
|
44
|
+
}
|
|
45
|
+
if (command.diagnostics.length > 0) {
|
|
46
|
+
context.stderr(formatDiagnostics(command.diagnostics));
|
|
47
|
+
}
|
|
48
|
+
return command.exitCode;
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=output.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"output.js","sourceRoot":"","sources":["../src/output.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAIxD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AA6BpC,MAAM,UAAU,OAAO,CAAC,IAAiB;IACvC,MAAM,WAAW,GAAG,IAAI,CAAC,WAAW,IAAI,EAAE,CAAC;IAC3C,OAAO;QACL,QAAQ,EAAE,IAAI,CAAC,QAAQ;QACvB,WAAW;QACX,IAAI,EAAE,IAAI,CAAC,IAAI,IAAI,EAAE;QACrB,GAAG,CAAC,IAAI,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CA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/dist/paths.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The repository-relative POSIX paths every package in this repository speaks, and the
|
|
3
|
+
* one place they become operating-system paths.
|
|
4
|
+
*
|
|
5
|
+
* A plan's paths, a manifest's records and a generator's path helpers are all
|
|
6
|
+
* `app/generated/...`, joined with `/`. They are converted at the filesystem boundary
|
|
7
|
+
* and nowhere else, so no comparison in the CLI can be defeated by a separator.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* The absolute path `posixPath` names under `root`.
|
|
11
|
+
*
|
|
12
|
+
* An absolute path is taken as it is. `aid init --from C:\specs\app.spec.yaml` and
|
|
13
|
+
* `aid validate /srv/app/app.spec.yaml` are ordinary invocations, and joining an absolute
|
|
14
|
+
* path onto the working directory does not fail loudly -- it produces a well-formed path
|
|
15
|
+
* to a file that cannot exist, so the caller reads a "no such file" for a file that is
|
|
16
|
+
* right there.
|
|
17
|
+
*/
|
|
18
|
+
export declare function absolutePath(root: string, posixPath: string): string;
|
|
19
|
+
/** The parent of a repository-relative POSIX path, or `''` for a top-level one. */
|
|
20
|
+
export declare function parentPath(posixPath: string): string;
|
|
21
|
+
//# sourceMappingURL=paths.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paths.d.ts","sourceRoot":"","sources":["../src/paths.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH;;;;;;;;GAQG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CAIpE;AAED,mFAAmF;AACnF,wBAAgB,UAAU,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAGpD"}
|
package/dist/paths.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The repository-relative POSIX paths every package in this repository speaks, and the
|
|
3
|
+
* one place they become operating-system paths.
|
|
4
|
+
*
|
|
5
|
+
* A plan's paths, a manifest's records and a generator's path helpers are all
|
|
6
|
+
* `app/generated/...`, joined with `/`. They are converted at the filesystem boundary
|
|
7
|
+
* and nowhere else, so no comparison in the CLI can be defeated by a separator.
|
|
8
|
+
*/
|
|
9
|
+
import { isAbsolute, join, resolve } from 'node:path';
|
|
10
|
+
/**
|
|
11
|
+
* The absolute path `posixPath` names under `root`.
|
|
12
|
+
*
|
|
13
|
+
* An absolute path is taken as it is. `aid init --from C:\specs\app.spec.yaml` and
|
|
14
|
+
* `aid validate /srv/app/app.spec.yaml` are ordinary invocations, and joining an absolute
|
|
15
|
+
* path onto the working directory does not fail loudly -- it produces a well-formed path
|
|
16
|
+
* to a file that cannot exist, so the caller reads a "no such file" for a file that is
|
|
17
|
+
* right there.
|
|
18
|
+
*/
|
|
19
|
+
export function absolutePath(root, posixPath) {
|
|
20
|
+
if (posixPath === '')
|
|
21
|
+
return root;
|
|
22
|
+
if (isAbsolute(posixPath))
|
|
23
|
+
return resolve(posixPath);
|
|
24
|
+
return join(root, ...posixPath.split('/'));
|
|
25
|
+
}
|
|
26
|
+
/** The parent of a repository-relative POSIX path, or `''` for a top-level one. */
|
|
27
|
+
export function parentPath(posixPath) {
|
|
28
|
+
const index = posixPath.lastIndexOf('/');
|
|
29
|
+
return index === -1 ? '' : posixPath.slice(0, index);
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=paths.js.map
|