@cosyte/cli 0.0.1 → 0.0.3

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/dist/index.d.cts CHANGED
@@ -3,23 +3,30 @@ export { r as readFileBytes, a as readStreamBytes } from './io-B2EobRzC.cjs';
3
3
  import 'node:stream';
4
4
 
5
5
  /**
6
- * The CLI version string, synced with `package.json#version` on release by the Changesets `version`
7
- * script. Kept in its own module so both the programmatic entry point and the dispatcher share one
8
- * source of truth.
6
+ * The CLI version string, synced with `package.json#version` on release by `scripts/sync-version.mjs`,
7
+ * which the `version` script runs immediately after `changeset version`. Kept in its own module so
8
+ * both the programmatic entry point and the dispatcher share one source of truth.
9
+ *
10
+ * The declaration below is rewritten by that script and is matched at column 0, annotation included.
11
+ * Renaming it or reflowing it makes the script exit non-zero rather than silently no-op; the shape is
12
+ * pinned by `test/sanity.test.ts`, and the value is compared against `package.json` there too.
9
13
  *
10
14
  * @packageDocumentation
11
15
  */
12
16
  /**
13
17
  * The `@cosyte/cli` version. On the uniform `v0.0.x-until-first-alpha` ladder.
14
18
  *
19
+ * Read by `cosyte --version` and by the MCP server's advertised `SERVER_INFO`, so it is a
20
+ * user-visible surface on both front doors, not merely an export.
21
+ *
15
22
  * @example
16
23
  * ```ts
17
24
  * import { VERSION } from "@cosyte/cli";
18
25
  *
19
- * typeof VERSION; // => "string"
26
+ * console.log(`cosyte ${VERSION}`);
20
27
  * ```
21
28
  */
22
- declare const VERSION = "0.0.0";
29
+ declare const VERSION: string;
23
30
 
24
31
  /**
25
32
  * The `cosyte` CLI **exit-code contract**: a designed, documented surface that CI pipelines and
@@ -36,7 +43,7 @@ declare const VERSION = "0.0.0";
36
43
  * | `2` | `USAGE` | usage error: unknown command, bad flag, missing argument (EX_USAGE) |
37
44
  * | `65` | `DATAERR` | data error: input could not be parsed / format not detected (EX_DATAERR) |
38
45
  * | `66` | `NOINPUT` | no input: the file does not exist or is unreadable (EX_NOINPUT) |
39
- * | `69` | `UNAVAILABLE` | a required capability is not yet available: e.g. `redact` before `@cosyte/deid` ships (EX_UNAVAILABLE) |
46
+ * | `69` | `UNAVAILABLE` | a required capability is not yet available: e.g. `redact` before `@cosyte/deid` is wired (EX_UNAVAILABLE) |
40
47
  * | `70` | `SOFTWARE` | internal error: an unexpected exception, i.e. a bug (EX_SOFTWARE) |
41
48
  *
42
49
  * The load-bearing `validate` rule: a **parseable-but-invalid** message is exit `1`, never exit `0`.
@@ -70,7 +77,7 @@ declare const EXIT: {
70
77
  readonly DATAERR: 65;
71
78
  /** No input: the named file does not exist or is unreadable (`EX_NOINPUT`). */
72
79
  readonly NOINPUT: 66;
73
- /** Unavailable: a required capability is not yet built (e.g. `redact` before `@cosyte/deid`), a
80
+ /** Unavailable: a required capability is not yet wired (e.g. `redact` before `@cosyte/deid`), a
74
81
  * distinct non-zero signal that is never a fake success (`EX_UNAVAILABLE`). */
75
82
  readonly UNAVAILABLE: 69;
76
83
  /** Internal error: an unexpected exception (a bug), distinct from a handled bad input (`EX_SOFTWARE`). */
