@hyperdrive.bot/paseo-cli 0.2.6

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 (212) hide show
  1. package/bin/paseo +3 -0
  2. package/dist/classify.d.ts +19 -0
  3. package/dist/classify.js +49 -0
  4. package/dist/cli.d.ts +3 -0
  5. package/dist/cli.js +119 -0
  6. package/dist/commands/agent/archive.d.ts +18 -0
  7. package/dist/commands/agent/archive.js +102 -0
  8. package/dist/commands/agent/attach.d.ts +11 -0
  9. package/dist/commands/agent/attach.js +159 -0
  10. package/dist/commands/agent/delete.d.ts +15 -0
  11. package/dist/commands/agent/delete.js +107 -0
  12. package/dist/commands/agent/import.d.ts +14 -0
  13. package/dist/commands/agent/import.js +122 -0
  14. package/dist/commands/agent/index.d.ts +3 -0
  15. package/dist/commands/agent/index.js +48 -0
  16. package/dist/commands/agent/inspect.d.ts +15 -0
  17. package/dist/commands/agent/inspect.js +209 -0
  18. package/dist/commands/agent/logs.d.ts +19 -0
  19. package/dist/commands/agent/logs.js +180 -0
  20. package/dist/commands/agent/ls.d.ts +44 -0
  21. package/dist/commands/agent/ls.js +204 -0
  22. package/dist/commands/agent/mode.d.ts +18 -0
  23. package/dist/commands/agent/mode.js +100 -0
  24. package/dist/commands/agent/reload.d.ts +15 -0
  25. package/dist/commands/agent/reload.js +75 -0
  26. package/dist/commands/agent/run.d.ts +44 -0
  27. package/dist/commands/agent/run.js +464 -0
  28. package/dist/commands/agent/send.d.ts +19 -0
  29. package/dist/commands/agent/send.js +187 -0
  30. package/dist/commands/agent/stop.d.ts +17 -0
  31. package/dist/commands/agent/stop.js +115 -0
  32. package/dist/commands/agent/update.d.ts +18 -0
  33. package/dist/commands/agent/update.js +139 -0
  34. package/dist/commands/agent/wait.d.ts +17 -0
  35. package/dist/commands/agent/wait.js +158 -0
  36. package/dist/commands/agent-hook.d.ts +7 -0
  37. package/dist/commands/agent-hook.js +67 -0
  38. package/dist/commands/chat/create.d.ts +9 -0
  39. package/dist/commands/chat/create.js +23 -0
  40. package/dist/commands/chat/delete.d.ts +6 -0
  41. package/dist/commands/chat/delete.js +20 -0
  42. package/dist/commands/chat/index.d.ts +3 -0
  43. package/dist/commands/chat/index.js +47 -0
  44. package/dist/commands/chat/inspect.d.ts +6 -0
  45. package/dist/commands/chat/inspect.js +20 -0
  46. package/dist/commands/chat/ls.d.ts +6 -0
  47. package/dist/commands/chat/ls.js +20 -0
  48. package/dist/commands/chat/post.d.ts +9 -0
  49. package/dist/commands/chat/post.js +28 -0
  50. package/dist/commands/chat/read.d.ts +11 -0
  51. package/dist/commands/chat/read.js +40 -0
  52. package/dist/commands/chat/schema.d.ts +36 -0
  53. package/dist/commands/chat/schema.js +81 -0
  54. package/dist/commands/chat/shared.d.ts +19 -0
  55. package/dist/commands/chat/shared.js +118 -0
  56. package/dist/commands/chat/wait.d.ts +9 -0
  57. package/dist/commands/chat/wait.js +45 -0
  58. package/dist/commands/daemon/index.d.ts +3 -0
  59. package/dist/commands/daemon/index.js +57 -0
  60. package/dist/commands/daemon/local-daemon.d.ts +78 -0
  61. package/dist/commands/daemon/local-daemon.js +544 -0
  62. package/dist/commands/daemon/pair.d.ts +9 -0
  63. package/dist/commands/daemon/pair.js +76 -0
  64. package/dist/commands/daemon/restart.d.ts +12 -0
  65. package/dist/commands/daemon/restart.js +99 -0
  66. package/dist/commands/daemon/runtime-toolchain.d.ts +6 -0
  67. package/dist/commands/daemon/runtime-toolchain.js +87 -0
  68. package/dist/commands/daemon/set-password.d.ts +17 -0
  69. package/dist/commands/daemon/set-password.js +82 -0
  70. package/dist/commands/daemon/start.d.ts +6 -0
  71. package/dist/commands/daemon/start.js +56 -0
  72. package/dist/commands/daemon/status.d.ts +10 -0
  73. package/dist/commands/daemon/status.js +338 -0
  74. package/dist/commands/daemon/stop.d.ts +15 -0
  75. package/dist/commands/daemon/stop.js +60 -0
  76. package/dist/commands/hooks.d.ts +19 -0
  77. package/dist/commands/hooks.js +89 -0
  78. package/dist/commands/loop/index.d.ts +3 -0
  79. package/dist/commands/loop/index.js +18 -0
  80. package/dist/commands/loop/inspect.d.ts +13 -0
  81. package/dist/commands/loop/inspect.js +100 -0
  82. package/dist/commands/loop/logs.d.ts +8 -0
  83. package/dist/commands/loop/logs.js +69 -0
  84. package/dist/commands/loop/ls.d.ts +18 -0
  85. package/dist/commands/loop/ls.js +62 -0
  86. package/dist/commands/loop/run.d.ts +30 -0
  87. package/dist/commands/loop/run.js +162 -0
  88. package/dist/commands/loop/stop.d.ts +15 -0
  89. package/dist/commands/loop/stop.js +56 -0
  90. package/dist/commands/loop/types.d.ts +138 -0
  91. package/dist/commands/loop/types.js +2 -0
  92. package/dist/commands/onboard.d.ts +10 -0
  93. package/dist/commands/onboard.js +416 -0
  94. package/dist/commands/open.d.ts +2 -0
  95. package/dist/commands/open.js +84 -0
  96. package/dist/commands/permit/allow.d.ts +20 -0
  97. package/dist/commands/permit/allow.js +133 -0
  98. package/dist/commands/permit/deny.d.ts +12 -0
  99. package/dist/commands/permit/deny.js +105 -0
  100. package/dist/commands/permit/index.d.ts +3 -0
  101. package/dist/commands/permit/index.js +27 -0
  102. package/dist/commands/permit/ls.d.ts +18 -0
  103. package/dist/commands/permit/ls.js +66 -0
  104. package/dist/commands/provider/index.d.ts +3 -0
  105. package/dist/commands/provider/index.js +16 -0
  106. package/dist/commands/provider/ls.d.ts +19 -0
  107. package/dist/commands/provider/ls.js +73 -0
  108. package/dist/commands/provider/models.d.ts +20 -0
  109. package/dist/commands/provider/models.js +53 -0
  110. package/dist/commands/schedule/create.d.ts +18 -0
  111. package/dist/commands/schedule/create.js +40 -0
  112. package/dist/commands/schedule/delete.d.ts +10 -0
  113. package/dist/commands/schedule/delete.js +32 -0
  114. package/dist/commands/schedule/index.d.ts +3 -0
  115. package/dist/commands/schedule/index.js +66 -0
  116. package/dist/commands/schedule/inspect.d.ts +6 -0
  117. package/dist/commands/schedule/inspect.js +24 -0
  118. package/dist/commands/schedule/logs.d.ts +6 -0
  119. package/dist/commands/schedule/logs.js +23 -0
  120. package/dist/commands/schedule/ls.d.ts +5 -0
  121. package/dist/commands/schedule/ls.js +23 -0
  122. package/dist/commands/schedule/pause.d.ts +5 -0
  123. package/dist/commands/schedule/pause.js +23 -0
  124. package/dist/commands/schedule/resume.d.ts +5 -0
  125. package/dist/commands/schedule/resume.js +23 -0
  126. package/dist/commands/schedule/run-once.d.ts +5 -0
  127. package/dist/commands/schedule/run-once.js +23 -0
  128. package/dist/commands/schedule/schema.d.ts +21 -0
  129. package/dist/commands/schedule/schema.js +67 -0
  130. package/dist/commands/schedule/shared.d.ts +56 -0
  131. package/dist/commands/schedule/shared.js +346 -0
  132. package/dist/commands/schedule/types.d.ts +168 -0
  133. package/dist/commands/schedule/types.js +2 -0
  134. package/dist/commands/schedule/update.d.ts +21 -0
  135. package/dist/commands/schedule/update.js +39 -0
  136. package/dist/commands/speech/index.d.ts +3 -0
  137. package/dist/commands/speech/index.js +5 -0
  138. package/dist/commands/terminal/capture.d.ts +10 -0
  139. package/dist/commands/terminal/capture.js +68 -0
  140. package/dist/commands/terminal/create.d.ts +10 -0
  141. package/dist/commands/terminal/create.js +38 -0
  142. package/dist/commands/terminal/index.d.ts +3 -0
  143. package/dist/commands/terminal/index.js +43 -0
  144. package/dist/commands/terminal/kill.d.ts +6 -0
  145. package/dist/commands/terminal/kill.js +36 -0
  146. package/dist/commands/terminal/ls.d.ts +10 -0
  147. package/dist/commands/terminal/ls.js +21 -0
  148. package/dist/commands/terminal/schema.d.ts +18 -0
  149. package/dist/commands/terminal/schema.js +23 -0
  150. package/dist/commands/terminal/send-keys.d.ts +7 -0
  151. package/dist/commands/terminal/send-keys.js +76 -0
  152. package/dist/commands/terminal/shared.d.ts +12 -0
  153. package/dist/commands/terminal/shared.js +61 -0
  154. package/dist/commands/workflow/get.d.ts +13 -0
  155. package/dist/commands/workflow/get.js +75 -0
  156. package/dist/commands/workflow/index.d.ts +10 -0
  157. package/dist/commands/workflow/index.js +21 -0
  158. package/dist/commands/workflow/start.d.ts +26 -0
  159. package/dist/commands/workflow/start.js +105 -0
  160. package/dist/commands/workflow/status.d.ts +17 -0
  161. package/dist/commands/workflow/status.js +57 -0
  162. package/dist/commands/worktree/archive.d.ts +20 -0
  163. package/dist/commands/worktree/archive.js +104 -0
  164. package/dist/commands/worktree/create-input.d.ts +15 -0
  165. package/dist/commands/worktree/create-input.js +56 -0
  166. package/dist/commands/worktree/create.d.ts +11 -0
  167. package/dist/commands/worktree/create.js +58 -0
  168. package/dist/commands/worktree/index.d.ts +3 -0
  169. package/dist/commands/worktree/index.js +25 -0
  170. package/dist/commands/worktree/ls.d.ts +19 -0
  171. package/dist/commands/worktree/ls.js +97 -0
  172. package/dist/index.d.ts +2 -0
  173. package/dist/index.js +6 -0
  174. package/dist/output/index.d.ts +45 -0
  175. package/dist/output/index.js +47 -0
  176. package/dist/output/json.d.ts +11 -0
  177. package/dist/output/json.js +37 -0
  178. package/dist/output/quiet.d.ts +9 -0
  179. package/dist/output/quiet.js +22 -0
  180. package/dist/output/render.d.ts +15 -0
  181. package/dist/output/render.js +83 -0
  182. package/dist/output/table.d.ts +13 -0
  183. package/dist/output/table.js +135 -0
  184. package/dist/output/types.d.ts +73 -0
  185. package/dist/output/types.js +8 -0
  186. package/dist/output/with-output.d.ts +41 -0
  187. package/dist/output/with-output.js +87 -0
  188. package/dist/output/yaml.d.ts +11 -0
  189. package/dist/output/yaml.js +38 -0
  190. package/dist/run.d.ts +14 -0
  191. package/dist/run.js +33 -0
  192. package/dist/utils/client-id.d.ts +2 -0
  193. package/dist/utils/client-id.js +37 -0
  194. package/dist/utils/client.d.ts +44 -0
  195. package/dist/utils/client.js +330 -0
  196. package/dist/utils/command-options.d.ts +6 -0
  197. package/dist/utils/command-options.js +17 -0
  198. package/dist/utils/duration.d.ts +7 -0
  199. package/dist/utils/duration.js +38 -0
  200. package/dist/utils/errors.d.ts +5 -0
  201. package/dist/utils/errors.js +10 -0
  202. package/dist/utils/hook-socket.d.ts +2 -0
  203. package/dist/utils/hook-socket.js +35 -0
  204. package/dist/utils/paths.d.ts +12 -0
  205. package/dist/utils/paths.js +22 -0
  206. package/dist/utils/provider-model.d.ts +11 -0
  207. package/dist/utils/provider-model.js +49 -0
  208. package/dist/utils/timeline.d.ts +11 -0
  209. package/dist/utils/timeline.js +11 -0
  210. package/dist/version.d.ts +2 -0
  211. package/dist/version.js +10 -0
  212. package/package.json +48 -0
