@hop-top/kit 0.5.0-alpha.6 → 0.5.0-alpha.8

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 (72) hide show
  1. package/CHANGELOG.md +52 -0
  2. package/LICENSE-cobra.txt +174 -0
  3. package/NOTICE +15 -0
  4. package/README.md +3 -3
  5. package/dist/alias-D9_qFlyP.d.ts +174 -0
  6. package/dist/alias.d.ts +1 -1
  7. package/dist/alias.js +10 -2
  8. package/dist/chunk-263IZ6Z6.js +915 -0
  9. package/dist/{chunk-S45UHXQF.js → chunk-BLS2OBIQ.js} +106 -25
  10. package/dist/{chunk-7FDIN5KE.js → chunk-GHPJJV5L.js} +8 -4
  11. package/dist/chunk-JKMQSAJP.js +174 -0
  12. package/dist/chunk-JZ22ZUFA.js +1131 -0
  13. package/dist/{chunk-GAZPYCQD.js → chunk-NLMS7HGP.js} +93 -35
  14. package/dist/chunk-QQQYCWSC.js +240 -0
  15. package/dist/chunk-XJTRY453.js +868 -0
  16. package/dist/cli.js +6 -4
  17. package/dist/completion-csVun6SP.d.ts +112 -0
  18. package/dist/completion-values-By-mnjNt.d.ts +142 -0
  19. package/dist/completion-values.d.ts +1 -0
  20. package/dist/completion-values.js +29 -0
  21. package/dist/completion.d.ts +2 -1
  22. package/dist/completion.js +23 -2
  23. package/dist/compliance-AxFf-uMy.d.ts +60 -0
  24. package/dist/compliance.d.ts +1 -0
  25. package/dist/compliance.js +17 -0
  26. package/dist/config-CaK60ByQ.d.ts +241 -0
  27. package/dist/config.d.ts +1 -1
  28. package/dist/config.js +4 -2
  29. package/dist/index.d.ts +7 -5
  30. package/dist/index.js +26 -18
  31. package/dist/log-CkaxMX3U.d.ts +115 -0
  32. package/dist/log.d.ts +1 -1
  33. package/dist/log.js +2 -2
  34. package/dist/toolspec-UrWnoJ3Y.d.ts +336 -0
  35. package/dist/toolspec.d.ts +2 -1
  36. package/dist/toolspec.js +27 -2
  37. package/package.json +19 -3
  38. package/src/alias.conformance.test.ts +250 -0
  39. package/src/alias.test.ts +206 -2
  40. package/src/alias.ts +196 -21
  41. package/src/cli.ts +5 -0
  42. package/src/completion-scripts.ts +16 -0
  43. package/src/completion-values.test.ts +70 -10
  44. package/src/completion-values.ts +170 -66
  45. package/src/completion.conformance.test.ts +297 -0
  46. package/src/completion.test.ts +256 -145
  47. package/src/completion.ts +767 -121
  48. package/src/config-merge.test.ts +425 -0
  49. package/src/config.test.ts +41 -0
  50. package/src/config.ts +265 -18
  51. package/src/index.test.ts +2 -1
  52. package/src/index.ts +5 -1
  53. package/src/log.test.ts +270 -1
  54. package/src/log.ts +172 -44
  55. package/src/published-types.test.ts +18 -0
  56. package/src/toolspec-internal.ts +197 -0
  57. package/src/toolspec-manifest.test.ts +82 -0
  58. package/src/toolspec-manifest.ts +404 -0
  59. package/src/toolspec-spec-schemas.ts +12 -0
  60. package/src/toolspec-spec.test.ts +273 -0
  61. package/src/toolspec-spec.ts +458 -0
  62. package/src/toolspec.from-command.test.ts +216 -0
  63. package/src/toolspec.ts +159 -0
  64. package/test/toolspec/fixture.ts +73 -0
  65. package/dist/alias-BOj0-VAr.d.ts +0 -88
  66. package/dist/chunk-6RFRV4VP.js +0 -128
  67. package/dist/chunk-IQXEISMC.js +0 -142
  68. package/dist/chunk-W7ERKNSQ.js +0 -171
  69. package/dist/completion-CVnPcWMZ.d.ts +0 -32
  70. package/dist/config-Bm9fBXch.d.ts +0 -134
  71. package/dist/log-uKjHsK-c.d.ts +0 -62
  72. package/dist/toolspec-DPBr18Ub.d.ts +0 -106
