@telorun/cli 0.69.0 → 0.71.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/README.md +99 -22
  2. package/dist/cli.js +11 -0
  3. package/dist/cli.js.map +1 -1
  4. package/dist/commands/cel.d.ts.map +1 -1
  5. package/dist/commands/cel.js +33 -14
  6. package/dist/commands/cel.js.map +1 -1
  7. package/dist/commands/check.d.ts.map +1 -1
  8. package/dist/commands/check.js +43 -8
  9. package/dist/commands/check.js.map +1 -1
  10. package/dist/commands/install.d.ts.map +1 -1
  11. package/dist/commands/install.js +27 -17
  12. package/dist/commands/install.js.map +1 -1
  13. package/dist/commands/module.d.ts.map +1 -1
  14. package/dist/commands/module.js +36 -31
  15. package/dist/commands/module.js.map +1 -1
  16. package/dist/commands/publish.d.ts.map +1 -1
  17. package/dist/commands/publish.js +40 -24
  18. package/dist/commands/publish.js.map +1 -1
  19. package/dist/commands/run.d.ts.map +1 -1
  20. package/dist/commands/run.js +15 -4
  21. package/dist/commands/run.js.map +1 -1
  22. package/dist/commands/search.d.ts.map +1 -1
  23. package/dist/commands/search.js +19 -10
  24. package/dist/commands/search.js.map +1 -1
  25. package/dist/commands/upgrade.d.ts.map +1 -1
  26. package/dist/commands/upgrade.js +35 -21
  27. package/dist/commands/upgrade.js.map +1 -1
  28. package/dist/controller-progress.d.ts.map +1 -1
  29. package/dist/controller-progress.js +0 -0
  30. package/dist/controller-progress.js.map +1 -1
  31. package/dist/debug-event-subscriber.d.ts.map +1 -1
  32. package/dist/debug-event-subscriber.js +2 -1
  33. package/dist/debug-event-subscriber.js.map +1 -1
  34. package/dist/logger.d.ts +23 -0
  35. package/dist/logger.d.ts.map +1 -1
  36. package/dist/logger.js +65 -36
  37. package/dist/logger.js.map +1 -1
  38. package/dist/output.d.ts +111 -0
  39. package/dist/output.d.ts.map +1 -0
  40. package/dist/output.js +143 -0
  41. package/dist/output.js.map +1 -0
  42. package/package.json +5 -5
