@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.
- package/CHANGELOG.md +107 -0
- package/README.md +333 -9
- package/dist/aim-CTp-kJW2.d.ts +139 -0
- package/dist/aim.d.ts +1 -116
- package/dist/alias-dhhr08Ei.d.ts +88 -0
- package/dist/alias.d.ts +2 -73
- package/dist/api-miiso81x.d.ts +77 -0
- package/dist/api.d.ts +1 -62
- package/dist/auth-2-jfgiHn.d.ts +34 -0
- package/dist/auth.d.ts +1 -26
- package/dist/cli-DLygZLi9.d.ts +450 -0
- package/dist/cli.d.ts +6 -309
- package/dist/cli.js +192 -63
- package/dist/config-BUY7_W2n.d.ts +103 -0
- package/dist/config.d.ts +1 -97
- package/dist/errcorrect-BcX1Ft0K.d.ts +44 -0
- package/dist/errcorrect.d.ts +1 -37
- package/dist/error-DISJKeDu.d.ts +144 -0
- package/dist/id/index.d.ts +2 -83
- package/dist/index-Bc5c7Ty5.d.ts +328 -0
- package/dist/index-C3Zw4wDJ.d.ts +359 -0
- package/dist/index-MLrRDvEG.d.ts +1073 -0
- package/dist/index-QSffbLnj.d.ts +94 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.js +6794 -0
- package/dist/llm-B5XUWH8T.d.ts +231 -0
- package/dist/llm.d.ts +1 -188
- package/dist/mcp/index.d.ts +2 -0
- package/dist/mcp/index.js +1453 -0
- package/dist/netpolicy-asvCfwi8.d.ts +138 -0
- package/dist/netpolicy.d.ts +1 -0
- package/dist/netpolicy.js +118 -0
- package/dist/output-4aXs91GY.d.ts +396 -0
- package/dist/output.d.ts +3 -213
- package/dist/output.js +567 -43
- package/dist/progress-CAzyxeWl.d.ts +38 -0
- package/dist/progress.d.ts +1 -30
- package/dist/provenance-SMFHm5gx.d.ts +30 -0
- package/dist/provenance.d.ts +1 -24
- package/dist/routellm-PGSt2D1y.d.ts +75 -0
- package/dist/routellm.d.ts +2 -64
- package/dist/rpc-D5xLEf8V.d.ts +32 -0
- package/dist/rpc.d.ts +2 -25
- package/dist/safety-CUaYEjZc.d.ts +30 -0
- package/dist/safety.d.ts +1 -24
- package/dist/scope-BrhYB4ij.d.ts +141 -0
- package/dist/scope.d.ts +1 -121
- package/dist/serve-DE-jscpb.d.ts +646 -0
- package/dist/serve.d.ts +3 -0
- package/dist/serve.js +1019 -0
- package/dist/stream-CrjeCp0M.d.ts +44 -0
- package/dist/stream.d.ts +1 -35
- package/dist/telemetry/index.d.ts +1 -315
- package/dist/telemetry/index.js +12 -1
- package/dist/tui/index.d.ts +5 -298
- package/dist/tui/index.js +3 -10
- package/dist/upgrade-p_zh3pvV.d.ts +102 -0
- package/dist/upgrade.d.ts +1 -95
- package/dist/xdg-DB7Shoib.d.ts +179 -0
- package/dist/xdg.d.ts +1 -169
- package/package.json +26 -3
- package/src/cli.offline.test.ts +93 -0
- package/src/cli.parity.test.ts +192 -0
- package/src/cli.ts +112 -12
- package/src/index.test.ts +58 -0
- package/src/index.ts +37 -0
- package/src/log.parity.test.ts +105 -0
- package/src/log.ts +64 -13
- package/src/mcp/bridge.test.ts +150 -0
- package/src/mcp/bridge.ts +246 -0
- package/src/mcp/conformance.test.ts +336 -0
- package/src/mcp/dispatch.ts +313 -0
- package/src/mcp/index.ts +138 -0
- package/src/mcp/legacy.ts +314 -0
- package/src/mcp/mcp.test.ts +697 -0
- package/src/mcp/modern-confirm.test.ts +520 -0
- package/src/mcp/modern-confirm.ts +452 -0
- package/src/mcp/modern.ts +723 -0
- package/src/mcp/tasks.ts +82 -0
- package/src/mcp/testtree.ts +250 -0
- package/src/mcp/types.ts +504 -0
- package/src/netpolicy.test.ts +202 -0
- package/src/netpolicy.ts +231 -0
- package/src/output/dispatch.ts +10 -2
- package/src/output/error.ts +316 -0
- package/src/output/formatter.ts +29 -5
- package/src/output/formatters/csv.ts +48 -12
- package/src/output/formatters/json.ts +4 -25
- package/src/output/formatters/project.ts +34 -0
- package/src/output/formatters/table.ts +8 -6
- package/src/output/formatters/text.ts +7 -3
- package/src/output/formatters/yaml.ts +5 -22
- package/src/output/projection.test.ts +298 -0
- package/src/output/projection.ts +33 -59
- package/src/output/template.ts +11 -21
- package/src/output.surface.test.ts +41 -0
- package/src/output.ts +41 -3
- package/src/serve.test.ts +1257 -0
- package/src/serve.ts +1665 -0
- package/src/telemetry/client.test.ts +31 -0
- package/src/telemetry/client.ts +7 -1
- package/src/telemetry/offline.test.ts +64 -0
- package/src/tui/parity.test.ts +120 -31
- package/src/tui/parity.ts +58 -7
- package/test/output/csv.test.ts +164 -0
- package/test/output/error.test.ts +246 -0
- package/src/tui/parity.json +0 -74
package/src/output/projection.ts
CHANGED
|
@@ -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 (
|
|
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
|
|
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
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
if (
|
|
63
|
-
|
|
64
|
-
|
|
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
|
|
71
|
-
*
|
|
72
|
-
*
|
|
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 (
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
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
|
|
package/src/output/template.ts
CHANGED
|
@@ -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
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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
|
|
32
|
-
*
|
|
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';
|