package/src/log.test.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { describe, it, expect, vi } from 'vitest';
2
- import { createLogger } from './log';
2
+ import { createLogger, withVerbose, type LogRecord } from './log';
3
3
 
4
4
  function makeStderr(): { write: ReturnType<typeof vi.fn>; captured: () => string } {
5
5
  const chunks: string[] = [];
@@ -143,3 +143,272 @@ describe('log key-value edge cases', () => {
143
143
  });
144
144
  });
145
145
  });
146
+
147
+ // ---------------------------------------------------------------------------
148
+ // Default output regression — no options must stay byte-identical
149
+ // ---------------------------------------------------------------------------
150
+
151
+ describe('log default output (regression pin)', () => {
152
+ it('writes exact LEVEL msg k=v lines to process.stderr', () => {
153
+ withStderr((captured) => {
154
+ const log = createLogger({ noColor: true });
155
+ log.info('start', 'port', 8080, 'path', '/my dir');
156
+ log.warn('w');
157
+ log.error('e', 'code', 2);
158
+ log.debug('d');
159
+ expect(captured()).toBe(
160
+ 'INFO start port=8080 path="/my dir"\n'
161
+ + 'WARN w\n'
162
+ + 'ERRO e code=2\n'
163
+ + 'DEBU d\n',
164
+ );
165
+ });
166
+ });
167
+
168
+ it('keeps the themed ANSI prefixes when no option is passed', () => {
169
+ withStderr((captured) => {
170
+ const log = createLogger();
171
+ log.info('i');
172
+ log.error('e');
173
+ expect(captured()).toBe(
174
+ '\x1b[38;2;133;129;131mINFO\x1b[0m i\n'
175
+ + '\x1b[1m\x1b[38;2;237;74;94mERRO\x1b[0m\x1b[22m e\n',
176
+ );
177
+ });
178
+ });
179
+ });
180
+
181
+ // ---------------------------------------------------------------------------
182
+ // Injectable output stream
183
+ // ---------------------------------------------------------------------------
184
+
185
+ describe('log output option', () => {
186
+ function sink(): { output: { write(chunk: string): boolean }; text: () => string } {
187
+ const chunks: string[] = [];
188
+ return {
189
+ output: { write: (chunk: string) => { chunks.push(chunk); return true; } },
190
+ text: () => chunks.join(''),
191
+ };
192
+ }
193
+
194
+ it('createLogger writes to the injected output, not stderr', () => {
195
+ withStderr((captured) => {
196
+ const s = sink();
197
+ const log = createLogger({ noColor: true, output: s.output });
198
+ log.info('hello', 'k', 'v');
199
+ expect(s.text()).toBe('INFO hello k=v\n');
200
+ expect(captured()).toBe('');
201
+ });
202
+ });
203
+
204
+ it('withVerbose writes to the injected output, not stderr', () => {
205
+ withStderr((captured) => {
206
+ const s = sink();
207
+ const log = withVerbose({ noColor: true, verbose: 1, output: s.output });
208
+ log.debug('dbg');
209
+ expect(s.text()).toBe('DEBU dbg\n');
210
+ expect(captured()).toBe('');
211
+ });
212
+ });
213
+
214
+ it('injected output still honors quiet', () => {
215
+ const s = sink();
216
+ const log = createLogger({ quiet: true, noColor: true, output: s.output });
217
+ log.info('hidden');
218
+ log.warn('shown');
219
+ expect(s.text()).toBe('WARN shown\n');
220
+ });
221
+ });
222
+
223
+ // ---------------------------------------------------------------------------
224
+ // Shared sink helper for option tests
225
+ // ---------------------------------------------------------------------------
226
+
227
+ function capture(): { output: { write(chunk: string): boolean }; text: () => string } {
228
+ const chunks: string[] = [];
229
+ return {
230
+ output: { write: (chunk: string) => { chunks.push(chunk); return true; } },
231
+ text: () => chunks.join(''),
232
+ };
233
+ }
234
+
235
+ function emitAll(log: ReturnType<typeof createLogger>): void {
236
+ log.trace('t');
237
+ log.debug('d');
238
+ log.info('i');
239
+ log.warn('w');
240
+ log.error('e');
241
+ }
242
+
243
+ // ---------------------------------------------------------------------------
244
+ // level option
245
+ // ---------------------------------------------------------------------------
246
+
247
+ describe('log level option', () => {
248
+ it('sets the threshold on createLogger', () => {
249
+ const s = capture();
250
+ emitAll(createLogger({ noColor: true, output: s.output, level: 'warn' }));
251
+ expect(s.text()).toBe('WARN w\nERRO e\n');
252
+ });
253
+
254
+ it('can lower createLogger below its debug default', () => {
255
+ const s = capture();
256
+ emitAll(createLogger({ noColor: true, output: s.output, level: 'trace' }));
257
+ expect(s.text()).toBe('TRAC t\nDEBU d\nINFO i\nWARN w\nERRO e\n');
258
+ });
259
+
260
+ it('wins over the verbose count on withVerbose', () => {
261
+ const s = capture();
262
+ emitAll(withVerbose({ noColor: true, output: s.output, verbose: 2, level: 'error' }));
263
+ expect(s.text()).toBe('ERRO e\n');
264
+ });
265
+
266
+ it("'silent' drops everything", () => {
267
+ const s = capture();
268
+ emitAll(createLogger({ output: s.output, level: 'silent' }));
269
+ emitAll(withVerbose({ output: s.output, verbose: 2, level: 'silent' }));
270
+ expect(s.text()).toBe('');
271
+ });
272
+
273
+ it('quiet only raises: lower level is lifted to warn', () => {
274
+ const s = capture();
275
+ emitAll(createLogger({ noColor: true, output: s.output, level: 'debug', quiet: true }));
276
+ expect(s.text()).toBe('WARN w\nERRO e\n');
277
+ });
278
+
279
+ it('quiet never lowers: error and silent stay put', () => {
280
+ const s = capture();
281
+ emitAll(createLogger({ noColor: true, output: s.output, level: 'error', quiet: true }));
282
+ emitAll(createLogger({ noColor: true, output: s.output, level: 'silent', quiet: true }));
283
+ expect(s.text()).toBe('ERRO e\n');
284
+ });
285
+ });
286
+
287
+ // ---------------------------------------------------------------------------
288
+ // success
289
+ // ---------------------------------------------------------------------------
290
+
291
+ describe('log success', () => {
292
+ it('renders SUCC label with key-values', () => {
293
+ const s = capture();
294
+ createLogger({ noColor: true, output: s.output }).success('deployed', 'env', 'prod');
295
+ expect(s.text()).toBe('SUCC deployed env=prod\n');
296
+ });
297
+
298
+ it('uses the theme success colour (Guac #52CF84), not bold', () => {
299
+ const s = capture();
300
+ createLogger({ output: s.output }).success('ok');
301
+ expect(s.text()).toBe('\x1b[38;2;82;207;132mSUCC\x1b[0m ok\n');
302
+ });
303
+
304
+ it('is filtered exactly like info', () => {
305
+ const s = capture();
306
+ createLogger({ noColor: true, output: s.output, level: 'info' }).success('a');
307
+ withVerbose({ noColor: true, output: s.output }).success('b');
308
+ createLogger({ noColor: true, output: s.output, quiet: true }).success('hidden');
309
+ createLogger({ noColor: true, output: s.output, level: 'warn' }).success('hidden');
310
+ expect(s.text()).toBe('SUCC a\nSUCC b\n');
311
+ });
312
+ });
313
+
314
+ // ---------------------------------------------------------------------------
315
+ // format: 'json' (charm JSONFormatter shape)
316
+ // ---------------------------------------------------------------------------
317
+
318
+ describe("log format: 'json'", () => {
319
+ it('emits {"level","msg",...kv} with no time/pid/hostname or ANSI', () => {
320
+ const s = capture();
321
+ createLogger({ format: 'json', output: s.output })
322
+ .info('start', 'port', 8080, 'path', '/my dir', 'ok', true);
323
+ expect(s.text()).toBe('{"level":"info","msg":"start","port":8080,"path":"/my dir","ok":true}\n');
324
+ });
325
+
326
+ it('uses charm level strings', () => {
327
+ const s = capture();
328
+ emitAll(createLogger({ format: 'json', output: s.output, level: 'trace' }));
329
+ expect(s.text()).toBe(
330
+ '{"level":"trace","msg":"t"}\n'
331
+ + '{"level":"debug","msg":"d"}\n'
332
+ + '{"level":"info","msg":"i"}\n'
333
+ + '{"level":"warn","msg":"w"}\n'
334
+ + '{"level":"error","msg":"e"}\n',
335
+ );
336
+ });
337
+
338
+ it('marks success as level info + kind success', () => {
339
+ const s = capture();
340
+ createLogger({ format: 'json', output: s.output }).success('deployed', 'env', 'prod');
341
+ expect(s.text()).toBe('{"level":"info","msg":"deployed","kind":"success","env":"prod"}\n');
342
+ });
343
+
344
+ it('honors level filtering and withVerbose', () => {
345
+ const s = capture();
346
+ const log = withVerbose({ format: 'json', output: s.output, quiet: true });
347
+ log.info('hidden');
348
+ log.warn('shown');
349
+ expect(s.text()).toBe('{"level":"warn","msg":"shown"}\n');
350
+ });
351
+
352
+ it("format: 'text' is the default line format", () => {
353
+ const s = capture();
354
+ createLogger({ format: 'text', noColor: true, output: s.output }).info('x', 'k', 1);
355
+ expect(s.text()).toBe('INFO x k=1\n');
356
+ });
357
+ });
358
+
359
+ // ---------------------------------------------------------------------------
360
+ // formatter hook
361
+ // ---------------------------------------------------------------------------
362
+
363
+ describe('log formatter hook', () => {
364
+ const GLYPHS: Record<string, string> = { info: 'ℹ', warn: '▲', error: '●' };
365
+ const glyph = (rec: LogRecord): string =>
366
+ `${rec.kind === 'success' ? '✓' : GLYPHS[rec.level] ?? '·'} ${rec.msg}`;
367
+
368
+ it('writes the returned string, appending a missing newline', () => {
369
+ const s = capture();
370
+ const log = createLogger({ output: s.output, formatter: glyph });
371
+ log.info('hi');
372
+ log.success('done');
373
+ log.error('boom');
374
+ expect(s.text()).toBe('ℹ hi\n✓ done\n● boom\n');
375
+ });
376
+
377
+ it('does not double an existing trailing newline', () => {
378
+ const s = capture();
379
+ createLogger({ output: s.output, formatter: (r) => `${r.msg}\n` }).info('x');
380
+ expect(s.text()).toBe('x\n');
381
+ });
382
+
383
+ it('receives level, msg, fields and kind', () => {
384
+ const recs: LogRecord[] = [];
385
+ const log = createLogger({
386
+ output: capture().output,
387
+ formatter: (r) => { recs.push(r); return ''; },
388
+ });
389
+ log.warn('w', 'port', 8080, 'host', 'h');
390
+ log.success('s');
391
+ expect(recs).toEqual([
392
+ { level: 'warn', msg: 'w', fields: { port: 8080, host: 'h' } },
393
+ { level: 'info', msg: 's', fields: {}, kind: 'success' },
394
+ ]);
395
+ });
396
+
397
+ it('wins over format and noColor', () => {
398
+ const s = capture();
399
+ const log = withVerbose({
400
+ output: s.output, format: 'json', noColor: false, formatter: (r) => `[${r.level}] ${r.msg}`,
401
+ });
402
+ log.info('plain');
403
+ expect(s.text()).toBe('[info] plain\n');
404
+ });
405
+
406
+ it('is not called for filtered lines', () => {
407
+ const s = capture();
408
+ const log = createLogger({ output: s.output, quiet: true, formatter: (r) => r.msg });
409
+ log.info('hidden');
410
+ log.success('hidden');
411
+ log.warn('shown');
412
+ expect(s.text()).toBe('shown\n');
413
+ });
414
+ });
package/src/log.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Structured logger wrapping pino — applies kit's charmtone theme
3
- * colors to stderr output.
3
+ * colors to stderr output (or an injected `output` sink).
4
4
  *