@@ -161,8 +168,8 @@ declare const CLI_CODES: {
161
168
  /** The BYO ConceptMap supplied to `map-codes` is not valid JSON or not a loadable FHIR ConceptMap.
162
169
  * Names the stable terminology-loader code, never the map's bytes. Exit `65`. */
163
170
  readonly CLI_MAP_INVALID: "CLI_MAP_INVALID";
164
- /** A command whose ground-layer library is not yet built (e.g. `redact` before `@cosyte/deid`
165
- * ships). Never a fake success: a distinct, value-free "unavailable" signal. Exit `69`. */
171
+ /** A command whose ground-layer library is not yet wired (e.g. `redact` before `@cosyte/deid` is
172
+ * wired). Never a fake success: a distinct, value-free "unavailable" signal. Exit `69`. */
166
173
  readonly CLI_NOT_IMPLEMENTED: "CLI_NOT_IMPLEMENTED";
167
174
  /** An unexpected internal error (a bug). Exit `70`. */
168
175
  readonly CLI_INTERNAL: "CLI_INTERNAL";
@@ -616,6 +623,33 @@ declare function valueFreeLocator(pos: unknown): string;
616
623
  * ```
617
624
  */
618
625
  declare function loadOptional<T>(format: CosyteFormat, load: () => Promise<T>): Promise<T>;
626
+ /**
627
+ * The same graceful-degradation path as {@link loadOptional}, keyed on a **package name** rather than
628
+ * a {@link CosyteFormat}, with the diagnostic supplied by the caller.
629
+ *
630
+ * Two of the packages the CLI lazy-loads are not wire-format parsers and so cannot go through
631
+ * {@link loadOptional}: `@cosyte/transform` (a conversion library, not one of the eight formats, so
632
+ * calling it a "parser" in the diagnostic would be wrong) and `@cosyte/fhir` (a format, but absent for
633
+ * a reason no reinstall fixes, which the message has to say). Both are reachable from a published
634
+ * install only if the user already has them, so both must degrade to a value-free
635
+ * `CLI_PARSER_UNAVAILABLE` (exit `69`) instead of surfacing a raw resolver error and a stack frame.
636
+ *
637
+ * @template T - The imported module's type.
638
+ * @param detail - The value-free diagnostic detail shown when the package is absent.
639
+ * @param load - A thunk performing the dynamic import.
640
+ * @returns The imported module.
641
+ * @throws {CliError} `CLI_PARSER_UNAVAILABLE` (exit `69`) when the package is absent; any other error
642
+ * propagates unchanged.
643
+ * @example
644
+ * ```ts
645
+ * import { loadOptionalPackage } from "@cosyte/cli";
646
+ *
647
+ * await loadOptionalPackage("the conversion library is not installed", () =>
648
+ * import("@cosyte/transform"),
649
+ * );
650
+ * ```
651
+ */
652
+ declare function loadOptionalPackage<T>(detail: string, load: () => Promise<T>): Promise<T>;
619
653
  /**
620
654
  * Parse one record of `format` into the wrapped library's model + its value-free warnings. The model
621
655
  * is emitted verbatim on the data channel; the CLI adds no parsing of its own.
@@ -914,14 +948,14 @@ declare function parseFailureResult(format: CosyteFormat, bytes: Uint8Array, pos
914
948
 
915
949
  /**
916
950
  * The **de-identification seam**: the single, documented plug-in point where the `redact` / `deid`
917
- * command will delegate to **`@cosyte/deid`** once that library ships and is vetted.
951
+ * command will delegate to **`@cosyte/deid`** once that integration lands and is vetted.
918
952
  *
919
953
  * ## Why the CLI ships no built-in redactor (the boundary decision)
920
954
  *
921
- * `@cosyte/deid` is **unpublished**, and the wrapped
955
+ * The CLI does **not wire `@cosyte/deid` yet**, and the wrapped
922
956
  * parsers (`@cosyte/hl7`, `@cosyte/fhir`) expose **no de-identification API**: they redact only
923
- * their own *diagnostics*, not the parsed model. So there is nothing to delegate to today, and adding
924
- * `@cosyte/deid` would depend on unbuilt code.
957
+ * their own *diagnostics*, not the parsed model. So there is nothing for the CLI to delegate to
958
+ * today.
925
959
  *
926
960
  * A tempting alternative, a "minimal built-in Safe-Harbor pass over the obvious PHI loci" (e.g. the
927
961
  * HL7 `PID` segment, `Patient.name`/`Patient.address` in FHIR), is **deliberately rejected**. Real
@@ -932,7 +966,7 @@ declare function parseFailureResult(format: CosyteFormat, bytes: Uint8Array, pos
932
966
  *
933
967
  * So `redact` is an **honest, typed `CLI_NOT_IMPLEMENTED`** (never a fake success, never a partial
934
968
  * scrub presented as de-identified, never invent a capability the ground layer lacks),
935
- * gated on `@cosyte/deid`, with this seam as its one drop-in point. When `@cosyte/deid` lands and is
969
+ * gated on `@cosyte/deid`, with this seam as its one drop-in point. When that integration lands and is
936
970
  * conformance-graded, {@link deidStatus} flips to `available` and the command reads the input, calls
937
971
  * the delegated de-identifier, and emits the de-identified model: the command surface (`redact`,
938
972
  * `deid`, `<file|->`, `--format`) already exists so that change is additive.
@@ -956,7 +990,7 @@ interface DeidAvailability {
956
990
  * Report the current de-identification availability. Today it is always unavailable (see the module
957
991
  * docs); this is the single line that flips when `@cosyte/deid` is wired.
958
992
  *
959
- * @returns The {@link DeidAvailability}: `{ available: false, reason }` until `@cosyte/deid` ships.
993
+ * @returns The {@link DeidAvailability}: `{ available: false, reason }` until `@cosyte/deid` is wired.
960
994
  * @example
961
995
  * ```ts
962
996
  * import { deidStatus } from "@cosyte/cli";
@@ -1299,7 +1333,7 @@ declare function mapCodesCommand(args: string[], deps: RunDeps): Promise<RunResu
1299
1333
  * PHI, emitting a de-identified copy of the parsed model.
1300
1334
  *
1301
1335
  * **It is deliberately not implemented yet.** De-identification belongs to **`@cosyte/deid`**, which
1302
- * is unpublished, and the wrapped parsers expose no de-id API to delegate to. A
1336
+ * the CLI does not wire yet, and the wrapped parsers expose no de-id API to delegate to. A
1303
1337
  * built-in "minimal Safe-Harbor" pass over only the obvious PHI loci would leave PHI behind and
1304
1338
  * present a **false-safety impression**: the cardinal hazard `redact` exists to avoid. So this
1305
1339
  * command is an **honest, typed `CLI_NOT_IMPLEMENTED`** (never a fake success, never a partial scrub
@@ -1357,4 +1391,4 @@ declare function redactCommand(args: string[]): RunResult;
1357
1391
  */
1358
1392
  declare function completionCommand(args: string[]): RunResult;
1359
1393
 
1360
- export { CLI_CODES, type CliCode, CliError, type CosyteFormat, DEID_UNAVAILABLE_REASON, DETECTABLE_FORMATS, type DeidAvailability, type DetectResult, EXIT, type ExitCode, type Finding, type FmtResult, type InputResolution, type InspectSummary, KNOWN_FORMATS, OP_SUPPORT, type Op, type ParseResult, type ParseWarning, type PhiPosture, type ResolvedInput, RunDeps, type RunResult, SHOW_VALUES, UNSAFE_EXCERPT_MAX, UNSAFE_SHOW_VALUES_FLAG, VALUE_FREE, VERSION, type Verdict, asCosyteFormat, classifyCandidates, completionCommand, convertCommand, convertOutcome, deframeMllp, deidStatus, detectFormat, detectionError, errorResult, extractPhiPosture, extractStableCode, fmtCommand, fmtFormat, formatDiagnostic, formatHl7Position, formatsSupporting, inspectCommand, inspectFormat, loadOptional, mapCodesCommand, parseCommand, parseFailureResult, parseFormat, redactCommand, resolveInput, run, supportsOp, toCliError, unsafeInputSuffix, validateCommand, validateFormat, valueFreeLocator };
1394
+ export { CLI_CODES, type CliCode, CliError, type CosyteFormat, DEID_UNAVAILABLE_REASON, DETECTABLE_FORMATS, type DeidAvailability, type DetectResult, EXIT, type ExitCode, type Finding, type FmtResult, type InputResolution, type InspectSummary, KNOWN_FORMATS, OP_SUPPORT, type Op, type ParseResult, type ParseWarning, type PhiPosture, type ResolvedInput, RunDeps, type RunResult, SHOW_VALUES, UNSAFE_EXCERPT_MAX, UNSAFE_SHOW_VALUES_FLAG, VALUE_FREE, VERSION, type Verdict, asCosyteFormat, classifyCandidates, completionCommand, convertCommand, convertOutcome, deframeMllp, deidStatus, detectFormat, detectionError, errorResult, extractPhiPosture, extractStableCode, fmtCommand, fmtFormat, formatDiagnostic, formatHl7Position, formatsSupporting, inspectCommand, inspectFormat, loadOptional, loadOptionalPackage, mapCodesCommand, parseCommand, parseFailureResult, parseFormat, redactCommand, resolveInput, run, supportsOp, toCliError, unsafeInputSuffix, validateCommand, validateFormat, valueFreeLocator };
package/dist/index.d.ts CHANGED
@@ -3,23 +3,30 @@ export { r as readFileBytes, a as readStreamBytes } from './io-B2EobRzC.js';
3
3
  import 'node:stream';
4
4
 
5
5
  /**
6
- * The CLI version string, synced with `package.json#version` on release by the Changesets `version`
7
- * script. Kept in its own module so both the programmatic entry point and the dispatcher share one
8
- * source of truth.
6
+ * The CLI version string, synced with `package.json#version` on release by `scripts/sync-version.mjs`,
7
+ * which the `version` script runs immediately after `changeset version`. Kept in its own module so
8
+ * both the programmatic entry point and the dispatcher share one source of truth.
9
+ *
10
+ * The declaration below is rewritten by that script and is matched at column 0, annotation included.
11
+ * Renaming it or reflowing it makes the script exit non-zero rather than silently no-op; the shape is
12
+ * pinned by `test/sanity.test.ts`, and the value is compared against `package.json` there too.
9
13
  *
10
14
  * @packageDocumentation
11
15
  */
12
16
  /**
13
17
  * The `@cosyte/cli` version. On the uniform `v0.0.x-until-first-alpha` ladder.
14
18
  *
19
+ * Read by `cosyte --version` and by the MCP server's advertised `SERVER_INFO`, so it is a
20
+ * user-visible surface on both front doors, not merely an export.
21
+ *
15
22
  * @example
16
23
  * ```ts
17
24
  * import { VERSION } from "@cosyte/cli";
18
25
  *
19
- * typeof VERSION; // => "string"
26
+ * console.log(`cosyte ${VERSION}`);
20
27
  * ```
21
28
  */
22
- declare const VERSION = "0.0.0";
29
+ declare const VERSION: string;
23
30
 
24
31
  /**
25
32
  * The `cosyte` CLI **exit-code contract**: a designed, documented surface that CI pipelines and
@@ -36,7 +43,7 @@ declare const VERSION = "0.0.0";
36
43
  * | `2` | `USAGE` | usage error: unknown command, bad flag, missing argument (EX_USAGE) |
37
44
  * | `65` | `DATAERR` | data error: input could not be parsed / format not detected (EX_DATAERR) |
38
45
  * | `66` | `NOINPUT` | no input: the file does not exist or is unreadable (EX_NOINPUT) |
39
- * | `69` | `UNAVAILABLE` | a required capability is not yet available: e.g. `redact` before `@cosyte/deid` ships (EX_UNAVAILABLE) |
46
+ * | `69` | `UNAVAILABLE` | a required capability is not yet available: e.g. `redact` before `@cosyte/deid` is wired (EX_UNAVAILABLE) |
40
47
  * | `70` | `SOFTWARE` | internal error: an unexpected exception, i.e. a bug (EX_SOFTWARE) |
41
48
  *
42
49
  * The load-bearing `validate` rule: a **parseable-but-invalid** message is exit `1`, never exit `0`.
@@ -70,7 +77,7 @@ declare const EXIT: {
70
77
  readonly DATAERR: 65;
71
78
  /** No input: the named file does not exist or is unreadable (`EX_NOINPUT`). */
72
79
  readonly NOINPUT: 66;
73
- /** Unavailable: a required capability is not yet built (e.g. `redact` before `@cosyte/deid`), a
80
+ /** Unavailable: a required capability is not yet wired (e.g. `redact` before `@cosyte/deid`), a
74
81
  * distinct non-zero signal that is never a fake success (`EX_UNAVAILABLE`). */
75
82
  readonly UNAVAILABLE: 69;
76
83
  /** Internal error: an unexpected exception (a bug), distinct from a handled bad input (`EX_SOFTWARE`). */
@@ -161,8 +168,8 @@ declare const CLI_CODES: {
161
168
  /** The BYO ConceptMap supplied to `map-codes` is not valid JSON or not a loadable FHIR ConceptMap.
162
169
  * Names the stable terminology-loader code, never the map's bytes. Exit `65`. */
163
170
  readonly CLI_MAP_INVALID: "CLI_MAP_INVALID";
164
- /** A command whose ground-layer library is not yet built (e.g. `redact` before `@cosyte/deid`
165
- * ships). Never a fake success: a distinct, value-free "unavailable" signal. Exit `69`. */
171
+ /** A command whose ground-layer library is not yet wired (e.g. `redact` before `@cosyte/deid` is
172
+ * wired). Never a fake success: a distinct, value-free "unavailable" signal. Exit `69`. */
166
173
  readonly CLI_NOT_IMPLEMENTED: "CLI_NOT_IMPLEMENTED";
167
174
  /** An unexpected internal error (a bug). Exit `70`. */
168
175
  readonly CLI_INTERNAL: "CLI_INTERNAL";
@@ -616,6 +623,33 @@ declare function valueFreeLocator(pos: unknown): string;
616
623
  * ```
617
624
  */
618
625
  declare function loadOptional<T>(format: CosyteFormat, load: () => Promise<T>): Promise<T>;
626
+ /**
627
+ * The same graceful-degradation path as {@link loadOptional}, keyed on a **package name** rather than
628
+ * a {@link CosyteFormat}, with the diagnostic supplied by the caller.
629
+ *
630
+ * Two of the packages the CLI lazy-loads are not wire-format parsers and so cannot go through
631
+ * {@link loadOptional}: `@cosyte/transform` (a conversion library, not one of the eight formats, so
632
+ * calling it a "parser" in the diagnostic would be wrong) and `@cosyte/fhir` (a format, but absent for
633
+ * a reason no reinstall fixes, which the message has to say). Both are reachable from a published
634
+ * install only if the user already has them, so both must degrade to a value-free
635
+ * `CLI_PARSER_UNAVAILABLE` (exit `69`) instead of surfacing a raw resolver error and a stack frame.
636
+ *
637
+ * @template T - The imported module's type.
638
+ * @param detail - The value-free diagnostic detail shown when the package is absent.
639
+ * @param load - A thunk performing the dynamic import.
640
+ * @returns The imported module.
641
+ * @throws {CliError} `CLI_PARSER_UNAVAILABLE` (exit `69`) when the package is absent; any other error
642
+ * propagates unchanged.
643
+ * @example
644
+ * ```ts
645
+ * import { loadOptionalPackage } from "@cosyte/cli";
646
+ *
647
+ * await loadOptionalPackage("the conversion library is not installed", () =>
648
+ * import("@cosyte/transform"),
649
+ * );
650
+ * ```
651
+ */
652
+ declare function loadOptionalPackage<T>(detail: string, load: () => Promise<T>): Promise<T>;
619
653
  /**
620
654
  * Parse one record of `format` into the wrapped library's model + its value-free warnings. The model
621
655
  * is emitted verbatim on the data channel; the CLI adds no parsing of its own.
@@ -914,14 +948,14 @@ declare function parseFailureResult(format: CosyteFormat, bytes: Uint8Array, pos
914
948
 
915
949
  /**
916
950
  * The **de-identification seam**: the single, documented plug-in point where the `redact` / `deid`
917
- * command will delegate to **`@cosyte/deid`** once that library ships and is vetted.
951
+ * command will delegate to **`@cosyte/deid`** once that integration lands and is vetted.
918
952
  *
919
953
  * ## Why the CLI ships no built-in redactor (the boundary decision)
920
954
  *
921
- * `@cosyte/deid` is **unpublished**, and the wrapped
955
+ * The CLI does **not wire `@cosyte/deid` yet**, and the wrapped
922
956
  * parsers (`@cosyte/hl7`, `@cosyte/fhir`) expose **no de-identification API**: they redact only
923
- * their own *diagnostics*, not the parsed model. So there is nothing to delegate to today, and adding
924
- * `@cosyte/deid` would depend on unbuilt code.
957
+ * their own *diagnostics*, not the parsed model. So there is nothing for the CLI to delegate to
958
+ * today.
925
959
  *
926
960
  * A tempting alternative, a "minimal built-in Safe-Harbor pass over the obvious PHI loci" (e.g. the
927
961
  * HL7 `PID` segment, `Patient.name`/`Patient.address` in FHIR), is **deliberately rejected**. Real
@@ -932,7 +966,7 @@ declare function parseFailureResult(format: CosyteFormat, bytes: Uint8Array, pos
932
966
  *
933
967
  * So `redact` is an **honest, typed `CLI_NOT_IMPLEMENTED`** (never a fake success, never a partial
934
968
  * scrub presented as de-identified, never invent a capability the ground layer lacks),
935
- * gated on `@cosyte/deid`, with this seam as its one drop-in point. When `@cosyte/deid` lands and is
969
+ * gated on `@cosyte/deid`, with this seam as its one drop-in point. When that integration lands and is
936
970
  * conformance-graded, {@link deidStatus} flips to `available` and the command reads the input, calls
937
971
  * the delegated de-identifier, and emits the de-identified model: the command surface (`redact`,
938
972
  * `deid`, `<file|->`, `--format`) already exists so that change is additive.
@@ -956,7 +990,7 @@ interface DeidAvailability {
956
990
  * Report the current de-identification availability. Today it is always unavailable (see the module
957
991
  * docs); this is the single line that flips when `@cosyte/deid` is wired.
958
992
  *
959
- * @returns The {@link DeidAvailability}: `{ available: false, reason }` until `@cosyte/deid` ships.
993
+ * @returns The {@link DeidAvailability}: `{ available: false, reason }` until `@cosyte/deid` is wired.
960
994
  * @example
961
995
  * ```ts
962
996
  * import { deidStatus } from "@cosyte/cli";
@@ -1299,7 +1333,7 @@ declare function mapCodesCommand(args: string[], deps: RunDeps): Promise<RunResu
1299
1333
  * PHI, emitting a de-identified copy of the parsed model.
1300
1334
  *
1301
1335
  * **It is deliberately not implemented yet.** De-identification belongs to **`@cosyte/deid`**, which
1302
- * is unpublished, and the wrapped parsers expose no de-id API to delegate to. A
1336
+ * the CLI does not wire yet, and the wrapped parsers expose no de-id API to delegate to. A
1303
1337
  * built-in "minimal Safe-Harbor" pass over only the obvious PHI loci would leave PHI behind and
1304
1338
  * present a **false-safety impression**: the cardinal hazard `redact` exists to avoid. So this
1305
1339
  * command is an **honest, typed `CLI_NOT_IMPLEMENTED`** (never a fake success, never a partial scrub
@@ -1357,4 +1391,4 @@ declare function redactCommand(args: string[]): RunResult;
1357
1391
  */
1358
1392
  declare function completionCommand(args: string[]): RunResult;
1359
1393
 
1360
- export { CLI_CODES, type CliCode, CliError, type CosyteFormat, DEID_UNAVAILABLE_REASON, DETECTABLE_FORMATS, type DeidAvailability, type DetectResult, EXIT, type ExitCode, type Finding, type FmtResult, type InputResolution, type InspectSummary, KNOWN_FORMATS, OP_SUPPORT, type Op, type ParseResult, type ParseWarning, type PhiPosture, type ResolvedInput, RunDeps, type RunResult, SHOW_VALUES, UNSAFE_EXCERPT_MAX, UNSAFE_SHOW_VALUES_FLAG, VALUE_FREE, VERSION, type Verdict, asCosyteFormat, classifyCandidates, completionCommand, convertCommand, convertOutcome, deframeMllp, deidStatus, detectFormat, detectionError, errorResult, extractPhiPosture, extractStableCode, fmtCommand, fmtFormat, formatDiagnostic, formatHl7Position, formatsSupporting, inspectCommand, inspectFormat, loadOptional, mapCodesCommand, parseCommand, parseFailureResult, parseFormat, redactCommand, resolveInput, run, supportsOp, toCliError, unsafeInputSuffix, validateCommand, validateFormat, valueFreeLocator };
1394
+ export { CLI_CODES, type CliCode, CliError, type CosyteFormat, DEID_UNAVAILABLE_REASON, DETECTABLE_FORMATS, type DeidAvailability, type DetectResult, EXIT, type ExitCode, type Finding, type FmtResult, type InputResolution, type InspectSummary, KNOWN_FORMATS, OP_SUPPORT, type Op, type ParseResult, type ParseWarning, type PhiPosture, type ResolvedInput, RunDeps, type RunResult, SHOW_VALUES, UNSAFE_EXCERPT_MAX, UNSAFE_SHOW_VALUES_FLAG, VALUE_FREE, VERSION, type Verdict, asCosyteFormat, classifyCandidates, completionCommand, convertCommand, convertOutcome, deframeMllp, deidStatus, detectFormat, detectionError, errorResult, extractPhiPosture, extractStableCode, fmtCommand, fmtFormat, formatDiagnostic, formatHl7Position, formatsSupporting, inspectCommand, inspectFormat, loadOptional, loadOptionalPackage, mapCodesCommand, parseCommand, parseFailureResult, parseFormat, redactCommand, resolveInput, run, supportsOp, toCliError, unsafeInputSuffix, validateCommand, validateFormat, valueFreeLocator };
package/dist/index.mjs CHANGED
@@ -2,7 +2,7 @@ import { readFile } from 'fs/promises';
2
2
  import { parseArgs } from 'util';
3
3
 
4
4
  // src/core/version.ts
5
- var VERSION = "0.0.0";
5
+ var VERSION = "0.0.3";
6
6
 
7
7
  // src/core/exit-codes.ts
8
8
  var EXIT = {
@@ -18,7 +18,7 @@ var EXIT = {
18
18
  DATAERR: 65,
19
19
  /** No input: the named file does not exist or is unreadable (`EX_NOINPUT`). */
20
20
  NOINPUT: 66,
21
- /** Unavailable: a required capability is not yet built (e.g. `redact` before `@cosyte/deid`), a
21
+ /** Unavailable: a required capability is not yet wired (e.g. `redact` before `@cosyte/deid`), a
22
22
  * distinct non-zero signal that is never a fake success (`EX_UNAVAILABLE`). */
23
23
  UNAVAILABLE: 69,
24
24
  /** Internal error: an unexpected exception (a bug), distinct from a handled bad input (`EX_SOFTWARE`). */
@@ -49,8 +49,8 @@ var CLI_CODES = {
49
49
  /** The BYO ConceptMap supplied to `map-codes` is not valid JSON or not a loadable FHIR ConceptMap.
50
50
  * Names the stable terminology-loader code, never the map's bytes. Exit `65`. */
51
51
  CLI_MAP_INVALID: "CLI_MAP_INVALID",
52
- /** A command whose ground-layer library is not yet built (e.g. `redact` before `@cosyte/deid`
53
- * ships). Never a fake success: a distinct, value-free "unavailable" signal. Exit `69`. */
52
+ /** A command whose ground-layer library is not yet wired (e.g. `redact` before `@cosyte/deid` is
53
+ * wired). Never a fake success: a distinct, value-free "unavailable" signal. Exit `69`. */
54
54
  CLI_NOT_IMPLEMENTED: "CLI_NOT_IMPLEMENTED",
55
55
  /** An unexpected internal error (a bug). Exit `70`. */
56
56
  CLI_INTERNAL: "CLI_INTERNAL"
@@ -226,19 +226,25 @@ function anyError(findings) {
226
226
  return findings.some((f) => ERROR_SEVERITIES.has(f.severity));
227
227
  }
228
228
  async function loadOptional(format, load) {
229
+ return loadOptionalPackage(
230
+ `the @cosyte/${format} parser is not installed; install it to use this format (it is an optional dependency)`,
231
+ load
232
+ );
233
+ }
234
+ async function loadOptionalPackage(detail, load) {
229
235
  try {
230
236
  return await load();
231
237
  } catch (e) {
232
238
  if (isModuleNotFound(e)) {
233
- throw new CliError(
234
- CLI_CODES.CLI_PARSER_UNAVAILABLE,
235
- EXIT.UNAVAILABLE,
236
- `the @cosyte/${format} parser is not installed; install it to use this format (it is an optional dependency)`
237
- );
239
+ throw new CliError(CLI_CODES.CLI_PARSER_UNAVAILABLE, EXIT.UNAVAILABLE, detail);
238
240
  }
239
241
  throw e;
240
242
  }
241
243
  }
244
+ var FHIR_UNAVAILABLE = "the @cosyte/fhir parser is not installed, and it is not currently on the npm registry, so it cannot be installed from there; FHIR support is unavailable in this install";
245
+ async function loadFhir() {
246
+ return loadOptionalPackage(FHIR_UNAVAILABLE, () => import('@cosyte/fhir'));
247
+ }
242
248
  function isModuleNotFound(e) {
243
249
  if (typeof e !== "object" || e === null) return false;
244
250
  const code = "code" in e ? e.code : void 0;
@@ -257,7 +263,7 @@ async function parseFormat(format, bytes) {
257
263
  };
258
264
  }
259
265
  case "fhir": {
260
- const { parseResource, serializeResource } = await import('@cosyte/fhir');
266
+ const { parseResource, serializeResource } = await loadFhir();
261
267
  const text = decode(bytes);
262
268
  const { resource, issues } = parseResource(text);
263
269
  const model = JSON.parse(serializeResource(resource));
@@ -318,7 +324,7 @@ async function inspectFormat(format, bytes) {
318
324
  };
319
325
  }
320
326
  case "fhir": {
321
- const { parseResource, resourceType, readBundle } = await import('@cosyte/fhir');
327
+ const { parseResource, resourceType, readBundle } = await loadFhir();
322
328
  const { resource, issues } = parseResource(decode(bytes));
323
329
  const rt = resourceType(resource) ?? null;
324
330
  if (rt === "Bundle") {
@@ -428,7 +434,7 @@ async function fmtFormat(format, bytes) {
428
434
  return { output: msg.toString(), warningCount: msg.warnings.length };
429
435
  }
430
436
  case "fhir": {
431
- const { parseResource, serializeResource } = await import('@cosyte/fhir');
437
+ const { parseResource, serializeResource } = await loadFhir();
432
438
  const { resource, issues } = parseResource(decode(bytes));
433
439
  return { output: serializeResource(resource), warningCount: issues.length };
434
440
  }
@@ -466,7 +472,7 @@ async function fmtFormat(format, bytes) {
466
472
  async function validateFormat(format, bytes) {
467
473
  switch (format) {
468
474
  case "fhir": {
469
- const { parseResource, validateResource } = await import('@cosyte/fhir');
475
+ const { parseResource, validateResource } = await loadFhir();
470
476
  const { resource, issues } = parseResource(decode(bytes));
471
477
  const validation = validateResource(resource);
472
478
  const findings = [
@@ -670,7 +676,7 @@ async function readStreamBytes(stream) {
670
676
  }
671
677
 
672
678
  // src/core/deid.ts
673
- var DEID_UNAVAILABLE_REASON = "redact/deid is not yet available. It delegates to @cosyte/deid, which is unpublished. The CLI ships no built-in redactor: a partial Safe-Harbor scrub over only the obvious PHI loci would leave PHI behind and present a false-safety impression, so nothing is emitted. This command will produce a de-identified copy once @cosyte/deid ships and is vetted.";
679
+ var DEID_UNAVAILABLE_REASON = "redact/deid is not yet available. It delegates to @cosyte/deid, which the CLI does not wire yet. The CLI ships no built-in redactor: a partial Safe-Harbor scrub over only the obvious PHI loci would leave PHI behind and present a false-safety impression, so nothing is emitted. This command will produce a de-identified copy once that integration lands and is vetted.";
674
680
  function deidStatus() {
675
681
  return { available: false, reason: DEID_UNAVAILABLE_REASON };
676
682
  }
@@ -836,11 +842,12 @@ async function convertCommand(args, deps, posture = VALUE_FREE) {
836
842
  return { stdout: `${conversion.bundleText}
837
843
  `, stderr, exit };
838
844
  }
845
+ var TRANSFORM_UNAVAILABLE = "the @cosyte/transform conversion library is not installed, so convert is unavailable; it requires @cosyte/fhir, which is not currently on the npm registry, so npm skips transform as an unresolvable optional dependency and installing it directly fails for the same reason";
839
846
  async function runConvert(bytes, posture) {
840
847
  const [{ parseHL7 }, { toFhir }, { serializeResource }] = await Promise.all([
841
848
  import('@cosyte/hl7'),
842
- import('@cosyte/transform'),
843
- import('@cosyte/fhir')
849
+ loadOptionalPackage(TRANSFORM_UNAVAILABLE, () => import('@cosyte/transform')),
850
+ loadFhir()
844
851
  ]);
845
852
  let msg;
846
853
  try {
@@ -1322,7 +1329,7 @@ Commands:
1322
1329
  fmt <file|-> Canonically re-serialize via the parser's spec-clean serializer
1323
1330
  convert <file|-> Convert HL7 v2 \u2192 FHIR R4 via @cosyte/transform (use --to fhir)
1324
1331
  map-codes <cmap|-> Translate a code through a BYO FHIR ConceptMap via @cosyte/terminology
1325
- redact <file|-> De-identify a message (alias: deid): gated on @cosyte/deid, not yet available
1332
+ redact <file|-> De-identify a message (alias: deid): gated on @cosyte/deid, not yet wired
1326
1333
  mcp Start the stdio MCP server (agent front door; also the cosyte-mcp bin)
1327
1334
  completion <shell> Print a shell completion script (bash | zsh | fish)
1328
1335
 
@@ -1409,6 +1416,6 @@ function resolve(e) {
1409
1416
  `, exit: e.exit };
1410
1417
  }
1411
1418
 
1412
- export { CLI_CODES, CliError, DEID_UNAVAILABLE_REASON, DETECTABLE_FORMATS, EXIT, KNOWN_FORMATS, OP_SUPPORT, SHOW_VALUES, UNSAFE_EXCERPT_MAX, UNSAFE_SHOW_VALUES_FLAG, VALUE_FREE, VERSION, asCosyteFormat, classifyCandidates, completionCommand, convertCommand, convertOutcome, deframeMllp, deidStatus, detectFormat, detectionError, errorResult, extractPhiPosture, extractStableCode, fmtCommand, fmtFormat, formatDiagnostic, formatHl7Position, formatsSupporting, inspectCommand, inspectFormat, loadOptional, mapCodesCommand, parseCommand, parseFailureResult, parseFormat, readFileBytes, readStreamBytes, redactCommand, resolveInput, run, supportsOp, toCliError, unsafeInputSuffix, validateCommand, validateFormat, valueFreeLocator };
1419
+ export { CLI_CODES, CliError, DEID_UNAVAILABLE_REASON, DETECTABLE_FORMATS, EXIT, KNOWN_FORMATS, OP_SUPPORT, SHOW_VALUES, UNSAFE_EXCERPT_MAX, UNSAFE_SHOW_VALUES_FLAG, VALUE_FREE, VERSION, asCosyteFormat, classifyCandidates, completionCommand, convertCommand, convertOutcome, deframeMllp, deidStatus, detectFormat, detectionError, errorResult, extractPhiPosture, extractStableCode, fmtCommand, fmtFormat, formatDiagnostic, formatHl7Position, formatsSupporting, inspectCommand, inspectFormat, loadOptional, loadOptionalPackage, mapCodesCommand, parseCommand, parseFailureResult, parseFormat, readFileBytes, readStreamBytes, redactCommand, resolveInput, run, supportsOp, toCliError, unsafeInputSuffix, validateCommand, validateFormat, valueFreeLocator };
1413
1420
  //# sourceMappingURL=index.mjs.map
1414
1421
  //# sourceMappingURL=index.mjs.map