@getpaseo/cli 0.1.2
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/bin/paseo +2 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +150 -0
- package/dist/cli.js.map +1 -0
- package/dist/commands/agent/archive.d.ts +17 -0
- package/dist/commands/agent/archive.d.ts.map +1 -0
- package/dist/commands/agent/archive.js +91 -0
- package/dist/commands/agent/archive.js.map +1 -0
- package/dist/commands/agent/attach.d.ts +10 -0
- package/dist/commands/agent/attach.d.ts.map +1 -0
- package/dist/commands/agent/attach.js +166 -0
- package/dist/commands/agent/attach.js.map +1 -0
- package/dist/commands/agent/index.d.ts +3 -0
- package/dist/commands/agent/index.d.ts.map +1 -0
- package/dist/commands/agent/index.js +112 -0
- package/dist/commands/agent/index.js.map +1 -0
- package/dist/commands/agent/inspect.d.ts +14 -0
- package/dist/commands/agent/inspect.d.ts.map +1 -0
- package/dist/commands/agent/inspect.js +185 -0
- package/dist/commands/agent/inspect.js.map +1 -0
- package/dist/commands/agent/logs.d.ts +11 -0
- package/dist/commands/agent/logs.d.ts.map +1 -0
- package/dist/commands/agent/logs.js +207 -0
- package/dist/commands/agent/logs.js.map +1 -0
- package/dist/commands/agent/ls.d.ts +34 -0
- package/dist/commands/agent/ls.d.ts.map +1 -0
- package/dist/commands/agent/ls.js +153 -0
- package/dist/commands/agent/ls.js.map +1 -0
- package/dist/commands/agent/mode.d.ts +18 -0
- package/dist/commands/agent/mode.d.ts.map +1 -0
- package/dist/commands/agent/mode.js +97 -0
- package/dist/commands/agent/mode.js.map +1 -0
- package/dist/commands/agent/run.d.ts +27 -0
- package/dist/commands/agent/run.d.ts.map +1 -0
- package/dist/commands/agent/run.js +146 -0
- package/dist/commands/agent/run.js.map +1 -0
- package/dist/commands/agent/send.d.ts +16 -0
- package/dist/commands/agent/send.d.ts.map +1 -0
- package/dist/commands/agent/send.js +172 -0
- package/dist/commands/agent/send.js.map +1 -0
- package/dist/commands/agent/stop.d.ts +16 -0
- package/dist/commands/agent/stop.d.ts.map +1 -0
- package/dist/commands/agent/stop.js +104 -0
- package/dist/commands/agent/stop.js.map +1 -0
- package/dist/commands/agent/wait.d.ts +16 -0
- package/dist/commands/agent/wait.d.ts.map +1 -0
- package/dist/commands/agent/wait.js +171 -0
- package/dist/commands/agent/wait.js.map +1 -0
- package/dist/commands/daemon/index.d.ts +3 -0
- package/dist/commands/daemon/index.d.ts.map +1 -0
- package/dist/commands/daemon/index.js +41 -0
- package/dist/commands/daemon/index.js.map +1 -0
- package/dist/commands/daemon/local-daemon.d.ts +51 -0
- package/dist/commands/daemon/local-daemon.d.ts.map +1 -0
- package/dist/commands/daemon/local-daemon.js +298 -0
- package/dist/commands/daemon/local-daemon.js.map +1 -0
- package/dist/commands/daemon/pair.d.ts +8 -0
- package/dist/commands/daemon/pair.d.ts.map +1 -0
- package/dist/commands/daemon/pair.js +34 -0
- package/dist/commands/daemon/pair.js.map +1 -0
- package/dist/commands/daemon/restart.d.ts +12 -0
- package/dist/commands/daemon/restart.d.ts.map +1 -0
- package/dist/commands/daemon/restart.js +97 -0
- package/dist/commands/daemon/restart.js.map +1 -0
- package/dist/commands/daemon/start.d.ts +6 -0
- package/dist/commands/daemon/start.d.ts.map +1 -0
- package/dist/commands/daemon/start.js +121 -0
- package/dist/commands/daemon/start.js.map +1 -0
- package/dist/commands/daemon/status.d.ts +10 -0
- package/dist/commands/daemon/status.d.ts.map +1 -0
- package/dist/commands/daemon/status.js +119 -0
- package/dist/commands/daemon/status.js.map +1 -0
- package/dist/commands/daemon/stop.d.ts +12 -0
- package/dist/commands/daemon/stop.d.ts.map +1 -0
- package/dist/commands/daemon/stop.js +56 -0
- package/dist/commands/daemon/stop.js.map +1 -0
- package/dist/commands/permit/allow.d.ts +20 -0
- package/dist/commands/permit/allow.d.ts.map +1 -0
- package/dist/commands/permit/allow.js +133 -0
- package/dist/commands/permit/allow.js.map +1 -0
- package/dist/commands/permit/deny.d.ts +12 -0
- package/dist/commands/permit/deny.d.ts.map +1 -0
- package/dist/commands/permit/deny.js +105 -0
- package/dist/commands/permit/deny.js.map +1 -0
- package/dist/commands/permit/index.d.ts +3 -0
- package/dist/commands/permit/index.d.ts.map +1 -0
- package/dist/commands/permit/index.js +37 -0
- package/dist/commands/permit/index.js.map +1 -0
- package/dist/commands/permit/ls.d.ts +18 -0
- package/dist/commands/permit/ls.d.ts.map +1 -0
- package/dist/commands/permit/ls.js +65 -0
- package/dist/commands/permit/ls.js.map +1 -0
- package/dist/commands/provider/index.d.ts +3 -0
- package/dist/commands/provider/index.d.ts.map +1 -0
- package/dist/commands/provider/index.js +22 -0
- package/dist/commands/provider/index.js.map +1 -0
- package/dist/commands/provider/ls.d.ts +17 -0
- package/dist/commands/provider/ls.d.ts.map +1 -0
- package/dist/commands/provider/ls.js +51 -0
- package/dist/commands/provider/ls.js.map +1 -0
- package/dist/commands/provider/models.d.ts +16 -0
- package/dist/commands/provider/models.d.ts.map +1 -0
- package/dist/commands/provider/models.js +45 -0
- package/dist/commands/provider/models.js.map +1 -0
- package/dist/commands/speech/download.d.ts +14 -0
- package/dist/commands/speech/download.d.ts.map +1 -0
- package/dist/commands/speech/download.js +46 -0
- package/dist/commands/speech/download.js.map +1 -0
- package/dist/commands/speech/index.d.ts +3 -0
- package/dist/commands/speech/index.d.ts.map +1 -0
- package/dist/commands/speech/index.js +25 -0
- package/dist/commands/speech/index.js.map +1 -0
- package/dist/commands/speech/models.d.ts +16 -0
- package/dist/commands/speech/models.d.ts.map +1 -0
- package/dist/commands/speech/models.js +49 -0
- package/dist/commands/speech/models.js.map +1 -0
- package/dist/commands/worktree/archive.d.ts +16 -0
- package/dist/commands/worktree/archive.d.ts.map +1 -0
- package/dist/commands/worktree/archive.js +98 -0
- package/dist/commands/worktree/archive.js.map +1 -0
- package/dist/commands/worktree/index.d.ts +3 -0
- package/dist/commands/worktree/index.d.ts.map +1 -0
- package/dist/commands/worktree/index.js +22 -0
- package/dist/commands/worktree/index.js.map +1 -0
- package/dist/commands/worktree/ls.d.ts +17 -0
- package/dist/commands/worktree/ls.d.ts.map +1 -0
- package/dist/commands/worktree/ls.js +89 -0
- package/dist/commands/worktree/ls.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -0
- package/dist/output/index.d.ts +45 -0
- package/dist/output/index.d.ts.map +1 -0
- package/dist/output/index.js +47 -0
- package/dist/output/index.js.map +1 -0
- package/dist/output/json.d.ts +11 -0
- package/dist/output/json.d.ts.map +1 -0
- package/dist/output/json.js +37 -0
- package/dist/output/json.js.map +1 -0
- package/dist/output/quiet.d.ts +9 -0
- package/dist/output/quiet.d.ts.map +1 -0
- package/dist/output/quiet.js +22 -0
- package/dist/output/quiet.js.map +1 -0
- package/dist/output/render.d.ts +15 -0
- package/dist/output/render.d.ts.map +1 -0
- package/dist/output/render.js +80 -0
- package/dist/output/render.js.map +1 -0
- package/dist/output/table.d.ts +13 -0
- package/dist/output/table.d.ts.map +1 -0
- package/dist/output/table.js +135 -0
- package/dist/output/table.js.map +1 -0
- package/dist/output/types.d.ts +71 -0
- package/dist/output/types.d.ts.map +1 -0
- package/dist/output/types.js +8 -0
- package/dist/output/types.js.map +1 -0
- package/dist/output/with-output.d.ts +37 -0
- package/dist/output/with-output.d.ts.map +1 -0
- package/dist/output/with-output.js +78 -0
- package/dist/output/with-output.js.map +1 -0
- package/dist/output/yaml.d.ts +11 -0
- package/dist/output/yaml.d.ts.map +1 -0
- package/dist/output/yaml.js +38 -0
- package/dist/output/yaml.js.map +1 -0
- package/dist/utils/client.d.ts +35 -0
- package/dist/utils/client.d.ts.map +1 -0
- package/dist/utils/client.js +110 -0
- package/dist/utils/client.js.map +1 -0
- package/package.json +39 -0
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Main render dispatcher for CLI output.
|
|
3
|
+
*
|
|
4
|
+
* Selects the appropriate renderer based on output options.
|
|
5
|
+
*/
|
|
6
|
+
import chalk from 'chalk';
|
|
7
|
+
import YAML from 'yaml';
|
|
8
|
+
import { renderTable } from './table.js';
|
|
9
|
+
import { renderJson } from './json.js';
|
|
10
|
+
import { renderYaml } from './yaml.js';
|
|
11
|
+
import { renderQuiet } from './quiet.js';
|
|
12
|
+
/** Default output options */
|
|
13
|
+
export const defaultOutputOptions = {
|
|
14
|
+
format: 'table',
|
|
15
|
+
quiet: false,
|
|
16
|
+
noHeaders: false,
|
|
17
|
+
noColor: false,
|
|
18
|
+
};
|
|
19
|
+
/** Render command result to string based on output options */
|
|
20
|
+
export function render(result, options = {}) {
|
|
21
|
+
const opts = { ...defaultOutputOptions, ...options };
|
|
22
|
+
// Quiet mode takes precedence
|
|
23
|
+
if (opts.quiet) {
|
|
24
|
+
return renderQuiet(result, opts);
|
|
25
|
+
}
|
|
26
|
+
// Dispatch to format-specific renderer
|
|
27
|
+
switch (opts.format) {
|
|
28
|
+
case 'json':
|
|
29
|
+
return renderJson(result, opts);
|
|
30
|
+
case 'yaml':
|
|
31
|
+
return renderYaml(result, opts);
|
|
32
|
+
case 'table':
|
|
33
|
+
default:
|
|
34
|
+
return renderTable(result, opts);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/** Convert an unknown error to a CommandError */
|
|
38
|
+
export function toCommandError(error) {
|
|
39
|
+
if (isCommandError(error)) {
|
|
40
|
+
return error;
|
|
41
|
+
}
|
|
42
|
+
if (error instanceof Error) {
|
|
43
|
+
return {
|
|
44
|
+
code: 'UNKNOWN_ERROR',
|
|
45
|
+
message: error.message,
|
|
46
|
+
details: error.stack,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
return {
|
|
50
|
+
code: 'UNKNOWN_ERROR',
|
|
51
|
+
message: String(error),
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
/** Type guard for CommandError */
|
|
55
|
+
function isCommandError(error) {
|
|
56
|
+
return (typeof error === 'object' &&
|
|
57
|
+
error !== null &&
|
|
58
|
+
'code' in error &&
|
|
59
|
+
'message' in error &&
|
|
60
|
+
typeof error.code === 'string' &&
|
|
61
|
+
typeof error.message === 'string');
|
|
62
|
+
}
|
|
63
|
+
/** Render an error to string based on output options */
|
|
64
|
+
export function renderError(error, options = {}) {
|
|
65
|
+
const opts = { ...defaultOutputOptions, ...options };
|
|
66
|
+
if (opts.format === 'json') {
|
|
67
|
+
return JSON.stringify({ error }, null, 2);
|
|
68
|
+
}
|
|
69
|
+
if (opts.format === 'yaml') {
|
|
70
|
+
return YAML.stringify({ error });
|
|
71
|
+
}
|
|
72
|
+
// Table/default format: human-readable error
|
|
73
|
+
const prefix = opts.noColor ? 'Error: ' : chalk.red('Error: ');
|
|
74
|
+
const message = error.message;
|
|
75
|
+
if (error.details && typeof error.details === 'string') {
|
|
76
|
+
return `${prefix}${message}\n${error.details}`;
|
|
77
|
+
}
|
|
78
|
+
return `${prefix}${message}`;
|
|
79
|
+
}
|
|
80
|
+
//# sourceMappingURL=render.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"render.js","sourceRoot":"","sources":["../../src/output/render.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,IAAI,MAAM,MAAM,CAAA;AAEvB,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AACxC,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AACtC,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AACtC,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAExC,6BAA6B;AAC7B,MAAM,CAAC,MAAM,oBAAoB,GAAkB;IACjD,MAAM,EAAE,OAAO;IACf,KAAK,EAAE,KAAK;IACZ,SAAS,EAAE,KAAK;IAChB,OAAO,EAAE,KAAK;CACf,CAAA;AAED,8DAA8D;AAC9D,MAAM,U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AwD;AACxD,MAAM,UAAU,WAAW,CACzB,KAAmB,EACnB,UAAkC,EAAE;IAEpC,MAAM,IAAI,GAAkB,EAAE,GAAG,oBAAoB,EAAE,GAAG,OAAO,EAAE,CAAA;IAEnE,IAAI,IAAI,CAAC,MAAM,KAAK,MAAM,EAAE,CAAC;QAC3B,OAAO,IAAI,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC,CAAA;IAC3C,CAAC;IAED,IAAI,IAAI,CAAC,MAAM,KAAK,MAAM,EAAE,CAAC;QAC3B,OAAO,IAAI,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,CAAC,CAAA;IAClC,CAAC;IAED,6CAA6C;IAC7C,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,SAAS,CAAC,CAAA;IAC9D,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,CAAA;IAE7B,IAAI,KAAK,CAAC,OAAO,IAAI,OAAO,KAAK,CAAC,OAAO,KAAK,QAAQ,EAAE,CAAC;QACvD,OAAO,GAAG,MAAM,GAAG,OAAO,KAAK,KAAK,CAAC,OAAO,EAAE,CAAA;IAChD,CAAC;IAED,OAAO,GAAG,MAAM,GAAG,OAAO,EAAE,CAAA;AAC9B,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Table renderer for CLI output.
|
|
3
|
+
*
|
|
4
|
+
* Renders structured data as aligned ASCII tables with optional color support.
|
|
5
|
+
*/
|
|
6
|
+
import type { AnyCommandResult, OutputOptions, OutputSchema } from './types.js';
|
|
7
|
+
/** Render a list result as a table */
|
|
8
|
+
export declare function renderTable<T>(result: AnyCommandResult<T>, options: OutputOptions): string;
|
|
9
|
+
/** Render just a table header (for streaming) */
|
|
10
|
+
export declare function renderTableHeader<T>(schema: OutputSchema<T>, options: OutputOptions, widths?: number[]): string;
|
|
11
|
+
/** Render just a table row (for streaming) */
|
|
12
|
+
export declare function renderTableRow<T>(item: T, schema: OutputSchema<T>, options: OutputOptions, widths?: number[]): string;
|
|
13
|
+
//# sourceMappingURL=table.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"table.d.ts","sourceRoot":"","sources":["../../src/output/table.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,EACV,gBAAgB,EAEhB,aAAa,EACb,YAAY,EACb,MAAM,YAAY,CAAA;AAmInB,sCAAsC;AACtC,wBAAgB,WAAW,CAAC,CAAC,EAC3B,MAAM,EAAE,gBAAgB,CAAC,CAAC,CAAC,EAC3B,OAAO,EAAE,aAAa,GACrB,MAAM,CAyBR;AAED,iDAAiD;AACjD,wBAAgB,iBAAiB,CAAC,CAAC,EACjC,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC,EACvB,OAAO,EAAE,aAAa,EACtB,MAAM,CAAC,EAAE,MAAM,EAAE,GAChB,MAAM,CAIR;AAED,8CAA8C;AAC9C,wBAAgB,cAAc,CAAC,CAAC,EAC9B,IAAI,EAAE,CAAC,EACP,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC,EACvB,OAAO,EAAE,aAAa,EACtB,MAAM,CAAC,EAAE,MAAM,EAAE,GAChB,MAAM,CAIR"}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Table renderer for CLI output.
|
|
3
|
+
*
|
|
4
|
+
* Renders structured data as aligned ASCII tables with optional color support.
|
|
5
|
+
*/
|
|
6
|
+
import chalk from 'chalk';
|
|
7
|
+
// ANSI escape code regex for stripping colors when measuring width
|
|
8
|
+
const ANSI_REGEX =
|
|
9
|
+
// eslint-disable-next-line no-control-regex
|
|
10
|
+
/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g;
|
|
11
|
+
/** Strip ANSI escape codes from a string */
|
|
12
|
+
function stripAnsi(str) {
|
|
13
|
+
return str.replace(ANSI_REGEX, '');
|
|
14
|
+
}
|
|
15
|
+
/** Get visible string length (excluding ANSI codes) */
|
|
16
|
+
function visibleLength(str) {
|
|
17
|
+
return stripAnsi(str).length;
|
|
18
|
+
}
|
|
19
|
+
/** Pad a cell to the specified width with alignment */
|
|
20
|
+
function padCell(cell, width, align) {
|
|
21
|
+
const visible = visibleLength(cell);
|
|
22
|
+
const padding = Math.max(0, width - visible);
|
|
23
|
+
switch (align) {
|
|
24
|
+
case 'right':
|
|
25
|
+
return ' '.repeat(padding) + cell;
|
|
26
|
+
case 'center': {
|
|
27
|
+
const left = Math.floor(padding / 2);
|
|
28
|
+
const right = padding - left;
|
|
29
|
+
return ' '.repeat(left) + cell + ' '.repeat(right);
|
|
30
|
+
}
|
|
31
|
+
case 'left':
|
|
32
|
+
default:
|
|
33
|
+
return cell + ' '.repeat(padding);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/** Apply a chalk color to a string */
|
|
37
|
+
function applyColor(str, colorName) {
|
|
38
|
+
// Map color names to chalk methods
|
|
39
|
+
const colorMap = {
|
|
40
|
+
red: chalk.red,
|
|
41
|
+
green: chalk.green,
|
|
42
|
+
blue: chalk.blue,
|
|
43
|
+
yellow: chalk.yellow,
|
|
44
|
+
cyan: chalk.cyan,
|
|
45
|
+
magenta: chalk.magenta,
|
|
46
|
+
white: chalk.white,
|
|
47
|
+
gray: chalk.gray,
|
|
48
|
+
grey: chalk.grey,
|
|
49
|
+
dim: chalk.dim,
|
|
50
|
+
bold: chalk.bold,
|
|
51
|
+
};
|
|
52
|
+
const colorFn = colorMap[colorName];
|
|
53
|
+
return colorFn ? colorFn(str) : str;
|
|
54
|
+
}
|
|
55
|
+
/** Extract value from item using field definition */
|
|
56
|
+
function getValue(item, field) {
|
|
57
|
+
return typeof field === 'function' ? field(item) : item[field];
|
|
58
|
+
}
|
|
59
|
+
/** Render a single table row */
|
|
60
|
+
function renderRow(item, columns, widths, options) {
|
|
61
|
+
return columns
|
|
62
|
+
.map((col, colIndex) => {
|
|
63
|
+
const value = getValue(item, col.field);
|
|
64
|
+
let cell = String(value ?? '');
|
|
65
|
+
const width = widths[colIndex];
|
|
66
|
+
// Apply color if enabled
|
|
67
|
+
if (col.color && !options.noColor) {
|
|
68
|
+
const colorName = col.color(value, item);
|
|
69
|
+
if (colorName) {
|
|
70
|
+
cell = applyColor(cell, colorName);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return padCell(cell, width ?? 0, col.align ?? 'left');
|
|
74
|
+
})
|
|
75
|
+
.join(' ');
|
|
76
|
+
}
|
|
77
|
+
/** Render header row */
|
|
78
|
+
function renderHeader(columns, widths, options) {
|
|
79
|
+
const headerRow = columns
|
|
80
|
+
.map((col, i) => padCell(col.header, widths[i] ?? 0, col.align ?? 'left'))
|
|
81
|
+
.join(' ');
|
|
82
|
+
return options.noColor ? headerRow : chalk.bold(headerRow);
|
|
83
|
+
}
|
|
84
|
+
/** Calculate column widths based on content and hints */
|
|
85
|
+
function calculateWidths(data, columns, includeHeaders) {
|
|
86
|
+
return columns.map((col) => {
|
|
87
|
+
// Start with header width if including headers
|
|
88
|
+
let maxWidth = includeHeaders ? col.header.length : 0;
|
|
89
|
+
// Check all data values
|
|
90
|
+
for (const item of data) {
|
|
91
|
+
const value = getValue(item, col.field);
|
|
92
|
+
const str = String(value ?? '');
|
|
93
|
+
maxWidth = Math.max(maxWidth, visibleLength(str));
|
|
94
|
+
}
|
|
95
|
+
// Apply width hint if specified (minimum width)
|
|
96
|
+
if (col.width) {
|
|
97
|
+
maxWidth = Math.max(maxWidth, col.width);
|
|
98
|
+
}
|
|
99
|
+
return maxWidth;
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
/** Render a list result as a table */
|
|
103
|
+
export function renderTable(result, options) {
|
|
104
|
+
const { schema } = result;
|
|
105
|
+
const data = result.type === 'list' ? result.data : [result.data];
|
|
106
|
+
if (data.length === 0) {
|
|
107
|
+
return '';
|
|
108
|
+
}
|
|
109
|
+
const columns = schema.columns;
|
|
110
|
+
const includeHeaders = !options.noHeaders;
|
|
111
|
+
const widths = calculateWidths(data, columns, includeHeaders);
|
|
112
|
+
const lines = [];
|
|
113
|
+
// Add header row
|
|
114
|
+
if (includeHeaders) {
|
|
115
|
+
lines.push(renderHeader(columns, widths, options));
|
|
116
|
+
}
|
|
117
|
+
// Add data rows
|
|
118
|
+
for (const item of data) {
|
|
119
|
+
lines.push(renderRow(item, columns, widths, options));
|
|
120
|
+
}
|
|
121
|
+
return lines.join('\n');
|
|
122
|
+
}
|
|
123
|
+
/** Render just a table header (for streaming) */
|
|
124
|
+
export function renderTableHeader(schema, options, widths) {
|
|
125
|
+
const columns = schema.columns;
|
|
126
|
+
const actualWidths = widths ?? columns.map((col) => col.width ?? col.header.length);
|
|
127
|
+
return renderHeader(columns, actualWidths, options);
|
|
128
|
+
}
|
|
129
|
+
/** Render just a table row (for streaming) */
|
|
130
|
+
export function renderTableRow(item, schema, options, widths) {
|
|
131
|
+
const columns = schema.columns;
|
|
132
|
+
const actualWidths = widths ?? columns.map((col) => col.width ?? col.header.length);
|
|
133
|
+
return renderRow(item, columns, actualWidths, options);
|
|
134
|
+
}
|
|
135
|
+
//# sourceMappingURL=table.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"table.js","sourceRoot":"","sources":["../../src/output/table.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAA6B,MAAM,OAAO,CAAA;AAQjD,mEAAmE;AACnE,MAAM,UAAU;AACd,4CAA4C;AAC5C,6EAA6E,CAAA;AAE/E,4CAA4C;AAC5C,SAAS,SAAS,CAAC,GAAW;IAC5B,OAAO,GAAG,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAA;AACpC,CAAC;AAED,uDAAuD;AACvD,SAAS,aAAa,CAAC,GAAW;IAChC,OAAO,SAAS,CAAC,GAAG,CAAC,CAA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AAE,OAAO,CAAC,CAAA;AACrD,CAAC;AAED,8CAA8C;AAC9C,MAAM,UAAU,cAAc,CAC5B,IAAO,EACP,MAAuB,EACvB,OAAsB,EACtB,MAAiB;IAEjB,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,CAAA;IAC9B,MAAM,YAAY,GAAG,MAAM,IAAI,OAAO,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,KAAK,IAAI,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;IACnF,OAAO,SAAS,CAAC,IAAI,EAAE,OAAO,EAAE,YAAY,EAAE,OAAO,CAAC,CAAA;AACxD,CAAC"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Output format types for the Paseo CLI.
|
|
3
|
+
*
|
|
4
|
+
* This module defines the structured data types used by the output abstraction layer.
|
|
5
|
+
* Commands return CommandResult<T> which contains both data and rendering metadata.
|
|
6
|
+
*/
|
|
7
|
+
/** Supported output formats */
|
|
8
|
+
export type OutputFormat = 'table' | 'json' | 'yaml';
|
|
9
|
+
/** Options controlling output rendering */
|
|
10
|
+
export interface OutputOptions {
|
|
11
|
+
/** Output format (table, json, yaml) */
|
|
12
|
+
format: OutputFormat;
|
|
13
|
+
/** Minimal output - IDs only */
|
|
14
|
+
quiet: boolean;
|
|
15
|
+
/** Omit table headers */
|
|
16
|
+
noHeaders: boolean;
|
|
17
|
+
/** Disable color output */
|
|
18
|
+
noColor: boolean;
|
|
19
|
+
}
|
|
20
|
+
/** Column definition for table output */
|
|
21
|
+
export interface ColumnDef<T> {
|
|
22
|
+
/** Header text for the column */
|
|
23
|
+
header: string;
|
|
24
|
+
/** Field key or accessor function */
|
|
25
|
+
field: keyof T | ((item: T) => unknown);
|
|
26
|
+
/** Optional width hint (characters) */
|
|
27
|
+
width?: number;
|
|
28
|
+
/** Optional alignment */
|
|
29
|
+
align?: 'left' | 'right' | 'center';
|
|
30
|
+
/** Optional color function - returns chalk color name */
|
|
31
|
+
color?: (value: unknown, item: T) => string | undefined;
|
|
32
|
+
}
|
|
33
|
+
/** Schema describing how to render command output */
|
|
34
|
+
export interface OutputSchema<T> {
|
|
35
|
+
/** Field to use for quiet mode (--quiet outputs just this) */
|
|
36
|
+
idField: keyof T | ((item: T) => string);
|
|
37
|
+
/** Column definitions for table output */
|
|
38
|
+
columns: ColumnDef<T>[];
|
|
39
|
+
/** Optional: transform data before JSON/YAML output */
|
|
40
|
+
serialize?: (data: T) => unknown;
|
|
41
|
+
}
|
|
42
|
+
/** Result type for commands returning a single item */
|
|
43
|
+
export interface SingleResult<T> {
|
|
44
|
+
type: 'single';
|
|
45
|
+
/** The structured data to render */
|
|
46
|
+
data: T;
|
|
47
|
+
/** Schema describing how to render this data (for item type T) */
|
|
48
|
+
schema: OutputSchema<T>;
|
|
49
|
+
}
|
|
50
|
+
/** Result type for commands returning a list */
|
|
51
|
+
export interface ListResult<T> {
|
|
52
|
+
type: 'list';
|
|
53
|
+
/** The structured data to render */
|
|
54
|
+
data: T[];
|
|
55
|
+
/** Schema describing how to render this data (for item type T) */
|
|
56
|
+
schema: OutputSchema<T>;
|
|
57
|
+
}
|
|
58
|
+
/** Union type for all command results */
|
|
59
|
+
export type AnyCommandResult<T> = SingleResult<T> | ListResult<T>;
|
|
60
|
+
/** Base interface for command results (deprecated, use SingleResult or ListResult) */
|
|
61
|
+
export type CommandResult<T> = SingleResult<T> | ListResult<T>;
|
|
62
|
+
/** Structured error for command failures */
|
|
63
|
+
export interface CommandError {
|
|
64
|
+
/** Machine-readable error code */
|
|
65
|
+
code: string;
|
|
66
|
+
/** Human-readable message */
|
|
67
|
+
message: string;
|
|
68
|
+
/** Additional context */
|
|
69
|
+
details?: unknown;
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/output/types.ts"],"names":[],"mappings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AAM,EAAE,YAAY,CAAC,CAAC,CAAC,CAAA;CACxB;AAED,gDAAgD;AAChD,MAAM,WAAW,UAAU,CAAC,CAAC;IAC3B,IAAI,EAAE,MAAM,CAAA;IACZ,oCAAoC;IACpC,IAAI,EAAE,CAAC,EAAE,CAAA;IACT,kEAAkE;IAClE,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC,CAAA;CACxB;AAED,yCAAyC;AACzC,MAAM,MAAM,gBAAgB,CAAC,CAAC,IAAI,YAAY,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,CAAA;AAEjE,sFAAsF;AACtF,MAAM,MAAM,aAAa,CAAC,CAAC,IAAI,YAAY,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,CAAA;AAE9D,4CAA4C;AAC5C,MAAM,WAAW,YAAY;IAC3B,kCAAkC;IAClC,IAAI,EAAE,MAAM,CAAA;IACZ,6BAA6B;IAC7B,OAAO,EAAE,MAAM,CAAA;IACf,yBAAyB;IACzB,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Output format types for the Paseo CLI.
|
|
3
|
+
*
|
|
4
|
+
* This module defines the structured data types used by the output abstraction layer.
|
|
5
|
+
* Commands return CommandResult<T> which contains both data and rendering metadata.
|
|
6
|
+
*/
|
|
7
|
+
export {};
|
|
8
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/output/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Command wrapper for automatic output rendering.
|
|
3
|
+
*
|
|
4
|
+
* Wraps command handlers to automatically render results and handle errors.
|
|
5
|
+
*/
|
|
6
|
+
import type { Command } from 'commander';
|
|
7
|
+
import type { AnyCommandResult, OutputOptions } from './types.js';
|
|
8
|
+
/** Options that include output settings from global options */
|
|
9
|
+
export interface CommandOptions extends Partial<OutputOptions> {
|
|
10
|
+
[key: string]: unknown;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Wrap a command handler to automatically render output.
|
|
14
|
+
*
|
|
15
|
+
* The wrapped handler should return a CommandResult. The wrapper will:
|
|
16
|
+
* 1. Call the handler
|
|
17
|
+
* 2. Render the result using the appropriate format
|
|
18
|
+
* 3. Write to stdout
|
|
19
|
+
* 4. Handle errors by rendering to stderr and exiting with code 1
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* program
|
|
24
|
+
* .command('list')
|
|
25
|
+
* .action(withOutput(async (options) => {
|
|
26
|
+
* const data = await fetchData()
|
|
27
|
+
* return { type: 'list', data, schema }
|
|
28
|
+
* }))
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export declare function withOutput<T, Args extends unknown[]>(handler: (...args: [...Args, CommandOptions, Command]) => Promise<AnyCommandResult<T>>): (...args: [...Args, CommandOptions, Command]) => Promise<void>;
|
|
32
|
+
/**
|
|
33
|
+
* Helper to create output options from partial input.
|
|
34
|
+
* Useful for testing or manual rendering.
|
|
35
|
+
*/
|
|
36
|
+
export declare function createOutputOptions(partial?: Partial<OutputOptions>): OutputOptions;
|
|
37
|
+
//# sourceMappingURL=with-output.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"with-output.d.ts","sourceRoot":"","sources":["../../src/output/with-output.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACxC,OAAO,KAAK,EAAE,gBAAgB,EAAgB,aAAa,EAAE,MAAM,YAAY,CAAA;AAG/E,+DAA+D;AAC/D,MAAM,WAAW,cAAe,SAAQ,OAAO,CAAC,aAAa,CAAC;IAC5D,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CACvB;AA4BD;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAAE,IAAI,SAAS,OAAO,EAAE,EAClD,OAAO,EAAE,CAAC,GAAG,IAAI,EAAE,CAAC,GAAG,IAAI,EAAE,cAAc,EAAE,OAAO,CAAC,KAAK,OAAO,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,GACrF,CAAC,GAAG,IAAI,EAAE,CAAC,GAAG,IAAI,EAAE,cAAc,EAAE,OAAO,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,CAsBhE;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CACjC,OAAO,GAAE,OAAO,CAAC,aAAa,CAAM,GACnC,aAAa,CAEf"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Command wrapper for automatic output rendering.
|
|
3
|
+
*
|
|
4
|
+
* Wraps command handlers to automatically render results and handle errors.
|
|
5
|
+
*/
|
|
6
|
+
import { render, renderError, toCommandError, defaultOutputOptions } from './render.js';
|
|
7
|
+
function normalizeFormat(raw) {
|
|
8
|
+
const value = typeof raw === 'string' ? raw.trim().toLowerCase() : '';
|
|
9
|
+
// Common user expectation: "cli" means "table/human"
|
|
10
|
+
if (value === 'cli')
|
|
11
|
+
return 'table';
|
|
12
|
+
if (value === 'table' || value === 'json' || value === 'yaml')
|
|
13
|
+
return value;
|
|
14
|
+
const error = {
|
|
15
|
+
code: 'INVALID_FORMAT',
|
|
16
|
+
message: `Unsupported output format: ${String(raw)}`,
|
|
17
|
+
details: 'Supported formats: table, json, yaml',
|
|
18
|
+
};
|
|
19
|
+
throw error;
|
|
20
|
+
}
|
|
21
|
+
/** Extract output options from command options */
|
|
22
|
+
function extractOutputOptions(options) {
|
|
23
|
+
return {
|
|
24
|
+
format: options.json ? 'json' : normalizeFormat(options.format ?? defaultOutputOptions.format),
|
|
25
|
+
quiet: options.quiet ?? defaultOutputOptions.quiet,
|
|
26
|
+
noHeaders: options.headers === false, // Commander uses --no-headers -> headers: false
|
|
27
|
+
noColor: options.color === false, // Commander uses --no-color -> color: false
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Wrap a command handler to automatically render output.
|
|
32
|
+
*
|
|
33
|
+
* The wrapped handler should return a CommandResult. The wrapper will:
|
|
34
|
+
* 1. Call the handler
|
|
35
|
+
* 2. Render the result using the appropriate format
|
|
36
|
+
* 3. Write to stdout
|
|
37
|
+
* 4. Handle errors by rendering to stderr and exiting with code 1
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```typescript
|
|
41
|
+
* program
|
|
42
|
+
* .command('list')
|
|
43
|
+
* .action(withOutput(async (options) => {
|
|
44
|
+
* const data = await fetchData()
|
|
45
|
+
* return { type: 'list', data, schema }
|
|
46
|
+
* }))
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
export function withOutput(handler) {
|
|
50
|
+
return async (...args) => {
|
|
51
|
+
// Last two args are options and command
|
|
52
|
+
const command = args[args.length - 1];
|
|
53
|
+
// Use optsWithGlobals() to get both local and global options
|
|
54
|
+
const options = command.optsWithGlobals();
|
|
55
|
+
const outputOptions = extractOutputOptions(options);
|
|
56
|
+
try {
|
|
57
|
+
const result = await handler(...args);
|
|
58
|
+
const output = render(result, outputOptions);
|
|
59
|
+
if (output) {
|
|
60
|
+
process.stdout.write(output + '\n');
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
const commandError = toCommandError(error);
|
|
65
|
+
const errorOutput = renderError(commandError, outputOptions);
|
|
66
|
+
process.stderr.write(errorOutput + '\n');
|
|
67
|
+
process.exit(1);
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Helper to create output options from partial input.
|
|
73
|
+
* Useful for testing or manual rendering.
|
|
74
|
+
*/
|
|
75
|
+
export function createOutputOptions(partial = {}) {
|
|
76
|
+
return { ...defaultOutputOptions, ...partial };
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=with-output.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"with-output.js","sourceRoot":"","sources":["../../src/output/with-output.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAA;AAOvF,SAAS,eAAe,CAAC,GAAY;IACnC,MAAM,KAAK,GAAG,OAAO,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,CAAA;IAErE,qDAAqD;IACrD,IAAI,KAAK,KAAK,KAAK;QAAE,OAAO,OAAO,CAAA;IAEnC,IAAI,KAAK,KAAK,OAAO,IAAI,KAAK,KAAK,MAAM,IAAI,KAAK,KAAK,MAAM;QAAE,OAAO,KAAK,CAAA;IAE3E,MAAM,KAAK,GAAiB;QAC1B,IAAI,EAAE,gBAAgB;QACtB,OAAO,EAAE,8BAA8B,MAAM,CAAC,GAAG,CAAC,EAAE;QACpD,OAAO,EAAE,sCAAsC;KAChD,CAAA;IACD,MAAM,KAAK,CAAA;AACb,CAAC;AAED,kDAAkD;AAClD,SAAS,oBAAoB,CAAC,OAAuB;IACnD,OAAO;QACL,MAAM,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,eAAe,CAAC,OAAO,CAAC,MAAM,IAAI,oBAAoB,CAAC,MAAM,CAAC;QAC9F,KAAK,EAAE,OAAO,CAAC,KAAK,IAAI,oBAAoB,CAAC,KAAK;QAClD,SAAS,EAAE,OAAO,CAAC,OAAO,KAAK,KAAK,EAAE,gDAAgD;QACtF,OAAO,EAAE,OAAO,CAAC,KAAK,KAAK,KAAK,EAAE,4CAA4C;KAC/E,CAAA;AACH,CAAC;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,UAAU,CACxB,OAAsF;IAEtF,OAAO,KAAK,EAAE,GAAG,IAAI,EAAE,EAAE;QACvB,wCAAwC;QACxC,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAY,CAAA;QAChD,6DAA6D;QAC7D,MAAM,OAAO,GAAG,OAAO,CAAC,eAAe,EAAoB,CAAA;QAC3D,MAAM,aAAa,GAAG,oBAAoB,CAAC,OAAO,CAAC,CAAA;QAEnD,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,GAAG,IAAI,CAAC,CAAA;YACrC,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAA;YAE5C,IAAI,MAAM,EAAE,CAAC;gBACX,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,GAAG,IAAI,CAAC,CAAA;YACrC,CAAC;QACH,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,YAAY,GAAG,cAAc,CAAC,KAAK,CAAC,CAAA;YAC1C,MAAM,WAAW,GAAG,WAAW,CAAC,YAAY,EAAE,aAAa,CAAC,CAAA;YAC5D,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,WAAW,GAAG,IAAI,CAAC,CAAA;YACxC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;QACjB,CAAC;IACH,CAAC,CAAA;AACH,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,mBAAmB,CACjC,UAAkC,EAAE;IAEpC,OAAO,EAAE,GAAG,oBAAoB,EAAE,GAAG,OAAO,EAAE,CAAA;AAChD,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* YAML renderer for CLI output.
|
|
3
|
+
*
|
|
4
|
+
* Renders structured data as YAML for machine consumption and human readability.
|
|
5
|
+
*/
|
|
6
|
+
import type { AnyCommandResult, OutputOptions } from './types.js';
|
|
7
|
+
/** Render command result as YAML */
|
|
8
|
+
export declare function renderYaml<T>(result: AnyCommandResult<T>, _options: OutputOptions): string;
|
|
9
|
+
/** Render a single item as YAML document (for streaming) */
|
|
10
|
+
export declare function renderYamlDoc<T>(item: T, serialize?: (data: T) => unknown): string;
|
|
11
|
+
//# sourceMappingURL=yaml.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"yaml.d.ts","sourceRoot":"","sources":["../../src/output/yaml.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAEjE,oCAAoC;AACpC,wBAAgB,UAAU,CAAC,CAAC,EAC1B,MAAM,EAAE,gBAAgB,CAAC,CAAC,CAAC,EAC3B,QAAQ,EAAE,aAAa,GACtB,MAAM,CAyBR;AAED,4DAA4D;AAC5D,wBAAgB,aAAa,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,OAAO,GAAG,MAAM,CAGlF"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* YAML renderer for CLI output.
|
|
3
|
+
*
|
|
4
|
+
* Renders structured data as YAML for machine consumption and human readability.
|
|
5
|
+
*/
|
|
6
|
+
import YAML from 'yaml';
|
|
7
|
+
/** Render command result as YAML */
|
|
8
|
+
export function renderYaml(result, _options) {
|
|
9
|
+
const { schema } = result;
|
|
10
|
+
// Apply custom serializer if provided
|
|
11
|
+
if (schema.serialize) {
|
|
12
|
+
if (result.type === 'list') {
|
|
13
|
+
// If all items serialize to the same object, return just one
|
|
14
|
+
// This handles the case where a list of key-value rows should serialize
|
|
15
|
+
// to a single structured object
|
|
16
|
+
const serialized = result.data.map((item) => schema.serialize(item));
|
|
17
|
+
if (serialized.length > 0) {
|
|
18
|
+
const first = JSON.stringify(serialized[0]);
|
|
19
|
+
const allSame = serialized.every((s) => JSON.stringify(s) === first);
|
|
20
|
+
if (allSame) {
|
|
21
|
+
return YAML.stringify(serialized[0]);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return YAML.stringify(serialized);
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
const serialized = schema.serialize(result.data);
|
|
28
|
+
return YAML.stringify(serialized);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return YAML.stringify(result.data);
|
|
32
|
+
}
|
|
33
|
+
/** Render a single item as YAML document (for streaming) */
|
|
34
|
+
export function renderYamlDoc(item, serialize) {
|
|
35
|
+
const output = serialize ? serialize(item) : item;
|
|
36
|
+
return YAML.stringify(output);
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=yaml.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"yaml.js","sourceRoot":"","sources":["../../src/output/yaml.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,IAAI,MAAM,MAAM,CAAA;AAGvB,oCAAoC;AACpC,MAAM,UAAU,UAAU,CACxB,MAA2B,EAC3B,QAAuB;IAEvB,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,CAAA;IAEzB,sCAAsC;IACtC,IAAI,MAAM,CAAC,SAAS,EAAE,CAAC;QACrB,IAAI,MAAM,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;YAC3B,6DAA6D;YAC7D,wEAAwE;YACxE,gCAAgC;YAChC,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,MAAM,CAAC,SAAU,CAAC,IAAI,CAAC,CAAC,CAAA;YACrE,IAAI,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBAC1B,MAAM,KAAK,GAAG,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAA;gBAC3C,MAAM,OAAO,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,KAAK,CAAC,CAAA;gBACpE,IAAI,OAAO,EAAE,CAAC;oBACZ,OAAO,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAA;gBACtC,CAAC;YACH,CAAC;YACD,OAAO,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,CAAA;QACnC,CAAC;aAAM,CAAC;YACN,MAAM,UAAU,GAAG,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;YAChD,OAAO,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,CAAA;QACnC,CAAC;IACH,CAAC;IAED,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;AACpC,CAAC;AAED,4DAA4D;AAC5D,MAAM,UAAU,aAAa,CAAI,IAAO,EAAE,SAAgC;IACxE,MAAM,MAAM,GAAG,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAA;IACjD,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAA;AAC/B,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { DaemonClient } from '@getpaseo/server';
|
|
2
|
+
export interface ConnectOptions {
|
|
3
|
+
host?: string;
|
|
4
|
+
timeout?: number;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Get the daemon host from environment or options
|
|
8
|
+
*/
|
|
9
|
+
export declare function getDaemonHost(options?: ConnectOptions): string;
|
|
10
|
+
/**
|
|
11
|
+
* Create and connect a daemon client
|
|
12
|
+
* Returns the connected client or throws if connection fails
|
|
13
|
+
*/
|
|
14
|
+
export declare function connectToDaemon(options?: ConnectOptions): Promise<DaemonClient>;
|
|
15
|
+
/**
|
|
16
|
+
* Try to connect to the daemon, returns null if connection fails
|
|
17
|
+
*/
|
|
18
|
+
export declare function tryConnectToDaemon(options?: ConnectOptions): Promise<DaemonClient | null>;
|
|
19
|
+
/** Minimal agent type for ID resolution */
|
|
20
|
+
interface AgentLike {
|
|
21
|
+
id: string;
|
|
22
|
+
title?: string | null;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Resolve an agent ID from a partial ID or name.
|
|
26
|
+
* Supports:
|
|
27
|
+
* - Full ID match
|
|
28
|
+
* - Prefix match (first N characters)
|
|
29
|
+
* - Title/name match (case-insensitive)
|
|
30
|
+
*
|
|
31
|
+
* Returns the full agent ID if found, null otherwise.
|
|
32
|
+
*/
|
|
33
|
+
export declare function resolveAgentId(idOrName: string, agents: AgentLike[]): string | null;
|
|
34
|
+
export {};
|
|
35
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/utils/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAG/C,MAAM,WAAW,cAAc;IAC7B,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB;AAKD;;GAEG;AACH,wBAAgB,aAAa,CAAC,OAAO,CAAC,EAAE,cAAc,GAAG,MAAM,CAE9D;AAiBD;;;GAGG;AACH,wBAAsB,eAAe,CAAC,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,YAAY,CAAC,CAoCrF;AAED;;GAEG;AACH,wBAAsB,kBAAkB,CAAC,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC,CAM/F;AAED,2CAA2C;AAC3C,UAAU,SAAS;IACjB,EAAE,EAAE,MAAM,CAAA;IACV,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CACtB;AAED;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,MAAM,GAAG,IAAI,CAsCnF"}
|