5
5
  * API: `logger.info('msg', 'key', val, 'key2', val2)` (variadic key-value)
6
6
  * This matches Go's charm/log API, not pino's native object API.
@@ -25,11 +25,64 @@ export interface Logger {
25
25
  error(msg: string, ...keyvals: any[]): void;
26
26
  debug(msg: string, ...keyvals: any[]): void;
27
27
  trace(msg: string, ...keyvals: any[]): void;
28
+ /**
29
+ * Info-level line marked as a success: label `SUCC` in the theme's
30
+ * success colour. Filtered exactly like `info` (not a new level).
31
+ */
32
+ success(msg: string, ...keyvals: any[]): void;
28
33
  }
29
34
 
35
+ /** Minimal sink the logger writes rendered lines to. */
36
+ export interface LogOutput {
37
+ write(chunk: string): unknown;
38
+ }
39
+
40
+ /** Kit level vocabulary (same spellings as Go/py and `parity.json`). */
41
+ export type LogLevelName = 'trace' | 'debug' | 'info' | 'warn' | 'error' | 'fatal';
42
+
43
+ /** One log line, as handed to a custom `formatter`. */
44
+ export interface LogRecord {
45
+ level: LogLevelName;
46
+ msg: string;
47
+ /** Key-value pairs in call order (after pino serialization). */
48
+ fields: Record<string, unknown>;
49
+ /** Set on `success()` lines, whose `level` is `'info'`. */
50
+ kind?: 'success';
51
+ }
52
+
53
+ /** Renders a record to one line; a missing trailing newline is appended. */
54
+ export type LogFormatter = (rec: LogRecord) => string;
55
+
30
56
  export interface LoggerOptions {
31
57
  quiet?: boolean;
32
58
  noColor?: boolean;
59
+ /**
60
+ * Explicit threshold; wins over the factory default and the `-V` count.
61
+ * `'silent'` drops everything. `quiet` only raises it (to the contract's
62
+ * `quiet_override`), never lowers it — same as Go's `WithLevel`.
63
+ * TS-only option; not a parity verbosity entry.
64
+ */
65
+ level?: LogLevelName | 'silent';
66
+ /**
67
+ * Where rendered lines go. Defaults to `process.stderr`, resolved at
68
+ * write time. Mirrors Go's `(*log.Logger).SetOutput`; useful for
69
+ * capturing output in tests.
70
+ */
71
+ output?: LogOutput;
72
+ /**
73
+ * Line format. `'text'` (default) is `LEVEL msg k=v`; `'json'` is one
74
+ * object per line shaped like Go charm/log's JSONFormatter:
75
+ * `{"level":"info","msg":"...",...kv}` (no time/pid/hostname, no ANSI).
76
+ * `success` lines carry `"level":"info","kind":"success"`. Selected by
77
+ * this option only — no env var or flag.
78
+ */
79
+ format?: 'text' | 'json';
80
+ /**
81
+ * TS extension point: render each line yourself (glyph prefixes, house
82
+ * styles). The returned string is written as-is, plus `\n` if missing.
83
+ * Wins over `format` and `noColor`; level filtering still applies.
84
+ */
85
+ formatter?: LogFormatter;
33
86
  }
