@hop-top/kit 0.5.0-alpha.1 → 0.5.0-alpha.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.
Files changed (107) hide show
  1. package/CHANGELOG.md +107 -0
  2. package/README.md +333 -9
  3. package/dist/aim-CTp-kJW2.d.ts +139 -0
  4. package/dist/aim.d.ts +1 -116
  5. package/dist/alias-dhhr08Ei.d.ts +88 -0
  6. package/dist/alias.d.ts +2 -73
  7. package/dist/api-miiso81x.d.ts +77 -0
  8. package/dist/api.d.ts +1 -62
  9. package/dist/auth-2-jfgiHn.d.ts +34 -0
  10. package/dist/auth.d.ts +1 -26
  11. package/dist/cli-DLygZLi9.d.ts +450 -0
  12. package/dist/cli.d.ts +6 -309
  13. package/dist/cli.js +192 -63
  14. package/dist/config-BUY7_W2n.d.ts +103 -0
  15. package/dist/config.d.ts +1 -97
  16. package/dist/errcorrect-BcX1Ft0K.d.ts +44 -0
  17. package/dist/errcorrect.d.ts +1 -37
  18. package/dist/error-DISJKeDu.d.ts +144 -0
  19. package/dist/id/index.d.ts +2 -83
  20. package/dist/index-Bc5c7Ty5.d.ts +328 -0
  21. package/dist/index-C3Zw4wDJ.d.ts +359 -0
  22. package/dist/index-MLrRDvEG.d.ts +1073 -0
  23. package/dist/index-QSffbLnj.d.ts +94 -0
  24. package/dist/index.d.ts +28 -0
  25. package/dist/index.js +6794 -0
  26. package/dist/llm-B5XUWH8T.d.ts +231 -0
  27. package/dist/llm.d.ts +1 -188
  28. package/dist/mcp/index.d.ts +2 -0
  29. package/dist/mcp/index.js +1453 -0
  30. package/dist/netpolicy-asvCfwi8.d.ts +138 -0
  31. package/dist/netpolicy.d.ts +1 -0
  32. package/dist/netpolicy.js +118 -0
  33. package/dist/output-4aXs91GY.d.ts +396 -0
  34. package/dist/output.d.ts +3 -213
  35. package/dist/output.js +567 -43
  36. package/dist/progress-CAzyxeWl.d.ts +38 -0
  37. package/dist/progress.d.ts +1 -30
  38. package/dist/provenance-SMFHm5gx.d.ts +30 -0
  39. package/dist/provenance.d.ts +1 -24
  40. package/dist/routellm-PGSt2D1y.d.ts +75 -0
  41. package/dist/routellm.d.ts +2 -64
  42. package/dist/rpc-D5xLEf8V.d.ts +32 -0
  43. package/dist/rpc.d.ts +2 -25
  44. package/dist/safety-CUaYEjZc.d.ts +30 -0
  45. package/dist/safety.d.ts +1 -24
  46. package/dist/scope-BrhYB4ij.d.ts +141 -0
  47. package/dist/scope.d.ts +1 -121
  48. package/dist/serve-DE-jscpb.d.ts +646 -0
  49. package/dist/serve.d.ts +3 -0
  50. package/dist/serve.js +1019 -0
  51. package/dist/stream-CrjeCp0M.d.ts +44 -0
  52. package/dist/stream.d.ts +1 -35
  53. package/dist/telemetry/index.d.ts +1 -315
  54. package/dist/telemetry/index.js +12 -1
  55. package/dist/tui/index.d.ts +5 -298
  56. package/dist/tui/index.js +3 -10
  57. package/dist/upgrade-p_zh3pvV.d.ts +102 -0
  58. package/dist/upgrade.d.ts +1 -95
  59. package/dist/xdg-DB7Shoib.d.ts +179 -0
  60. package/dist/xdg.d.ts +1 -169
  61. package/package.json +26 -3
  62. package/src/cli.offline.test.ts +93 -0
  63. package/src/cli.parity.test.ts +192 -0
  64. package/src/cli.ts +112 -12
  65. package/src/index.test.ts +58 -0
  66. package/src/index.ts +37 -0
  67. package/src/log.parity.test.ts +105 -0
  68. package/src/log.ts +64 -13
  69. package/src/mcp/bridge.test.ts +150 -0
  70. package/src/mcp/bridge.ts +246 -0
  71. package/src/mcp/conformance.test.ts +336 -0
  72. package/src/mcp/dispatch.ts +313 -0
  73. package/src/mcp/index.ts +138 -0
  74. package/src/mcp/legacy.ts +314 -0
  75. package/src/mcp/mcp.test.ts +697 -0
  76. package/src/mcp/modern-confirm.test.ts +520 -0
  77. package/src/mcp/modern-confirm.ts +452 -0
  78. package/src/mcp/modern.ts +723 -0
  79. package/src/mcp/tasks.ts +82 -0
  80. package/src/mcp/testtree.ts +250 -0
  81. package/src/mcp/types.ts +504 -0
  82. package/src/netpolicy.test.ts +202 -0
  83. package/src/netpolicy.ts +231 -0
  84. package/src/output/dispatch.ts +10 -2
  85. package/src/output/error.ts +316 -0
  86. package/src/output/formatter.ts +29 -5
  87. package/src/output/formatters/csv.ts +48 -12
  88. package/src/output/formatters/json.ts +4 -25
  89. package/src/output/formatters/project.ts +34 -0
  90. package/src/output/formatters/table.ts +8 -6
  91. package/src/output/formatters/text.ts +7 -3
  92. package/src/output/formatters/yaml.ts +5 -22
  93. package/src/output/projection.test.ts +298 -0
  94. package/src/output/projection.ts +33 -59
  95. package/src/output/template.ts +11 -21
  96. package/src/output.surface.test.ts +41 -0
  97. package/src/output.ts +41 -3
  98. package/src/serve.test.ts +1257 -0
  99. package/src/serve.ts +1665 -0
  100. package/src/telemetry/client.test.ts +31 -0
  101. package/src/telemetry/client.ts +7 -1
  102. package/src/telemetry/offline.test.ts +64 -0
  103. package/src/tui/parity.test.ts +120 -31
  104. package/src/tui/parity.ts +58 -7
  105. package/test/output/csv.test.ts +164 -0
  106. package/test/output/error.test.ts +246 -0
  107. package/src/tui/parity.json +0 -74