@@ -0,0 +1,25 @@
1
+ import { Command } from "commander";
2
+ import { runLsCommand } from "./ls.js";
3
+ import { runArchiveCommand } from "./archive.js";
4
+ import { runCreateCommand } from "./create.js";
5
+ import { withOutput } from "../../output/index.js";
6
+ import { addJsonAndDaemonHostOptions } from "../../utils/command-options.js";
7
+ export function createWorktreeCommand() {
8
+ const worktree = new Command("worktree").description("Manage Paseo-managed git worktrees");
9
+ addJsonAndDaemonHostOptions(worktree.command("ls").description("List Paseo-managed git worktrees")).action(withOutput(runLsCommand));
10
+ addJsonAndDaemonHostOptions(worktree
11
+ .command("create")
12
+ .description("Create a Paseo-managed git worktree")
13
+ .option("--mode <mode>", "Creation mode: branch-off, checkout-branch, or checkout-pr")
14
+ .option("--new-branch <name>", "New branch name (--mode branch-off)")
15
+ .option("--base <ref>", "Base ref for new branch (--mode branch-off, defaults to repo default)")
16
+ .option("--branch <name>", "Existing branch to check out (--mode checkout-branch)")
17
+ .option("--pr-number <n>", "Pull request number (--mode checkout-pr)")
18
+ .option("--cwd <path>", "Repository directory (default: current)")).action(withOutput(runCreateCommand));
19
+ addJsonAndDaemonHostOptions(worktree
20
+ .command("archive")
21
+ .description("Archive a worktree (removes worktree and associated branch)")
22
+ .argument("<name>", "Worktree name or branch name")).action(withOutput(runArchiveCommand));
23
+ return worktree;
24
+ }
25
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,19 @@
1
+ import type { Command } from "commander";
2
+ import type { CommandOptions, ListResult, OutputSchema } from "../../output/index.js";
3
+ /** Worktree list item for display */
4
+ export interface WorktreeListItem {
5
+ name: string;
6
+ branch: string;
7
+ cwd: string;
8
+ agent: string;
9
+ }
10
+ export declare function resolvePaseoHomePath(): string;
11
+ export declare function resolvePaseoWorktreesDir(): string;
12
+ /** Schema for worktree ls output */
13
+ export declare const worktreeLsSchema: OutputSchema<WorktreeListItem>;
14
+ export type WorktreeLsResult = ListResult<WorktreeListItem>;
15
+ export interface WorktreeLsOptions extends CommandOptions {
16
+ host?: string;
17
+ }
18
+ export declare function runLsCommand(options: WorktreeLsOptions, _command: Command): Promise<WorktreeLsResult>;
19
+ //# sourceMappingURL=ls.d.ts.map
@@ -0,0 +1,97 @@
1
+ import { homedir } from "node:os";
2
+ import { basename, join, sep } from "node:path";
3
+ import { connectToDaemon, getDaemonHost } from "../../utils/client.js";
4
+ /** Shorten home directory in path */
5
+ function shortenPath(path) {
6
+ const home = process.env.HOME;
7
+ if (home && path.startsWith(home)) {
8
+ return "~" + path.slice(home.length);
9
+ }
10
+ return path;
11
+ }
12
+ /** Extract worktree name from path */
13
+ function extractWorktreeName(path) {
14
+ return basename(path);
15
+ }
16
+ export function resolvePaseoHomePath() {
17
+ return process.env.PASEO_HOME ?? join(homedir(), ".paseo");
18
+ }
19
+ export function resolvePaseoWorktreesDir() {
20
+ return join(resolvePaseoHomePath(), "worktrees");
21
+ }
22
+ function isAgentInManagedWorktree(agentCwd) {
23
+ const worktreesDir = resolvePaseoWorktreesDir();
24
+ return agentCwd === worktreesDir || agentCwd.startsWith(worktreesDir + sep);
25
+ }
26
+ /** Schema for worktree ls output */
27
+ export const worktreeLsSchema = {
28
+ idField: "name",
29
+ columns: [
30
+ { header: "NAME", field: "name", width: 20 },
31
+ { header: "BRANCH", field: "branch", width: 25 },
32
+ { header: "CWD", field: "cwd", width: 45 },
33
+ { header: "AGENT", field: "agent", width: 10 },
34
+ ],
35
+ };
36
+ export async function runLsCommand(options, _command) {
37
+ const host = getDaemonHost({ host: options.host });
38
+ let client;
39
+ try {
40
+ client = await connectToDaemon({ host: options.host });
41
+ }
42
+ catch (err) {
43
+ const message = err instanceof Error ? err.message : String(err);
44
+ const error = {
45
+ code: "DAEMON_NOT_RUNNING",
46
+ message: `Cannot connect to daemon at ${host}: ${message}`,
47
+ details: "Start the daemon with: paseo daemon start",
48
+ };
49
+ throw error;
50
+ }
51
+ try {
52
+ const agentsPayload = await client.fetchAgents({ filter: { includeArchived: true } });
53
+ const agents = agentsPayload.entries.map((entry) => entry.agent);
54
+ // Get worktree list from daemon
55
+ const response = await client.getPaseoWorktreeList({});
56
+ await client.close();
57
+ if (response.error) {
58
+ const error = {
59
+ code: "WORKTREE_LIST_FAILED",
60
+ message: `Failed to list worktrees: ${response.error.message}`,
61
+ };
62
+ throw error;
63
+ }
64
+ // Build a map of worktree paths to agent IDs
65
+ const worktreeAgentMap = new Map();
66
+ for (const agent of agents) {
67
+ if (isAgentInManagedWorktree(agent.cwd)) {
68
+ worktreeAgentMap.set(agent.cwd, agent.id.slice(0, 7));
69
+ }
70
+ }
71
+ const items = response.worktrees.map((wt) => ({
72
+ name: extractWorktreeName(wt.worktreePath),
73
+ branch: wt.branchName ?? "-",
74
+ cwd: shortenPath(wt.worktreePath),
75
+ agent: worktreeAgentMap.get(wt.worktreePath) ?? "-",
76
+ }));
77
+ return {
78
+ type: "list",
79
+ data: items,
80
+ schema: worktreeLsSchema,
81
+ };
82
+ }
83
+ catch (err) {
84
+ await client.close().catch(() => { });
85
+ // Re-throw CommandError as-is
86
+ if (err && typeof err === "object" && "code" in err) {
87
+ throw err;
88
+ }
89
+ const message = err instanceof Error ? err.message : String(err);
90
+ const error = {
91
+ code: "WORKTREE_LIST_FAILED",
92
+ message: `Failed to list worktrees: ${message}`,
93
+ };
94
+ throw error;
95
+ }
96
+ }
97
+ //# sourceMappingURL=ls.js.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=index.d.ts.map
package/dist/index.js ADDED
@@ -0,0 +1,6 @@
1
+ import { runCli } from "./run.js";
2
+ const exitCode = await runCli(process.argv.slice(2), {
3
+ nodeArgv: [process.argv[0] ?? "node", process.argv[1] ?? "paseo"],
4
+ });
5
+ process.exitCode = exitCode;
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Output abstraction layer for the Paseo CLI.
3
+ *
4
+ * This module provides structured output rendering with support for multiple formats:
5
+ * - table: Human-readable aligned tables (default)
6
+ * - json: Machine-readable JSON
7
+ * - yaml: Machine-readable YAML
8
+ * - quiet: Minimal output (IDs only)
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * import { withOutput, render, type ListResult, type OutputSchema } from './output/index.js'
13
+ *
14
+ * // Define your data type
15
+ * interface Agent { id: string; title: string; status: string }
16
+ *
17
+ * // Define how to render it
18
+ * const schema: OutputSchema<Agent> = {
19
+ * idField: 'id',
20
+ * columns: [
21
+ * { header: 'ID', field: 'id' },
22
+ * { header: 'TITLE', field: 'title' },
23
+ * { header: 'STATUS', field: 'status', color: (v) => v === 'running' ? 'green' : undefined },
24
+ * ],
25
+ * }
26
+ *
27
+ * // Return structured data from commands
28
+ * const result: ListResult<Agent> = {
29
+ * type: 'list',
30
+ * data: agents,
31
+ * schema,
32
+ * }
33
+ *
34
+ * // Render with options
35
+ * const output = render(result, { format: 'json' })
36
+ * ```
37
+ */
38
+ export type { OutputFormat, OutputOptions, ColumnDef, OutputSchema, CommandResult, SingleResult, ListResult, AnyCommandResult, CommandError, } from "./types.js";
39
+ export { renderTable, renderTableHeader, renderTableRow } from "./table.js";
40
+ export { renderJson, renderJsonLine } from "./json.js";
41
+ export { renderYaml, renderYamlDoc } from "./yaml.js";
42
+ export { renderQuiet } from "./quiet.js";
43
+ export { render, renderError, toCommandError, defaultOutputOptions } from "./render.js";
44
+ export { withOutput, createOutputOptions, type CommandOptions } from "./with-output.js";
45
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Output abstraction layer for the Paseo CLI.
3
+ *
4
+ * This module provides structured output rendering with support for multiple formats:
5
+ * - table: Human-readable aligned tables (default)
6
+ * - json: Machine-readable JSON
7
+ * - yaml: Machine-readable YAML
8
+ * - quiet: Minimal output (IDs only)
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * import { withOutput, render, type ListResult, type OutputSchema } from './output/index.js'
13
+ *
14
+ * // Define your data type
15
+ * interface Agent { id: string; title: string; status: string }
16
+ *
17
+ * // Define how to render it
18
+ * const schema: OutputSchema<Agent> = {
19
+ * idField: 'id',
20
+ * columns: [
21
+ * { header: 'ID', field: 'id' },
22
+ * { header: 'TITLE', field: 'title' },
23
+ * { header: 'STATUS', field: 'status', color: (v) => v === 'running' ? 'green' : undefined },
24
+ * ],
25
+ * }
26
+ *
27
+ * // Return structured data from commands
28
+ * const result: ListResult<Agent> = {
29
+ * type: 'list',
30
+ * data: agents,
31
+ * schema,
32
+ * }
33
+ *
34
+ * // Render with options
35
+ * const output = render(result, { format: 'json' })
36
+ * ```
37
+ */
38
+ // Renderers
39
+ export { renderTable, renderTableHeader, renderTableRow } from "./table.js";
40
+ export { renderJson, renderJsonLine } from "./json.js";
41
+ export { renderYaml, renderYamlDoc } from "./yaml.js";
42
+ export { renderQuiet } from "./quiet.js";
43
+ // Main render function
44
+ export { render, renderError, toCommandError, defaultOutputOptions } from "./render.js";
45
+ // Command wrapper
46
+ export { withOutput, createOutputOptions } from "./with-output.js";
47
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,11 @@
1
+ /**
2
+ * JSON renderer for CLI output.
3
+ *
4
+ * Renders structured data as formatted JSON for machine consumption.
5
+ */
6
+ import type { AnyCommandResult, OutputOptions } from "./types.js";
7
+ /** Render command result as JSON */
8
+ export declare function renderJson<T>(result: AnyCommandResult<T>, _options: OutputOptions): string;
9
+ /** Render a single item as JSON line (for NDJSON streaming) */
10
+ export declare function renderJsonLine<T>(item: T, serialize?: (data: T) => unknown): string;
11
+ //# sourceMappingURL=json.d.ts.map
@@ -0,0 +1,37 @@
1
+ /**
2
+ * JSON renderer for CLI output.
3
+ *
4
+ * Renders structured data as formatted JSON for machine consumption.
5
+ */
6
+ /** Render command result as JSON */
7
+ export function renderJson(result, _options) {
8
+ const { schema } = result;
9
+ // Apply custom serializer if provided
10
+ if (schema.serialize) {
11
+ if (result.type === "list") {
12
+ // If all items serialize to the same object, return just one
13
+ // This handles the case where a list of key-value rows should serialize
14
+ // to a single structured object
15
+ const serialized = result.data.map((item) => schema.serialize(item));
16
+ if (serialized.length > 0) {
17
+ const first = JSON.stringify(serialized[0]);
18
+ const allSame = serialized.every((s) => JSON.stringify(s) === first);
19
+ if (allSame) {
20
+ return JSON.stringify(serialized[0], null, 2);
21
+ }
22
+ }
23
+ return JSON.stringify(serialized, null, 2);
24
+ }
25
+ else {
26
+ const serialized = schema.serialize(result.data);
27
+ return JSON.stringify(serialized, null, 2);
28
+ }
29
+ }
30
+ return JSON.stringify(result.data, null, 2);
31
+ }
32
+ /** Render a single item as JSON line (for NDJSON streaming) */
33
+ export function renderJsonLine(item, serialize) {
34
+ const output = serialize ? serialize(item) : item;
35
+ return JSON.stringify(output);
36
+ }
37
+ //# sourceMappingURL=json.js.map
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Quiet renderer for CLI output.
3
+ *
4
+ * Outputs only ID fields, one per line. Useful for scripting and pipelines.
5
+ */
6
+ import type { AnyCommandResult, OutputOptions } from "./types.js";
7
+ /** Render command result in quiet mode (IDs only) */
8
+ export declare function renderQuiet<T>(result: AnyCommandResult<T>, _options: OutputOptions): string;
9
+ //# sourceMappingURL=quiet.d.ts.map
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Quiet renderer for CLI output.
3
+ *
4
+ * Outputs only ID fields, one per line. Useful for scripting and pipelines.
5
+ */
6
+ /** Extract ID from item using schema definition */
7
+ function getId(item, idField) {
8
+ if (typeof idField === "function") {
9
+ return idField(item);
10
+ }
11
+ return String(item[idField]);
12
+ }
13
+ /** Render command result in quiet mode (IDs only) */
14
+ export function renderQuiet(result, _options) {
15
+ if (result.type === "single") {
16
+ return getId(result.data, result.schema.idField);
17
+ }
18
+ else {
19
+ return result.data.map((item) => getId(item, result.schema.idField)).join("\n");
20
+ }
21
+ }
22
+ //# sourceMappingURL=quiet.js.map
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Main render dispatcher for CLI output.
3
+ *
4
+ * Selects the appropriate renderer based on output options.
5
+ */
6
+ import type { AnyCommandResult, CommandError, OutputOptions } from "./types.js";
7
+ /** Default output options */
8
+ export declare const defaultOutputOptions: OutputOptions;
9
+ /** Render command result to string based on output options */
10
+ export declare function render<T>(result: AnyCommandResult<T>, options?: Partial<OutputOptions>): string;
11
+ /** Convert an unknown error to a CommandError */
12
+ export declare function toCommandError(error: unknown): CommandError;
13
+ /** Render an error to string based on output options */
14
+ export declare function renderError(error: CommandError, options?: Partial<OutputOptions>): string;
15
+ //# sourceMappingURL=render.d.ts.map
@@ -0,0 +1,83 @@
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
+ if (result.schema.renderHuman) {
35
+ return result.schema.renderHuman(result, opts);
36
+ }
37
+ return renderTable(result, opts);
38
+ }
39
+ }
40
+ /** Convert an unknown error to a CommandError */
41
+ export function toCommandError(error) {
42
+ if (isCommandError(error)) {
43
+ return error;
44
+ }
45
+ if (error instanceof Error) {
46
+ return {
47
+ code: "UNKNOWN_ERROR",
48
+ message: error.message,
49
+ details: error.stack,
50
+ };
51
+ }
52
+ return {
53
+ code: "UNKNOWN_ERROR",
54
+ message: String(error),
55
+ };
56
+ }
57
+ /** Type guard for CommandError */
58
+ function isCommandError(error) {
59
+ return (typeof error === "object" &&
60
+ error !== null &&
61
+ "code" in error &&
62
+ "message" in error &&
63
+ typeof error.code === "string" &&
64
+ typeof error.message === "string");
65
+ }
66
+ /** Render an error to string based on output options */
67
+ export function renderError(error, options = {}) {
68
+ const opts = { ...defaultOutputOptions, ...options };
69
+ if (opts.format === "json") {
70
+ return JSON.stringify({ error }, null, 2);
71
+ }
72
+ if (opts.format === "yaml") {
73
+ return YAML.stringify({ error });
74
+ }
75
+ // Table/default format: human-readable error
76
+ const prefix = opts.noColor ? "Error: " : chalk.red("Error: ");
77
+ const message = error.message;
78
+ if (error.details && typeof error.details === "string") {
79
+ return `${prefix}${message}\n${error.details}`;
80
+ }
81
+ return `${prefix}${message}`;
82
+ }
83
+ //# sourceMappingURL=render.js.map
@@ -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,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,73 @@
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: custom renderer for human/table output */
40
+ renderHuman?: (result: AnyCommandResult<T>, options: OutputOptions) => string;
41
+ /** Optional: transform data before JSON/YAML output */
42
+ serialize?: (data: T) => unknown;
43
+ }
44
+ /** Result type for commands returning a single item */
45
+ export interface SingleResult<T> {
46
+ type: "single";
47
+ /** The structured data to render */
48
+ data: T;
49
+ /** Schema describing how to render this data (for item type T) */
50
+ schema: OutputSchema<T>;
51
+ }
52
+ /** Result type for commands returning a list */
53
+ export interface ListResult<T> {
54
+ type: "list";
55
+ /** The structured data to render */
56
+ data: T[];
57
+ /** Schema describing how to render this data (for item type T) */
58
+ schema: OutputSchema<T>;
59
+ }
60
+ /** Union type for all command results */
61
+ export type AnyCommandResult<T> = SingleResult<T> | ListResult<T>;
62
+ /** Base interface for command results (deprecated, use SingleResult or ListResult) */
63
+ export type CommandResult<T> = SingleResult<T> | ListResult<T>;
64
+ /** Structured error for command failures */
65
+ export interface CommandError {
66
+ /** Machine-readable error code */
67
+ code: string;
68
+ /** Human-readable message */
69
+ message: string;
70
+ /** Additional context */
71
+ details?: unknown;
72
+ }
73
+ //# sourceMappingURL=types.d.ts.map
@@ -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