package/dist/output.js ADDED
@@ -0,0 +1,143 @@
1
+ import { decideColor } from "@telorun/kernel";
2
+ export const OUTPUT_FORMATS = ["text", "json"];
3
+ const PLAIN = {
4
+ ok: (t) => t,
5
+ warn: (t) => t,
6
+ error: (t) => t,
7
+ dim: (t) => t,
8
+ };
9
+ function paletteFor(isTTY, env) {
10
+ // Follows `kernel/specs/logging.md` §11.2 precedence, shared with the `pretty`
11
+ // log encoding rather than reimplemented.
12
+ if (!decideColor({ setting: "auto", env, isTTY }))
13
+ return PLAIN;
14
+ const wrap = (code) => (text) => `\x1b[${code}m${text}\x1b[0m`;
15
+ return { ok: wrap("32"), warn: wrap("33"), error: wrap("31"), dim: wrap("2") };
16
+ }
17
+ /** The single seam every CLI-owned write goes through.
18
+ *
19
+ * The stream split is the whole contract:
20
+ *
21
+ * - **stdout is the machine surface.** Under `-o json` it carries the payload
22
+ * and nothing else, so a consumer parses it whole.
23
+ * - **stderr is the human surface, in BOTH formats.** Prose keeps flowing under
24
+ * `-o json` — the convention npm, cargo and kubectl follow — because the
25
+ * alternative is silence: a command that reports a failure reason through
26
+ * prose would otherwise have it swallowed, leaving `{"ok":false}` with no
27
+ * cause. Suppressing stderr was error swallowing, which Telo forbids.
28
+ *
29
+ * `telo run` is exempt from `-o json` entirely; see `emit`. */
30
+ export class Output {
31
+ format;
32
+ stdout;
33
+ stderr;
34
+ outStream;
35
+ errStream;
36
+ constructor(options) {
37
+ const { format, stdout = process.stdout, stderr = process.stderr, env = process.env, } = options;
38
+ this.format = format;
39
+ this.outStream = stdout;
40
+ this.errStream = stderr;
41
+ // Structured output must never carry escapes: a consumer parses it, and no
42
+ // terminal renders it. Deciding this here rather than at each call site is
43
+ // what makes "JSON is always clean" true by construction. stderr keeps its
44
+ // colour under `-o json` because it stays the human surface.
45
+ this.stdout = format === "text" ? paletteFor(Boolean(stdout.isTTY), env) : PLAIN;
46
+ this.stderr = paletteFor(Boolean(stderr.isTTY), env);
47
+ }
48
+ get isJson() {
49
+ return this.format === "json";
50
+ }
51
+ /** Human-readable line on stdout. Suppressed under `-o json`, where stdout is
52
+ * reserved for the payload. */
53
+ line(text = "") {
54
+ if (this.format === "text")
55
+ this.outStream.write(`${text}\n`);
56
+ }
57
+ /** Human-readable line on stderr. Written in BOTH formats — stderr is not the
58
+ * machine contract, and silencing it loses the reason a command failed. */
59
+ errLine(text = "") {
60
+ this.errStream.write(`${text}\n`);
61
+ }
62
+ /** Emit a command's structured RESULT ENVELOPE. A no-op in text mode.
63
+ *
64
+ * Every command that owns its stdout calls this exactly once, including when
65
+ * it has nothing interesting to report — a consumer cannot distinguish
66
+ * "nothing to say" from "this command ignores the flag", so a bare envelope
67
+ * is the difference between a contract and a guess.
68
+ *
69
+ * `telo run` is the ONE exemption, and it is a property of the command rather
70
+ * than an oversight: the kernel runs in-process and the app's own output goes
71
+ * to these same descriptors (`teeStdio` copies, it does not redirect), so
72
+ * NEITHER stream is the CLI's to claim. An envelope written after arbitrary
73
+ * app output is unparseable, which is the exact failure `-o json` exists to
74
+ * remove. The machine surface for a run already exists and is `--debug`,
75
+ * whose wire protocol is framed per event precisely because it shares a
76
+ * stream. */
77
+ emit(payload) {
78
+ if (this.format === "json")
79
+ this.outStream.write(serialize(payload));
80
+ }
81
+ /** Write a bare DOCUMENT to stdout, in either format.
82
+ *
83
+ * For the commands whose structured form is the document itself rather than a
84
+ * result report — `cel`, `search`, `module versions|manifest|digest|resources|kinds`.
85
+ * Unconditional because their per-command `--json` flag predates `-o` and
86
+ * must keep working under the default `text` format. One serializer with
87
+ * `emit`, so the CLI has a single JSON encoding rather than three. */
88
+ document(payload) {
89
+ this.outStream.write(serialize(payload));
90
+ }
91
+ /** Write verbatim content to stdout, unconditionally and with no framing.
92
+ *
93
+ * For the one case that is neither prose nor a JSON payload: `telo module
94
+ * manifest` printing a module's `telo.yaml` bytes, which ARE the output. It
95
+ * bypasses format handling because the bytes are the answer in every format
96
+ * — the `--json` path wraps them in a document instead and never reaches
97
+ * here. */
98
+ raw(content) {
99
+ this.outStream.write(content);
100
+ }
101
+ }
102
+ function serialize(payload) {
103
+ return `${JSON.stringify(payload, null, 2)}\n`;
104
+ }
105
+ /** Configured once from argv by a yargs middleware, before any handler runs, so
106
+ * call sites far from the handler reach the same decision without threading it
107
+ * through every signature. Tests construct an `Output` directly instead. */
108
+ let current = new Output({ format: "text" });
109
+ export function configureOutput(format) {
110
+ current = new Output({ format });
111
+ }
112
+ /** Swap the ambient instance, returning a restore function.
113
+ *
114
+ * For tests of code that reaches the seam through the accessor rather than
115
+ * through a parameter — they hand in an `Output` over recording streams instead
116
+ * of spying on `process.stderr.write`. */
117
+ export function installOutput(replacement) {
118
+ const previous = current;
119
+ current = replacement;
120
+ return () => {
121
+ current = previous;
122
+ };
123
+ }
124
+ export function output() {
125
+ return current;
126
+ }
127
+ /** yargs has already rejected anything outside `choices` by the time a handler
128
+ * runs, so an unrecognized value here means the enum grew and this function was
129
+ * not updated. Throwing is the point: silently degrading `-o yaml` to text is
130
+ * the worst failure a format flag can have. */
131
+ export function parseOutputFormat(value) {
132
+ if (OUTPUT_FORMATS.includes(value))
133
+ return value;
134
+ throw new Error(`Unsupported --output format '${String(value)}'. Expected one of: ${OUTPUT_FORMATS.join(", ")}.`);
135
+ }
136
+ /** Free-function forms of the seam, for the many call sites that only need to
137
+ * write a line and would otherwise each bind a local. They read the singleton
138
+ * per call, so they observe the configured format no matter when they run. */
139
+ export const outLine = (text = "") => current.line(text);
140
+ export const outErrLine = (text = "") => current.errLine(text);
141
+ export const outEmit = (payload) => current.emit(payload);
142
+ export const outDocument = (payload) => current.document(payload);
143
+ //# sourceMappingURL=output.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"output.js","sourceRoot":"","sources":["../src/output.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAM9C,MAAM,CAAC,MAAM,cAAc,GAAmB,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAiB/D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AAC,QAAQ,CAAC,OAAO,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@telorun/cli",
3
- "version": "0.69.0",
3
+ "version": "0.71.0",
4
4
  "description": "Telo CLI - Command-line interface for the Telo runtime.",
5
5
  "keywords": [
6
6
  "telo",
@@ -34,11 +34,11 @@
34
34
  "dist"
35
35
  ],
36
36
  "dependencies": {
37
- "@telorun/analyzer": "0.56.0",
37
+ "@telorun/analyzer": "0.56.1",
38
38
  "@telorun/glob": "0.2.0",
39
- "@telorun/ide-support": "0.11.2",
40
- "@telorun/kernel": "0.69.0",
41
- "@telorun/sdk": "0.68.0",
39
+ "@telorun/ide-support": "0.11.3",
40
+ "@telorun/kernel": "0.70.0",
41
+ "@telorun/sdk": "0.70.0",
42
42
  "@telorun/templating": "0.12.0",
43
43
  "dotenv": "^17.4.0",
44
44
  "packageurl-js": "^2.0.1",