@@ -2,14 +2,19 @@
2
2
  * @module output/projection
3
3
  *
4
4
  * Helpers for projecting structured data through ColumnSpec lists. Mirrors
5
- * Go's projection.go (filterColumns / projectToMaps / TableHeaders).
5
+ * Go's projection.go (projectToMaps / TableHeaders).
6
6
  *
7
7
  * Unlike Go (which uses `table:""` struct tags), TS callers pass an explicit
8
8
  * ColumnSpec[] list. When no columns are provided, callers fall back to
9
9
  * deriving headers from the first row's own enumerable keys.
10
+ *
11
+ * A ColumnSpec's `header` and `key` are the same name: validation and value
12
+ * lookup are one operation, matching what Go's `table:""` tag can express.
13
+ * `--cols` reorders as well as selects, so the user's order wins over the
14
+ * ColumnSpec list's.
10
15
  */
11
16
 
12
- import type { ColumnSpec } from './formatter';
17
+ import { columnName, type ColumnSpec } from './formatter';
13
18
 
14
19
  /** Normalises data into a readonly array of plain objects (rows). */
15
20
  export function normaliseRows<T>(data: T | readonly T[]): readonly T[] {
@@ -31,74 +36,43 @@ export function deriveHeaders(
31
36
  }
32
37
 
33
38
  /**
34
- * Filters a ColumnSpec list to those whose `header` appears in `selected`.
35
- * Order is preserved from `columns` (caller's intended order). Unknown
36
- * names in `selected` throw with the available header list.
37
- */
38
- export function filterColumns(
39
- columns: readonly ColumnSpec[],
40
- selected: readonly string[],
41
- ): readonly ColumnSpec[] {
42
- const have = new Set(columns.map(c => c.header));
43
- for (const name of selected) {
44
- if (!have.has(name)) {
45
- const valid = columns.map(c => c.header).join(', ');
46
- throw new Error(`unknown column "${name}" (valid: ${valid})`);
47
- }
48
- }
49
- const want = new Set(selected);
50
- return columns.filter(c => want.has(c.header));
51
- }
52
-
53
- /**
54
- * Builds a header→key lookup. Used to project rows for json/yaml/csv/text.
55
- * When no ColumnSpec list is provided, headers map to themselves (the row
56
- * already keys by the same names).
39
+ * Resolves the effective column list a formatter should render.
40
+ *
41
+ * Precedence, per the settled ordering contract:
42
+ * - `cols` non-empty → the user's `--cols`, verbatim and in user order
43
+ * (rule 2: --cols reorders as well as selects).
44
+ * - else a ColumnSpec list → its headers, in list order (rule 1).
45
+ * - else → empty, meaning "fall back to payload key order".
46
+ *
47
+ * Because header == key (rule 3), an ordered array of names carries
48
+ * everything a formatter needs: the labels and the row lookup keys are the
49
+ * same strings. Resolving here keeps precedence in one place and leaves the
50
+ * public Formatter signature untouched.
57
51
  */
58
- export function buildHeaderToKey(
59
- columns?: readonly ColumnSpec[],
60
- ): Map<string, string> {
61
- const out = new Map<string, string>();
62
- if (!columns) return out;
63
- for (const c of columns) {
64
- out.set(c.header, c.key);
65
- }
66
- return out;
52
+ export function resolveEffectiveCols(
53
+ cols: readonly string[],
54
+ columns: readonly ColumnSpec[] | undefined,
55
+ ): readonly string[] {
56
+ if (cols.length > 0) return cols;
57
+ if (columns && columns.length > 0) return columns.map(columnName);
58
+ return [];
67
59
  }
68
60
 
69
61
  /**
70
- * Projects rows to plain objects keyed by header, optionally filtered by
71
- * `cols`. When `columns` is undefined, rows are returned as-is for JSON/
72
- * YAML pass-through. When `cols` is empty AND `columns` is defined,
73
- * every column is included.
62
+ * Projects rows to plain objects keyed by column name, in `cols` order.
63
+ * An empty `cols` passes rows through untouched, so JSON/YAML keep whatever
64
+ * shape the caller handed in.
74
65
  */
75
66
  export function projectRows(
76
67
  rows: readonly unknown[],
77
- columns: readonly ColumnSpec[] | undefined,
78
68
  cols: readonly string[],
79
69
  ): readonly Record<string, unknown>[] {
80
- const active = columns
81
- ? cols.length > 0
82
- ? filterColumns(columns, cols)
83
- : columns
84
- : undefined;
85
-
86
70
  return rows.map(row => {
87
71
  const r = (row ?? {}) as Record<string, unknown>;
88
- if (active) {
89
- const out: Record<string, unknown> = {};
90
- for (const c of active) {
91
- out[c.header] = r[c.key];
92
- }
93
- return out;
94
- }
95
- if (cols.length > 0) {
96
- // No ColumnSpec provided — treat cols as direct keys on the row.
97
- const out: Record<string, unknown> = {};
98
- for (const k of cols) out[k] = r[k];
99
- return out;
100
- }
101
- return r;
72
+ if (cols.length === 0) return r;
73
+ const out: Record<string, unknown> = {};
74
+ for (const name of cols) out[name] = r[name];
75
+ return out;
102
76
  });
103
77
  }
104
78
 
@@ -11,6 +11,7 @@
11
11
 
12
12
  import { Eta } from 'eta';
13
13
  import type { ColumnSpec } from './formatter';
14
+ import { deriveHeaders, projectRows, resolveEffectiveCols } from './projection';
14
15
 
15
16
  const eta = new Eta({ autoEscape: false });
16
17
 
@@ -29,12 +30,16 @@ export async function renderTemplate(
29
30
  columns?: readonly ColumnSpec[],
30
31
  ): Promise<void> {
31
32
  const rows = Array.isArray(data) ? (data as readonly unknown[]) : [data];
32
- const items = projectItems(rows, columns);
33
- const cols = columns
34
- ? columns.map(c => c.header)
35
- : items.length > 0 && typeof items[0] === 'object' && items[0] !== null
36
- ? Object.keys(items[0] as Record<string, unknown>)
37
- : [];
33
+ // Projection applies only when a ColumnSpec list fixes the order; the
34
+ // template's own `cols` binding always resolves to concrete names so
35
+ // `it.cols` stays usable on the payload-key fallback path too.
36
+ const projected = resolveEffectiveCols([], columns);
37
+ const cols = projected.length > 0 ? projected : deriveHeaders(rows);
38
+ // Templates always index items by field, so non-object rows become {}.
39
+ const items = projectRows(
40
+ rows.map(r => (r === null || typeof r !== 'object' ? {} : r)),
41
+ projected,
42
+ );
38
43
  const input = { items, cols, data };
39
44
 
40
45
  let rendered: string;
@@ -46,18 +51,3 @@ export async function renderTemplate(
46
51
  }
47
52
  out.write(rendered);
48
53
  }
49
-
50
- function projectItems(
51
- rows: readonly unknown[],
52
- columns?: readonly ColumnSpec[],
53
- ): readonly Record<string, unknown>[] {
54
- if (!columns) {
55
- return rows.map(r => (r === null || typeof r !== 'object' ? {} : (r as Record<string, unknown>)));
56
- }
57
- return rows.map(row => {
58
- const r = (row ?? {}) as Record<string, unknown>;
59
- const out: Record<string, unknown> = {};
60
- for (const c of columns) out[c.header] = r[c.key];
61
- return out;
62
- });
63
- }
@@ -0,0 +1,41 @@
1
+ import { describe, it, expect } from 'vitest';
2
+ import * as output from './output';
3
+
4
+ /**
5
+ * Guards the public symbol surface of the `./output` subpath export.
6
+ *
7
+ * The exports-map contract test in `index.test.ts` only asserts that each
8
+ * declared subpath has a source file and a build entry — it says nothing
9
+ * about which symbols a subpath exposes. `registerOutputFlags` and
10
+ * `dispatch` were defined under `output/` but never re-exported here, so
11
+ * the README's Commander wiring and the generated cli-ts template both
12
+ * threw `TypeError: registerOutputFlags is not a function` against the
13
+ * published package. `output/` is not itself a published subpath, so
14
+ * consumers had no alternate import path.
15
+ *
16
+ * These names are load-bearing for documented adopter code. Removing one
17
+ * is a breaking change and must fail here first.
18
+ */
19
+ describe('output — documented symbol surface', () => {
20
+ // README "Wiring into a Commander CLI" + templates/cli-ts/src/cli.ts.tmpl.
21
+ it.each(['registerOutputFlags', 'dispatch'])(
22
+ 'exports %s as a function',
23
+ (name) => {
24
+ expect(typeof (output as Record<string, unknown>)[name]).toBe('function');
25
+ },
26
+ );
27
+
28
+ it('exports the rest of the flag-wiring surface', () => {
29
+ expect(typeof output.registryFor).toBe('function');
30
+ expect(typeof output.resolveCols).toBe('function');
31
+ });
32
+
33
+ it('keeps the render shim and format constants', () => {
34
+ expect(typeof output.render).toBe('function');
35
+ expect(output.JSON_FORMAT).toBe('json');
36
+ expect(output.YAML_FORMAT).toBe('yaml');
37
+ expect(output.TABLE_FORMAT).toBe('table');
38
+ expect(output.CSV_FORMAT).toBe('csv');
39
+ expect(output.TEXT_FORMAT).toBe('text');
40
+ });
41
+ });
package/src/output.ts CHANGED
@@ -28,17 +28,55 @@
28
28
  *
29
29
  * ## Backward compatibility
30
30
  *
31
- * `render(w, format, v)` keeps its original signature. New per-format
32
- * options + column projection are accessed via `dispatch()`.
31
+ * `render(w, format, v)` keeps its original signature and renders every
32
+ * column in payload key order. New per-format options and column ordering
33
+ * (ColumnSpec lists, `--cols`) are accessed via `dispatch()`.
33
34
  */
34
35
 
35
36
  // Re-export the typed surface.
36
37
  export type { Formatter, OptionSpec, OptionType, Options, ColumnSpec } from './output/formatter';
37
- export { parseOptions, optionTypeName } from './output/formatter';
38
+ export { parseOptions, optionTypeName, columnName } from './output/formatter';
39
+ export { deriveHeaders, resolveEffectiveCols, projectRows } from './output/projection';
38
40
  export { Registry, defaultRegistry, newRegistry } from './output/registry';
39
41
  export { jsonFormatter } from './output/formatters/json';
40
42
  export { yamlFormatter } from './output/formatters/yaml';
41
43
  export { tableFormatter } from './output/formatters/table';
44
+ export type { RegisterOutputFlagsOptions } from './output/flags';
45
+ export { registerOutputFlags, registryFor, resolveCols } from './output/flags';
46
+ export type { DispatchOptions } from './output/dispatch';
47
+ export { dispatch } from './output/dispatch';
48
+ export type { CliError } from './output/error';
49
+ export {
50
+ CODE_OK,
51
+ CODE_GENERIC,
52
+ CODE_USAGE,
53
+ CODE_NOT_FOUND,
54
+ CODE_CONFLICT,
55
+ CODE_UNAUTHORIZED,
56
+ CODE_TRANSIENT,
57
+ CODE_PROVENANCE_MISSING,
58
+ CODE_RATE_LIMITED,
59
+ EXIT_GENERIC,
60
+ EXIT_TRANSIENT,
61
+ EXIT_RATE_LIMITED,
62
+ EXIT_PROVENANCE_MISSING,
63
+ TRANSIENCE_TRANSIENT,
64
+ TRANSIENCE_PERMANENT,
65
+ TRANSIENCE_UNKNOWN,
66
+ transienceForCode,
67
+ wrapError,
68
+ unwrapError,
69
+ withTransience,
70
+ genericError,
71
+ notFoundError,
72
+ conflictError,
73
+ unauthorizedError,
74
+ usageError,
75
+ transientError,
76
+ rateLimitedError,
77
+ provenanceMissingError,
78
+ renderError,
79
+ } from './output/error';
42
80
 
43
81
  // Side-effect: register built-ins.
44
82
  import './output/builtins';