34
87
 
35
88
  // ---------------------------------------------------------------------------
@@ -40,6 +93,7 @@ const CHERRY = [0xed, 0x4a, 0x5e] as const;
40
93
  const YAM = [0xe5, 0xa1, 0x4e] as const;
41
94
  const SQUID = [0x85, 0x81, 0x83] as const;
42
95
  const SMOKE = [0xbf, 0xbc, 0xc8] as const;
96
+ const GUAC = [0x52, 0xcf, 0x84] as const; // theme.success
43
97
 
44
98
  type RGB = readonly [number, number, number];
45
99
 
@@ -55,35 +109,103 @@ function bold(text: string): string {
55
109
  // Kit-themed pino transport
56
110
  // ---------------------------------------------------------------------------
57
111
 
112
+ /**
113
+ * pino level number for `success`. One above info so it passes and drops
114
+ * at exactly the same thresholds as info (no kit level sits at 31).
115
+ */
116
+ const SUCCESS_LEVEL = 31;
117
+
58
118
  const LEVEL_STYLES: Record<number, { label: string; color: RGB; bold: boolean }> = {
59
119
  10: { label: 'TRAC', color: SMOKE, bold: false },
60
120
  20: { label: 'DEBU', color: SMOKE, bold: false },
61
121
  30: { label: 'INFO', color: SQUID, bold: false },
122
+ [SUCCESS_LEVEL]: { label: 'SUCC', color: GUAC, bold: false },
62
123
  40: { label: 'WARN', color: YAM, bold: true },
63
124
  50: { label: 'ERRO', color: CHERRY, bold: true },
64
125
  60: { label: 'ERRO', color: CHERRY, bold: true },
65
126
  };
66
127
 
67
- function kitTransport(noColor: boolean): pino.DestinationStream {
128
+ /** pino level number → kit level name (charm/log spellings). */
129
+ const LEVEL_NAMES: Record<number, LogLevelName> = {
130
+ 10: 'trace', 20: 'debug', 30: 'info', [SUCCESS_LEVEL]: 'info',
131
+ 40: 'warn', 50: 'error', 60: 'fatal',
132
+ };
133
+
134
+ /** pino bookkeeping keys that are never user fields. */
135
+ const RESERVED_KEYS = new Set(['level', 'time', 'pid', 'hostname', 'msg', 'v']);
136
+
137
+ /** A parsed log line, before rendering. */
138
+ interface ParsedRecord extends LogRecord {
139
+ levelNum: number;
140
+ }
141
+
142
+ function parseRecord(chunk: string): ParsedRecord {
143
+ const obj = JSON.parse(chunk);
144
+ const fields: Record<string, unknown> = {};
145
+ for (const [k, v] of Object.entries(obj)) {
146
+ if (!RESERVED_KEYS.has(k)) fields[k] = v;
147
+ }
148
+ const levelNum = LEVEL_STYLES[obj.level] ? obj.level : 30;
149
+ return {
150
+ levelNum,
151
+ level: LEVEL_NAMES[levelNum],
152
+ msg: obj.msg ?? '',
153
+ fields,
154
+ ...(levelNum === SUCCESS_LEVEL ? { kind: 'success' as const } : {}),
155
+ };
156
+ }
157
+
158
+ function renderText(rec: ParsedRecord, noColor: boolean): string {
159
+ const style = LEVEL_STYLES[rec.levelNum];
160
+ let prefix = noColor ? style.label : fg(style.color, style.label);
161
+ if (style.bold && !noColor) prefix = bold(prefix);
162
+
163
+ const kvParts: string[] = [];
164
+ for (const [k, v] of Object.entries(rec.fields)) {
165
+ const sv = String(v);
166
+ kvParts.push(sv.includes(' ') ? `${k}="${sv}"` : `${k}=${sv}`);
167
+ }
168
+ const kv = kvParts.length ? ' ' + kvParts.join(' ') : '';
169
+ return `${prefix} ${rec.msg}${kv}\n`;
170
+ }
171
+
172
+ function renderJSON(rec: ParsedRecord): string {
173
+ const out: Record<string, unknown> = { level: rec.level, msg: rec.msg };
174
+ if (rec.kind) out.kind = rec.kind;
175
+ Object.assign(out, rec.fields);
176
+ if (rec.kind) out.kind = rec.kind; // a user `kind` field never masks it
177
+ return JSON.stringify(out) + '\n';
178
+ }
179
+
180
+ function renderCustom(rec: ParsedRecord, formatter: LogFormatter): string {
181
+ const { levelNum: _levelNum, ...pub } = rec;
182
+ const line = formatter(pub);
183
+ return line.endsWith('\n') ? line : line + '\n';
184
+ }
185
+
186
+ interface TransportOptions {
187
+ noColor: boolean;
188
+ format: 'text' | 'json';
189
+ formatter?: LogFormatter;
190
+ output?: LogOutput;
191
+ }
192
+
193
+ function render(rec: ParsedRecord, o: TransportOptions): string {
194
+ if (o.formatter) return renderCustom(rec, o.formatter);
195
+ return o.format === 'json' ? renderJSON(rec) : renderText(rec, o.noColor);
196
+ }
197
+
198
+ function kitTransport(o: TransportOptions): pino.DestinationStream {
199
+ // Resolve the default lazily so callers that swap process.stderr after
200
+ // construction keep seeing their writes.
201
+ const out = (): LogOutput => o.output ?? process.stderr;
68
202
  return {
69
203
  write(chunk: string): void {
70
204
  try {
71
- const obj = JSON.parse(chunk);
72
- const style = LEVEL_STYLES[obj.level] ?? LEVEL_STYLES[30];
73
- let prefix = noColor ? style.label : fg(style.color, style.label);
74
- if (style.bold && !noColor) prefix = bold(prefix);
75
-
76
- const msg = obj.msg ?? '';
77
- const kvParts: string[] = [];
78
- for (const [k, v] of Object.entries(obj)) {
79
- if (['level', 'time', 'pid', 'hostname', 'msg', 'v'].includes(k)) continue;
80
- const sv = String(v);
81
- kvParts.push(sv.includes(' ') ? `${k}="${sv}"` : `${k}=${sv}`);
82
- }
83
- const kv = kvParts.length ? ' ' + kvParts.join(' ') : '';
84
- process.stderr.write(`${prefix} ${msg}${kv}\n`);
205
+ const rec = parseRecord(chunk);
206
+ out().write(render(rec, o));
85
207
  } catch {
86
- process.stderr.write(chunk);
208
+ out().write(chunk);
87
209
  }
88
210
  },
89
211
  };
@@ -155,17 +277,28 @@ export function quietLevel(d: ParityData): string {
155
277
  // Factory
156
278
  // ---------------------------------------------------------------------------
157
279
 
158
- export function createLogger(opts?: LoggerOptions): Logger {
159
- const quiet = opts?.quiet ?? false;
160
- const noColor = opts?.noColor ?? false;
280
+ const LEVEL_RANK: Record<string, number> = {
281
+ trace: 10, debug: 20, info: 30, warn: 40, error: 50, fatal: 60, silent: Infinity,
282
+ };
161
283
 
162
- // Note: the non-quiet level here is `debug`, NOT the contract's
163
- // zero-verbosity level. createLogger predates the verbosity contract and
164
- // is deliberately chattier than `withVerbose({ verbose: 0 })`; only the
165
- // quiet override is contract-declared, so only it is wired.
166
- const p = pino({
167
- level: quiet ? quietLevel(parity) : 'debug',
168
- }, kitTransport(noColor));
284
+ /** Apply `quiet` to a threshold: raise to the quiet override, never lower. */
285
+ function applyQuiet(level: string, quiet: boolean): string {
286
+ if (!quiet) return level;
287
+ const q = quietLevel(parity);
288
+ return LEVEL_RANK[level] < LEVEL_RANK[q] ? q : level;
289
+ }
290
+
291
+ function build(opts: LoggerOptions, defaultLevel: string): Logger {
292
+ const level = applyQuiet(opts.level ?? defaultLevel, opts.quiet ?? false);
293
+ const p = pino<'success'>(
294
+ { level, customLevels: { success: SUCCESS_LEVEL } },
295
+ kitTransport({
296
+ noColor: opts.noColor ?? false,
297
+ format: opts.format ?? 'text',
298
+ formatter: opts.formatter,
299
+ output: opts.output,
300
+ }),
301
+ );
169
302
 
170
303
  return {
171
304
  info: (msg, ...kv) => p.info(kvToObj(kv), msg),
@@ -173,34 +306,29 @@ export function createLogger(opts?: LoggerOptions): Logger {
173
306
  error: (msg, ...kv) => p.error(kvToObj(kv), msg),
174
307
  debug: (msg, ...kv) => p.debug(kvToObj(kv), msg),
175
308
  trace: (msg, ...kv) => p.trace(kvToObj(kv), msg),
309
+ success: (msg, ...kv) => p.success(kvToObj(kv), msg),
176
310
  };
177
311
  }
178
312
 
313
+ export function createLogger(opts?: LoggerOptions): Logger {
314
+ // Note: the default level here is `debug`, NOT the contract's
315
+ // zero-verbosity level. createLogger predates the verbosity contract and
316
+ // is deliberately chattier than `withVerbose({ verbose: 0 })`; only the
317
+ // quiet override is contract-declared, so only it is wired.
318
+ return build(opts ?? {}, 'debug');
319
+ }
320
+
179
321
  // ---------------------------------------------------------------------------
180
322
  // Verbose-aware factory
181
323
  // ---------------------------------------------------------------------------
182
324
 
183
325
  /**
184
326
  * Map verbose count to a pino level through the parity contract's
185
- * `verbosity.levels` table. Quiet overrides to the contract's
186
- * `quiet_override` level regardless of verbose count.
327
+ * `verbosity.levels` table. An explicit `level` wins over the count.
328
+ * Quiet raises to the contract's `quiet_override` level.
187
329
  */
188
330
  export function withVerbose(
189
331
  opts: LoggerOptions & { verbose?: number },
190
332
  ): Logger {
191
- const quiet = opts.quiet ?? false;
192
- const noColor = opts.noColor ?? false;
193
- const v = opts.verbose ?? 0;
194
-
195
- const level = quiet ? quietLevel(parity) : verbosityLevel(parity, v);
196
-
197
- const p = pino({ level }, kitTransport(noColor));
198
-
199
- return {
200
- info: (msg, ...kv) => p.info(kvToObj(kv), msg),
201
- warn: (msg, ...kv) => p.warn(kvToObj(kv), msg),
202
- error: (msg, ...kv) => p.error(kvToObj(kv), msg),
203
- debug: (msg, ...kv) => p.debug(kvToObj(kv), msg),
204
- trace: (msg, ...kv) => p.trace(kvToObj(kv), msg),
205
- };
333
+ return build(opts, verbosityLevel(parity, opts.verbose ?? 0));
206
334
  }
@@ -50,10 +50,28 @@ function consumerSource(): string {
50
50
  return `${imports}
51
51
  import type { CliError } from '${pkg.name}/output';
52
52
  import { output } from '${pkg.name}';
53
+ import { createLogger, type Logger } from '${pkg.name}/log';
54
+ import { completionCommand, generateBashCompletion } from '${pkg.name}/completion';
55
+ import { CompletionRegistry, staticValues, type Completer } from '${pkg.name}/completion-values';
56
+ import { loadToolSpec, type ToolSpec } from '${pkg.name}/toolspec';
57
+ import { Factor, formatReport, type Report } from '${pkg.name}/compliance';
58
+ import { compliance, completion, completionValues, log, toolspec } from '${pkg.name}';
53
59
 
54
60
  // Types re-exported through the root barrel's namespaces must stay types.
55
61
  export const viaSubpath: CliError | null = output.wrapError(new Error('x'), output.CODE_GENERIC, output.EXIT_GENERIC);
56
62
  export const viaNamespace: output.CliError | null = viaSubpath;
63
+
64
+ // Named symbols adopters import; pinned so dropping a subpath from the
65
+ // exports map (which also drops it from the loop above) still fails.
66
+ export const logger: Logger = createLogger();
67
+ export const logNs: log.Logger = log.createLogger();
68
+ export const completionFns = [completionCommand, generateBashCompletion, completion.generateZshCompletion];
69
+ export const completer: Completer = staticValues('a');
70
+ export const registry: completionValues.CompletionRegistry = new CompletionRegistry();
71
+ export const loadSpec: (p: string) => ToolSpec = loadToolSpec;
72
+ export const loadSpecNs: (p: string) => toolspec.ToolSpec = toolspec.loadToolSpec;
73
+ export const report = (r: Report): string => formatReport(r, 'json');
74
+ export const factor: compliance.Factor = Factor.SelfDescribing;
57
75
  export const all = [${specs.map((_, i) => `m${i}`).join(', ')}];
58
76
  `;
59
77
  }