htpx-cli 0.1.2 → 0.2.0

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 (252) hide show
  1. package/LICENSE +665 -21
  2. package/README.md +422 -116
  3. package/dist/cli/commands/clear.d.ts.map +1 -1
  4. package/dist/cli/commands/clear.js +11 -11
  5. package/dist/cli/commands/clear.js.map +1 -1
  6. package/dist/cli/commands/daemon.d.ts +3 -0
  7. package/dist/cli/commands/daemon.d.ts.map +1 -0
  8. package/dist/cli/commands/daemon.js +59 -0
  9. package/dist/cli/commands/daemon.js.map +1 -0
  10. package/dist/cli/commands/debug-dump.d.ts.map +1 -1
  11. package/dist/cli/commands/debug-dump.js +8 -10
  12. package/dist/cli/commands/debug-dump.js.map +1 -1
  13. package/dist/cli/commands/helpers.d.ts +18 -0
  14. package/dist/cli/commands/helpers.d.ts.map +1 -0
  15. package/dist/cli/commands/helpers.js +34 -0
  16. package/dist/cli/commands/helpers.js.map +1 -0
  17. package/dist/cli/commands/init.d.ts +1 -1
  18. package/dist/cli/commands/init.d.ts.map +1 -1
  19. package/dist/cli/commands/init.js +3 -4
  20. package/dist/cli/commands/init.js.map +1 -1
  21. package/dist/cli/commands/intercept.d.ts +2 -1
  22. package/dist/cli/commands/intercept.d.ts.map +1 -1
  23. package/dist/cli/commands/intercept.js +74 -30
  24. package/dist/cli/commands/intercept.js.map +1 -1
  25. package/dist/cli/commands/interceptors.d.ts +3 -0
  26. package/dist/cli/commands/interceptors.d.ts.map +1 -0
  27. package/dist/cli/commands/interceptors.js +163 -0
  28. package/dist/cli/commands/interceptors.js.map +1 -0
  29. package/dist/cli/commands/mcp.d.ts +3 -0
  30. package/dist/cli/commands/mcp.d.ts.map +1 -0
  31. package/dist/cli/commands/mcp.js +24 -0
  32. package/dist/cli/commands/mcp.js.map +1 -0
  33. package/dist/cli/commands/off.d.ts +8 -0
  34. package/dist/cli/commands/off.d.ts.map +1 -0
  35. package/dist/cli/commands/off.js +34 -0
  36. package/dist/cli/commands/off.js.map +1 -0
  37. package/dist/cli/commands/on.d.ts +9 -0
  38. package/dist/cli/commands/on.d.ts.map +1 -0
  39. package/dist/cli/commands/on.js +121 -0
  40. package/dist/cli/commands/on.js.map +1 -0
  41. package/dist/cli/commands/project.d.ts.map +1 -1
  42. package/dist/cli/commands/project.js +5 -3
  43. package/dist/cli/commands/project.js.map +1 -1
  44. package/dist/cli/commands/restart.d.ts.map +1 -1
  45. package/dist/cli/commands/restart.js +5 -10
  46. package/dist/cli/commands/restart.js.map +1 -1
  47. package/dist/cli/commands/status.d.ts.map +1 -1
  48. package/dist/cli/commands/status.js +50 -20
  49. package/dist/cli/commands/status.js.map +1 -1
  50. package/dist/cli/commands/stop.d.ts.map +1 -1
  51. package/dist/cli/commands/stop.js +7 -10
  52. package/dist/cli/commands/stop.js.map +1 -1
  53. package/dist/cli/commands/tui.d.ts.map +1 -1
  54. package/dist/cli/commands/tui.js +6 -13
  55. package/dist/cli/commands/tui.js.map +1 -1
  56. package/dist/cli/index.js +12 -7
  57. package/dist/cli/index.js.map +1 -1
  58. package/dist/cli/tui/App.d.ts +7 -2
  59. package/dist/cli/tui/App.d.ts.map +1 -1
  60. package/dist/cli/tui/App.js +490 -33
  61. package/dist/cli/tui/App.js.map +1 -1
  62. package/dist/cli/tui/components/AccordionContent.d.ts +28 -0
  63. package/dist/cli/tui/components/AccordionContent.d.ts.map +1 -0
  64. package/dist/cli/tui/components/AccordionContent.js +87 -0
  65. package/dist/cli/tui/components/AccordionContent.js.map +1 -0
  66. package/dist/cli/tui/components/AccordionPanel.d.ts +38 -0
  67. package/dist/cli/tui/components/AccordionPanel.d.ts.map +1 -0
  68. package/dist/cli/tui/components/AccordionPanel.js +110 -0
  69. package/dist/cli/tui/components/AccordionPanel.js.map +1 -0
  70. package/dist/cli/tui/components/AccordionSection.d.ts +32 -0
  71. package/dist/cli/tui/components/AccordionSection.d.ts.map +1 -0
  72. package/dist/cli/tui/components/AccordionSection.js +41 -0
  73. package/dist/cli/tui/components/AccordionSection.js.map +1 -0
  74. package/dist/cli/tui/components/ExportModal.d.ts +34 -0
  75. package/dist/cli/tui/components/ExportModal.d.ts.map +1 -0
  76. package/dist/cli/tui/components/ExportModal.js +109 -0
  77. package/dist/cli/tui/components/ExportModal.js.map +1 -0
  78. package/dist/cli/tui/components/FilterBar.d.ts +21 -0
  79. package/dist/cli/tui/components/FilterBar.d.ts.map +1 -0
  80. package/dist/cli/tui/components/FilterBar.js +155 -0
  81. package/dist/cli/tui/components/FilterBar.js.map +1 -0
  82. package/dist/cli/tui/components/HelpModal.d.ts +13 -0
  83. package/dist/cli/tui/components/HelpModal.d.ts.map +1 -0
  84. package/dist/cli/tui/components/HelpModal.js +78 -0
  85. package/dist/cli/tui/components/HelpModal.js.map +1 -0
  86. package/dist/cli/tui/components/HintContent.d.ts +25 -0
  87. package/dist/cli/tui/components/HintContent.d.ts.map +1 -0
  88. package/dist/cli/tui/components/HintContent.js +44 -0
  89. package/dist/cli/tui/components/HintContent.js.map +1 -0
  90. package/dist/cli/tui/components/InfoModal.d.ts +15 -0
  91. package/dist/cli/tui/components/InfoModal.d.ts.map +1 -0
  92. package/dist/cli/tui/components/InfoModal.js +17 -0
  93. package/dist/cli/tui/components/InfoModal.js.map +1 -0
  94. package/dist/cli/tui/components/JsonExplorerModal.d.ts +24 -0
  95. package/dist/cli/tui/components/JsonExplorerModal.d.ts.map +1 -0
  96. package/dist/cli/tui/components/JsonExplorerModal.js +311 -0
  97. package/dist/cli/tui/components/JsonExplorerModal.js.map +1 -0
  98. package/dist/cli/tui/components/Modal.d.ts +26 -0
  99. package/dist/cli/tui/components/Modal.d.ts.map +1 -0
  100. package/dist/cli/tui/components/Modal.js +15 -0
  101. package/dist/cli/tui/components/Modal.js.map +1 -0
  102. package/dist/cli/tui/components/Panel.d.ts +19 -0
  103. package/dist/cli/tui/components/Panel.d.ts.map +1 -0
  104. package/dist/cli/tui/components/Panel.js +37 -0
  105. package/dist/cli/tui/components/Panel.js.map +1 -0
  106. package/dist/cli/tui/components/RequestDetails.d.ts +4 -1
  107. package/dist/cli/tui/components/RequestDetails.d.ts.map +1 -1
  108. package/dist/cli/tui/components/RequestDetails.js +9 -5
  109. package/dist/cli/tui/components/RequestDetails.js.map +1 -1
  110. package/dist/cli/tui/components/RequestList.d.ts +9 -3
  111. package/dist/cli/tui/components/RequestList.d.ts.map +1 -1
  112. package/dist/cli/tui/components/RequestList.js +24 -11
  113. package/dist/cli/tui/components/RequestList.js.map +1 -1
  114. package/dist/cli/tui/components/RequestListItem.d.ts +26 -3
  115. package/dist/cli/tui/components/RequestListItem.d.ts.map +1 -1
  116. package/dist/cli/tui/components/RequestListItem.js +86 -9
  117. package/dist/cli/tui/components/RequestListItem.js.map +1 -1
  118. package/dist/cli/tui/components/SaveModal.d.ts +30 -0
  119. package/dist/cli/tui/components/SaveModal.d.ts.map +1 -0
  120. package/dist/cli/tui/components/SaveModal.js +95 -0
  121. package/dist/cli/tui/components/SaveModal.js.map +1 -0
  122. package/dist/cli/tui/components/StatusBar.d.ts +31 -2
  123. package/dist/cli/tui/components/StatusBar.d.ts.map +1 -1
  124. package/dist/cli/tui/components/StatusBar.js +44 -9
  125. package/dist/cli/tui/components/StatusBar.js.map +1 -1
  126. package/dist/cli/tui/components/TextViewerModal.d.ts +19 -0
  127. package/dist/cli/tui/components/TextViewerModal.d.ts.map +1 -0
  128. package/dist/cli/tui/components/TextViewerModal.js +227 -0
  129. package/dist/cli/tui/components/TextViewerModal.js.map +1 -0
  130. package/dist/cli/tui/hooks/useBodyExport.d.ts +26 -0
  131. package/dist/cli/tui/hooks/useBodyExport.d.ts.map +1 -0
  132. package/dist/cli/tui/hooks/useBodyExport.js +173 -0
  133. package/dist/cli/tui/hooks/useBodyExport.js.map +1 -0
  134. package/dist/cli/tui/hooks/useExport.d.ts +13 -2
  135. package/dist/cli/tui/hooks/useExport.d.ts.map +1 -1
  136. package/dist/cli/tui/hooks/useExport.js +46 -40
  137. package/dist/cli/tui/hooks/useExport.js.map +1 -1
  138. package/dist/cli/tui/hooks/useRequests.d.ts +9 -3
  139. package/dist/cli/tui/hooks/useRequests.d.ts.map +1 -1
  140. package/dist/cli/tui/hooks/useRequests.js +61 -15
  141. package/dist/cli/tui/hooks/useRequests.js.map +1 -1
  142. package/dist/cli/tui/hooks/useSaveBinary.d.ts +26 -0
  143. package/dist/cli/tui/hooks/useSaveBinary.d.ts.map +1 -0
  144. package/dist/cli/tui/hooks/useSaveBinary.js +165 -0
  145. package/dist/cli/tui/hooks/useSaveBinary.js.map +1 -0
  146. package/dist/cli/tui/hooks/useSpinner.d.ts +5 -0
  147. package/dist/cli/tui/hooks/useSpinner.d.ts.map +1 -0
  148. package/dist/cli/tui/hooks/useSpinner.js +25 -0
  149. package/dist/cli/tui/hooks/useSpinner.js.map +1 -0
  150. package/dist/cli/tui/utils/binary.d.ts +24 -0
  151. package/dist/cli/tui/utils/binary.d.ts.map +1 -0
  152. package/dist/cli/tui/utils/binary.js +152 -0
  153. package/dist/cli/tui/utils/binary.js.map +1 -0
  154. package/dist/cli/tui/utils/clipboard.d.ts +9 -0
  155. package/dist/cli/tui/utils/clipboard.d.ts.map +1 -0
  156. package/dist/cli/tui/utils/clipboard.js +58 -0
  157. package/dist/cli/tui/utils/clipboard.js.map +1 -0
  158. package/dist/cli/tui/utils/content-type.d.ts +8 -0
  159. package/dist/cli/tui/utils/content-type.d.ts.map +1 -0
  160. package/dist/cli/tui/utils/content-type.js +10 -0
  161. package/dist/cli/tui/utils/content-type.js.map +1 -0
  162. package/dist/cli/tui/utils/curl.d.ts.map +1 -1
  163. package/dist/cli/tui/utils/curl.js +9 -2
  164. package/dist/cli/tui/utils/curl.js.map +1 -1
  165. package/dist/cli/tui/utils/filters.d.ts +6 -0
  166. package/dist/cli/tui/utils/filters.d.ts.map +1 -0
  167. package/dist/cli/tui/utils/filters.js +13 -0
  168. package/dist/cli/tui/utils/filters.js.map +1 -0
  169. package/dist/cli/tui/utils/formatters.d.ts +8 -0
  170. package/dist/cli/tui/utils/formatters.d.ts.map +1 -1
  171. package/dist/cli/tui/utils/formatters.js +85 -0
  172. package/dist/cli/tui/utils/formatters.js.map +1 -1
  173. package/dist/cli/tui/utils/har.d.ts.map +1 -1
  174. package/dist/cli/tui/utils/har.js +3 -25
  175. package/dist/cli/tui/utils/har.js.map +1 -1
  176. package/dist/cli/tui/utils/json-tree.d.ts +69 -0
  177. package/dist/cli/tui/utils/json-tree.d.ts.map +1 -0
  178. package/dist/cli/tui/utils/json-tree.js +339 -0
  179. package/dist/cli/tui/utils/json-tree.js.map +1 -0
  180. package/dist/cli/tui/utils/open-external.d.ts +17 -0
  181. package/dist/cli/tui/utils/open-external.d.ts.map +1 -0
  182. package/dist/cli/tui/utils/open-external.js +57 -0
  183. package/dist/cli/tui/utils/open-external.js.map +1 -0
  184. package/dist/cli/tui/utils/syntax-highlight.d.ts +16 -0
  185. package/dist/cli/tui/utils/syntax-highlight.d.ts.map +1 -0
  186. package/dist/cli/tui/utils/syntax-highlight.js +64 -0
  187. package/dist/cli/tui/utils/syntax-highlight.js.map +1 -0
  188. package/dist/daemon/control.d.ts +3 -49
  189. package/dist/daemon/control.d.ts.map +1 -1
  190. package/dist/daemon/control.js +183 -141
  191. package/dist/daemon/control.js.map +1 -1
  192. package/dist/daemon/htpx-client.d.ts +8 -0
  193. package/dist/daemon/htpx-client.d.ts.map +1 -0
  194. package/dist/daemon/htpx-client.js +25 -0
  195. package/dist/daemon/htpx-client.js.map +1 -0
  196. package/dist/daemon/index.js +50 -2
  197. package/dist/daemon/index.js.map +1 -1
  198. package/dist/daemon/interceptor-loader.d.ts +30 -0
  199. package/dist/daemon/interceptor-loader.d.ts.map +1 -0
  200. package/dist/daemon/interceptor-loader.js +249 -0
  201. package/dist/daemon/interceptor-loader.js.map +1 -0
  202. package/dist/daemon/interceptor-runner.d.ts +39 -0
  203. package/dist/daemon/interceptor-runner.d.ts.map +1 -0
  204. package/dist/daemon/interceptor-runner.js +312 -0
  205. package/dist/daemon/interceptor-runner.js.map +1 -0
  206. package/dist/daemon/proxy.d.ts +12 -0
  207. package/dist/daemon/proxy.d.ts.map +1 -1
  208. package/dist/daemon/proxy.js +121 -10
  209. package/dist/daemon/proxy.js.map +1 -1
  210. package/dist/daemon/storage.d.ts +64 -2
  211. package/dist/daemon/storage.d.ts.map +1 -1
  212. package/dist/daemon/storage.js +527 -12
  213. package/dist/daemon/storage.js.map +1 -1
  214. package/dist/interceptors.d.ts +2 -0
  215. package/dist/interceptors.d.ts.map +1 -0
  216. package/dist/interceptors.js +2 -0
  217. package/dist/interceptors.js.map +1 -0
  218. package/dist/mcp/server.d.ts +110 -0
  219. package/dist/mcp/server.d.ts.map +1 -0
  220. package/dist/mcp/server.js +806 -0
  221. package/dist/mcp/server.js.map +1 -0
  222. package/dist/shared/config.d.ts +21 -0
  223. package/dist/shared/config.d.ts.map +1 -0
  224. package/dist/shared/config.js +83 -0
  225. package/dist/shared/config.js.map +1 -0
  226. package/dist/shared/content-type.d.ts +64 -0
  227. package/dist/shared/content-type.d.ts.map +1 -0
  228. package/dist/shared/content-type.js +145 -0
  229. package/dist/shared/content-type.js.map +1 -0
  230. package/dist/shared/control-client.d.ts +144 -0
  231. package/dist/shared/control-client.d.ts.map +1 -0
  232. package/dist/shared/control-client.js +272 -0
  233. package/dist/shared/control-client.js.map +1 -0
  234. package/dist/shared/daemon.d.ts.map +1 -1
  235. package/dist/shared/daemon.js +17 -4
  236. package/dist/shared/daemon.js.map +1 -1
  237. package/dist/shared/logger.d.ts +21 -5
  238. package/dist/shared/logger.d.ts.map +1 -1
  239. package/dist/shared/logger.js +100 -21
  240. package/dist/shared/logger.js.map +1 -1
  241. package/dist/shared/project.d.ts +16 -3
  242. package/dist/shared/project.d.ts.map +1 -1
  243. package/dist/shared/project.js +45 -5
  244. package/dist/shared/project.js.map +1 -1
  245. package/dist/shared/proxy-info.d.ts +10 -0
  246. package/dist/shared/proxy-info.d.ts.map +1 -0
  247. package/dist/shared/proxy-info.js +15 -0
  248. package/dist/shared/proxy-info.js.map +1 -0
  249. package/dist/shared/types.d.ts +95 -0
  250. package/dist/shared/types.d.ts.map +1 -1
  251. package/package.json +24 -5
  252. package/skills/htpx/SKILL.md +228 -0
@@ -0,0 +1,163 @@
1
+ import * as fs from "node:fs";
2
+ import * as path from "node:path";
3
+ import { Command } from "commander";
4
+ import { ControlClient } from "../../shared/control-client.js";
5
+ import { getHtpxPaths } from "../../shared/project.js";
6
+ import { isDaemonRunning } from "../../shared/daemon.js";
7
+ import { requireProjectRoot, getErrorMessage, getGlobalOptions } from "./helpers.js";
8
+ const EXAMPLE_INTERCEPTOR_FILENAME = "example.ts";
9
+ const EXAMPLE_INTERCEPTOR_CONTENT = `// Example htpx interceptor
10
+ // Uncomment and modify one of the patterns below to get started.
11
+ //
12
+ // Run \`htpx interceptors reload\` after editing, or run \`htpx daemon restart\`.
13
+
14
+ import type { Interceptor } from "htpx-cli/interceptors";
15
+
16
+ // --- Mock pattern: return a canned response without hitting the real server ---
17
+ //
18
+ // export default {
19
+ // name: "mock-users-api",
20
+ // match: (req) => req.path === "/api/users",
21
+ // handler: async () => ({
22
+ // status: 200,
23
+ // headers: { "content-type": "application/json" },
24
+ // body: JSON.stringify([{ id: 1, name: "Alice" }]),
25
+ // }),
26
+ // } satisfies Interceptor;
27
+
28
+ // --- Modify pattern: forward the request then alter the response ---
29
+ //
30
+ // export default {
31
+ // name: "inject-header",
32
+ // match: (req) => req.host.includes("example.com"),
33
+ // handler: async (ctx) => {
34
+ // const response = await ctx.forward();
35
+ // response.headers = { ...response.headers, "x-debug": "htpx" };
36
+ // return response;
37
+ // },
38
+ // } satisfies Interceptor;
39
+
40
+ // --- Observe pattern: log or inspect traffic without altering it ---
41
+ //
42
+ // export default {
43
+ // name: "log-api-calls",
44
+ // match: (req) => req.path.startsWith("/api/"),
45
+ // handler: async (ctx) => {
46
+ // ctx.log(\`\${ctx.request.method} \${ctx.request.url}\`);
47
+ // const response = await ctx.forward();
48
+ // ctx.log(\` -> \${response.status}\`);
49
+ // return response;
50
+ // },
51
+ // } satisfies Interceptor;
52
+ `;
53
+ /**
54
+ * Format interceptor info as a table row.
55
+ */
56
+ function formatInterceptorRow(name, sourceFile, hasMatch, error) {
57
+ const nameCol = name.padEnd(24);
58
+ const fileCol = sourceFile.padEnd(32);
59
+ const matchCol = hasMatch ? "yes" : "no ";
60
+ const errorCol = error ?? "";
61
+ return ` ${nameCol} ${fileCol} ${matchCol} ${errorCol}`;
62
+ }
63
+ /**
64
+ * Shared implementation for the list action (used by both `interceptors` and `interceptors list`).
65
+ */
66
+ async function listAction(command) {
67
+ const globalOpts = getGlobalOptions(command);
68
+ const projectRoot = requireProjectRoot(globalOpts.dir);
69
+ const paths = getHtpxPaths(projectRoot);
70
+ const running = await isDaemonRunning(projectRoot);
71
+ if (!running) {
72
+ console.log("Daemon is not running");
73
+ process.exit(0);
74
+ }
75
+ const client = new ControlClient(paths.controlSocketFile);
76
+ try {
77
+ const interceptors = await client.listInterceptors();
78
+ if (interceptors.length === 0) {
79
+ console.log("No interceptors loaded");
80
+ return;
81
+ }
82
+ console.log(` ${"Name".padEnd(24)} ${"Source".padEnd(32)} Match Error`);
83
+ console.log(` ${"─".repeat(24)} ${"─".repeat(32)} ${"─".repeat(5)} ${"─".repeat(20)}`);
84
+ for (const info of interceptors) {
85
+ const relativeSource = path.relative(projectRoot, info.sourceFile) || info.sourceFile;
86
+ console.log(formatInterceptorRow(info.name, relativeSource, info.hasMatch, info.error));
87
+ }
88
+ }
89
+ catch (err) {
90
+ console.error(`Error listing interceptors: ${getErrorMessage(err)}`);
91
+ process.exit(1);
92
+ }
93
+ finally {
94
+ client.close();
95
+ }
96
+ }
97
+ const listSubcommand = new Command("list")
98
+ .description("List loaded interceptors")
99
+ .action(async (_, command) => {
100
+ await listAction(command);
101
+ });
102
+ const reloadSubcommand = new Command("reload")
103
+ .description("Reload interceptors from disk")
104
+ .action(async (_, command) => {
105
+ const globalOpts = getGlobalOptions(command);
106
+ const projectRoot = requireProjectRoot(globalOpts.dir);
107
+ const paths = getHtpxPaths(projectRoot);
108
+ const running = await isDaemonRunning(projectRoot);
109
+ if (!running) {
110
+ console.log("Daemon is not running");
111
+ process.exit(0);
112
+ }
113
+ const client = new ControlClient(paths.controlSocketFile);
114
+ try {
115
+ const result = await client.reloadInterceptors();
116
+ if (result.success) {
117
+ console.log(`Reloaded ${result.count} interceptor${result.count === 1 ? "" : "s"}`);
118
+ }
119
+ else {
120
+ console.log(result.error ?? "Reload failed");
121
+ process.exit(1);
122
+ }
123
+ }
124
+ catch (err) {
125
+ console.error(`Error reloading interceptors: ${getErrorMessage(err)}`);
126
+ process.exit(1);
127
+ }
128
+ finally {
129
+ client.close();
130
+ }
131
+ });
132
+ const initSubcommand = new Command("init")
133
+ .description("Create example interceptor file")
134
+ .action(async (_, command) => {
135
+ const globalOpts = getGlobalOptions(command);
136
+ const projectRoot = requireProjectRoot(globalOpts.dir);
137
+ const paths = getHtpxPaths(projectRoot);
138
+ const interceptorsDir = paths.interceptorsDir;
139
+ if (!fs.existsSync(interceptorsDir)) {
140
+ fs.mkdirSync(interceptorsDir, { recursive: true });
141
+ }
142
+ const exampleFile = path.join(interceptorsDir, EXAMPLE_INTERCEPTOR_FILENAME);
143
+ if (fs.existsSync(exampleFile)) {
144
+ console.log(`Example file already exists: ${exampleFile}`);
145
+ return;
146
+ }
147
+ fs.writeFileSync(exampleFile, EXAMPLE_INTERCEPTOR_CONTENT, "utf-8");
148
+ console.log(`Created ${exampleFile}`);
149
+ console.log("");
150
+ console.log("Edit the file to define your interceptor, then either:");
151
+ console.log(" - Restart the daemon (htpx daemon restart)");
152
+ console.log(" - Run: htpx interceptors reload");
153
+ });
154
+ export const interceptorsCommand = new Command("interceptors")
155
+ .description("Manage request interceptors")
156
+ .addCommand(listSubcommand)
157
+ .addCommand(reloadSubcommand)
158
+ .addCommand(initSubcommand)
159
+ .action(async (_, command) => {
160
+ // Default action when no subcommand is specified — behaves like `list`
161
+ await listAction(command);
162
+ });
163
+ //# sourceMappingURL=interceptors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interceptors.js","sourceRoot":"","sources":["../../../src/cli/commands/interceptors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AAC/D,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAErF,MAAM,4BAA4B,GAAG,YAAY,CAAC;AAElD,MAAM,2BAA2B,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA2CnC,CAAC;AAEF;;GAEG;AACH,SAAS,oBAAoB,CAC3B,IAAY,EACZ,UAAkB,EAClB,QAAiB,EACjB,KAAc;IAEd,MAAM,OAAO,GAAG,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;IAChC,MAAM,OAAO,GAAG,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;IACtC,MAAM,QAAQ,GAAG,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC;IAC1C,MAAM,QAAQ,GAAG,KAAK,IAAI,EAAE,CAAC;IAC7B,OAAO,KAAK,OAAO,IAAI,OAAO,IAAI,QAAQ,OAAO,QAAQ,EAAE,CAAC;AAC9D,CAAC;AAED;;GAEG;AACH,KAAK,UAAU,UAAU,CAAC,OAAgB;IACxC,MAAM,UAAU,GAAG,gBAAgB,CAAC,OAAO,CAAC,CAAC;IAC7C,MAAM,WAAW,GAAG,kBAAkB,CAAC,UAA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;QAC/B,OAAO,CAAC,GAAG,CAAC,gCAAgC,WAAW,EAAE,CAAC,CAAC;QAC3D,OAAO;IACT,CAAC;IAED,EAAE,CAAC,aAAa,CAAC,WAAW,EAAE,2BAA2B,EAAE,OAAO,CAAC,CAAC;IACpE,OAAO,CAAC,GAAG,CAAC,WAAW,WAAW,EAAE,CAAC,CAAC;IACtC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAChB,OAAO,CAAC,GAAG,CAAC,wDAAwD,CAAC,CAAC;IACtE,OAAO,CAAC,GAAG,CAAC,8CAA8C,CAAC,CAAC;IAC5D,OAAO,CAAC,GAAG,CAAC,mCAAmC,CAAC,CAAC;AACnD,CAAC,CAAC,CAAC;AAEL,MAAM,CAAC,MAAM,mBAAmB,GAAG,IAAI,OAAO,CAAC,cAAc,CAAC;KAC3D,WAAW,CAAC,6BAA6B,CAAC;KAC1C,UAAU,CAAC,cAAc,CAAC;KAC1B,UAAU,CAAC,gBAAgB,CAAC;KAC5B,UAAU,CAAC,cAAc,CAAC;KAC1B,MAAM,CAAC,KAAK,EAAE,CAAC,EAAE,OAAgB,EAAE,EAAE;IACpC,uEAAuE;IACvE,MAAM,UAAU,CAAC,OAAO,CAAC,CAAC;AAC5B,CAAC,CAAC,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { Command } from "commander";
2
+ export declare const mcpCommand: Command;
3
+ //# sourceMappingURL=mcp.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcp.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/mcp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAIpC,eAAO,MAAM,UAAU,SAsBnB,CAAC"}
@@ -0,0 +1,24 @@
1
+ import { Command } from "commander";
2
+ import { createHtpxMcpServer } from "../../mcp/server.js";
3
+ import { getGlobalOptions, requireProjectRoot } from "./helpers.js";
4
+ export const mcpCommand = new Command("mcp")
5
+ .description("Start the htpx MCP server (stdio transport for AI tool integration)")
6
+ .action(async (_, command) => {
7
+ const globalOpts = getGlobalOptions(command);
8
+ const projectRoot = requireProjectRoot(globalOpts.dir);
9
+ const mcp = createHtpxMcpServer({ projectRoot });
10
+ let closing = false;
11
+ const shutdown = async () => {
12
+ if (closing)
13
+ return;
14
+ closing = true;
15
+ await mcp.close();
16
+ process.exit(0);
17
+ };
18
+ process.on("SIGINT", shutdown);
19
+ process.on("SIGTERM", shutdown);
20
+ await mcp.start();
21
+ // Log to stderr (stdout is reserved for MCP JSON-RPC protocol)
22
+ process.stderr.write(`htpx MCP server running (project: ${projectRoot})\n`);
23
+ });
24
+ //# sourceMappingURL=mcp.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcp.js","sourceRoot":"","sources":["../../../src/cli/commands/mcp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAEpE,MAAM,CAAC,MAAM,UAAU,GAAG,IAAI,OAAO,CAAC,KAAK,CAAC;KACzC,WAAW,CAAC,qEAAqE,CAAC;KAClF,MAAM,CAAC,KAAK,EAAE,CAAC,EAAE,OAAgB,EAAE,EAAE;IACpC,MAAM,UAAU,GAAG,gBAAgB,CAAC,OAAO,CAAC,CAAC;IAC7C,MAAM,WAAW,GAAG,kBAAkB,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;IAEvD,MAAM,GAAG,GAAG,mBAAmB,CAAC,EAAE,WAAW,EAAE,CAAC,CAAC;IAEjD,IAAI,OAAO,GAAG,KAAK,CAAC;IACpB,MAAM,QAAQ,GAAG,KAAK,IAAI,EAAE;QAC1B,IAAI,OAAO;YAAE,OAAO;QACpB,OAAO,GAAG,IAAI,CAAC;QACf,MAAM,GAAG,CAAC,KAAK,EAAE,CAAC;QAClB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC,CAAC;IACF,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;IAC/B,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;IAEhC,MAAM,GAAG,CAAC,KAAK,EAAE,CAAC;IAElB,+DAA+D;IAC/D,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,qCAAqC,WAAW,KAAK,CAAC,CAAC;AAC9E,CAAC,CAAC,CAAC"}
@@ -0,0 +1,8 @@
1
+ import { Command } from "commander";
2
+ /**
3
+ * Format environment variable unset statements for shell evaluation.
4
+ * Each line is an unset statement for one variable.
5
+ */
6
+ export declare function formatUnsetVars(vars: string[]): string;
7
+ export declare const offCommand: Command;
8
+ //# sourceMappingURL=off.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"off.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/off.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC;;;GAGG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,MAAM,CAEtD;AAED,eAAO,MAAM,UAAU,SA2BnB,CAAC"}
@@ -0,0 +1,34 @@
1
+ import { Command } from "commander";
2
+ /**
3
+ * Format environment variable unset statements for shell evaluation.
4
+ * Each line is an unset statement for one variable.
5
+ */
6
+ export function formatUnsetVars(vars) {
7
+ return vars.map((key) => `unset ${key}`).join("\n");
8
+ }
9
+ export const offCommand = new Command("off")
10
+ .description("Stop intercepting HTTP traffic in this shell")
11
+ .action(() => {
12
+ // If stdout is a TTY, user ran directly - show instructions instead
13
+ if (process.stdout.isTTY) {
14
+ console.log("To stop intercepting HTTP traffic, run:");
15
+ console.log("");
16
+ console.log(" eval $(htpx off)");
17
+ return;
18
+ }
19
+ // Environment variables set by htpx on
20
+ const envVars = [
21
+ "HTTP_PROXY",
22
+ "HTTPS_PROXY",
23
+ "SSL_CERT_FILE",
24
+ "REQUESTS_CA_BUNDLE",
25
+ "NODE_EXTRA_CA_CERTS",
26
+ "HTPX_SESSION_ID",
27
+ "HTPX_LABEL",
28
+ ];
29
+ // Output unset statements for eval
30
+ console.log(formatUnsetVars(envVars));
31
+ // Output confirmation as a comment (shown but not executed)
32
+ console.log("# htpx: interception stopped");
33
+ });
34
+ //# sourceMappingURL=off.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"off.js","sourceRoot":"","sources":["../../../src/cli/commands/off.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC;;;GAGG;AACH,MAAM,UAAU,eAAe,CAAC,IAAc;IAC5C,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,SAAS,GAAG,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACtD,CAAC;AAED,MAAM,CAAC,MAAM,UAAU,GAAG,IAAI,OAAO,CAAC,KAAK,CAAC;KACzC,WAAW,CAAC,8CAA8C,CAAC;KAC3D,MAAM,CAAC,GAAG,EAAE;IACX,oEAAoE;IACpE,IAAI,OAAO,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;QACzB,OAAO,CAAC,GAAG,CAAC,yCAAyC,CAAC,CAAC;QACvD,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QAChB,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAC,CAAC;QAClC,OAAO;IACT,CAAC;IAED,uCAAuC;IACvC,MAAM,OAAO,GAAG;QACd,YAAY;QACZ,aAAa;QACb,eAAe;QACf,oBAAoB;QACpB,qBAAqB;QACrB,iBAAiB;QACjB,YAAY;KACb,CAAC;IAEF,mCAAmC;IACnC,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC,CAAC;IAEtC,4DAA4D;IAC5D,OAAO,CAAC,GAAG,CAAC,8BAA8B,CAAC,CAAC;AAC9C,CAAC,CAAC,CAAC"}
@@ -0,0 +1,9 @@
1
+ import { Command } from "commander";
2
+ /**
3
+ * Format environment variable exports for shell evaluation.
4
+ * Each line is a shell export statement. Values are escaped for
5
+ * safe use in double-quoted context.
6
+ */
7
+ export declare function formatEnvVars(vars: Record<string, string>): string;
8
+ export declare const onCommand: Command;
9
+ //# sourceMappingURL=on.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"on.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/on.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAoBpC;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,CAIlE;AAED,eAAO,MAAM,SAAS,SAoGlB,CAAC"}
@@ -0,0 +1,121 @@
1
+ import { Command } from "commander";
2
+ import { findOrCreateProjectRoot, ensureHtpxDir, getHtpxPaths } from "../../shared/project.js";
3
+ import { startDaemon } from "../../shared/daemon.js";
4
+ import { ControlClient } from "../../shared/control-client.js";
5
+ import { parseVerbosity } from "../../shared/logger.js";
6
+ import { getErrorMessage, getGlobalOptions } from "./helpers.js";
7
+ /**
8
+ * Escape a string for safe use inside double-quoted shell context.
9
+ * Within double quotes, `\`, `"`, `$`, `` ` ``, and `!` are interpreted by the shell.
10
+ */
11
+ function escapeDoubleQuoted(str) {
12
+ return str
13
+ .replace(/\\/g, "\\\\")
14
+ .replace(/"/g, '\\"')
15
+ .replace(/\$/g, "\\$")
16
+ .replace(/`/g, "\\`")
17
+ .replace(/!/g, "\\!");
18
+ }
19
+ /**
20
+ * Format environment variable exports for shell evaluation.
21
+ * Each line is a shell export statement. Values are escaped for
22
+ * safe use in double-quoted context.
23
+ */
24
+ export function formatEnvVars(vars) {
25
+ return Object.entries(vars)
26
+ .map(([key, value]) => `export ${key}="${escapeDoubleQuoted(value)}"`)
27
+ .join("\n");
28
+ }
29
+ export const onCommand = new Command("on")
30
+ .description("Start intercepting HTTP traffic in this shell")
31
+ .option("-l, --label <label>", "Label for this session")
32
+ .option("--no-restart", "Do not auto-restart daemon on version mismatch")
33
+ .action(async (options, command) => {
34
+ // If stdout is a TTY, user ran directly - show instructions instead
35
+ if (process.stdout.isTTY) {
36
+ console.log("To intercept HTTP traffic, run:");
37
+ console.log("");
38
+ console.log(" eval $(htpx on)");
39
+ console.log("");
40
+ console.log("This sets the required environment variables in your shell.");
41
+ return;
42
+ }
43
+ const label = options.label;
44
+ const autoRestart = options.restart;
45
+ const globalOpts = getGlobalOptions(command);
46
+ const verbosity = globalOpts.verbose;
47
+ const logLevel = parseVerbosity(verbosity);
48
+ // Find project root (auto-creates .htpx if needed)
49
+ const projectRoot = findOrCreateProjectRoot(undefined, globalOpts.dir);
50
+ ensureHtpxDir(projectRoot);
51
+ const paths = getHtpxPaths(projectRoot);
52
+ try {
53
+ // Start daemon if not already running
54
+ const proxyPort = await startDaemon(projectRoot, {
55
+ logLevel,
56
+ autoRestart,
57
+ onVersionMismatch: (running, cli) => {
58
+ if (autoRestart) {
59
+ console.log(`# htpx: restarting daemon (version mismatch: ${running} -> ${cli})`);
60
+ }
61
+ else {
62
+ console.log(`# htpx warning: daemon version mismatch (running: ${running}, CLI: ${cli})`);
63
+ console.log(`# Use 'htpx daemon restart' to update.`);
64
+ }
65
+ },
66
+ });
67
+ const proxyUrl = `http://127.0.0.1:${proxyPort}`;
68
+ // Register session with daemon
69
+ const client = new ControlClient(paths.controlSocketFile);
70
+ try {
71
+ const session = await client.registerSession(label, process.ppid);
72
+ // Build environment variables
73
+ const envVars = {
74
+ HTTP_PROXY: proxyUrl,
75
+ HTTPS_PROXY: proxyUrl,
76
+ // Python requests library
77
+ SSL_CERT_FILE: paths.caCertFile,
78
+ REQUESTS_CA_BUNDLE: paths.caCertFile,
79
+ // Node.js
80
+ NODE_EXTRA_CA_CERTS: paths.caCertFile,
81
+ // htpx session tracking
82
+ HTPX_SESSION_ID: session.id,
83
+ };
84
+ if (label) {
85
+ envVars["HTPX_LABEL"] = label;
86
+ }
87
+ // Report interceptor status
88
+ try {
89
+ const interceptors = await client.listInterceptors();
90
+ if (interceptors.length > 0) {
91
+ const errorCount = interceptors.filter((i) => i.error).length;
92
+ const loadedCount = interceptors.length - errorCount;
93
+ if (errorCount > 0) {
94
+ console.log(`# Loaded ${loadedCount} interceptors (${errorCount} failed) from .htpx/interceptors/`);
95
+ }
96
+ else {
97
+ console.log(`# Loaded ${loadedCount} interceptors from .htpx/interceptors/`);
98
+ }
99
+ }
100
+ }
101
+ catch {
102
+ // Interceptor info not available — not critical
103
+ }
104
+ // Output env vars for eval
105
+ console.log(formatEnvVars(envVars));
106
+ // Output confirmation as a comment (shown but not executed)
107
+ const labelInfo = label ? ` (label: ${label})` : "";
108
+ console.log(`# htpx: intercepting traffic${labelInfo}`);
109
+ console.log(`# Proxy: ${proxyUrl}`);
110
+ console.log(`# Session: ${session.id}`);
111
+ }
112
+ finally {
113
+ client.close();
114
+ }
115
+ }
116
+ catch (err) {
117
+ console.error(`# htpx error: ${getErrorMessage(err)}`);
118
+ process.exit(1);
119
+ }
120
+ });
121
+ //# sourceMappingURL=on.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"on.js","sourceRoot":"","sources":["../../../src/cli/commands/on.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,uBAAuB,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAC/F,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AAC/D,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAEjE;;;GAGG;AACH,SAAS,kBAAkB,CAA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AC,CAAC;QAC1C,CAAC;gBAAS,CAAC;YACT,MAAM,CAAC,KAAK,EAAE,CAAC;QACjB,CAAC;IACH,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,OAAO,CAAC,KAAK,CAAC,iBAAiB,eAAe,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QACvD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC,CAAC,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"project.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/project.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAGpC,eAAO,MAAM,cAAc,SAA0E,CAAC"}
1
+ {"version":3,"file":"project.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/project.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAIpC,eAAO,MAAM,cAAc,SAE1B,CAAC"}
@@ -1,11 +1,13 @@
1
1
  import { Command } from "commander";
2
- import { ensureHtpxDir, getHtpxDir } from "../../shared/project.js";
2
+ import { ensureHtpxDir, findOrCreateProjectRoot, getHtpxDir } from "../../shared/project.js";
3
+ import { getGlobalOptions } from "./helpers.js";
3
4
  export const projectCommand = new Command("project").description("Manage htpx project configuration");
4
5
  projectCommand
5
6
  .command("init")
6
7
  .description("Initialise htpx in the current directory")
7
- .action(() => {
8
- const projectRoot = process.cwd();
8
+ .action((_, command) => {
9
+ const globalOpts = getGlobalOptions(command);
10
+ const projectRoot = findOrCreateProjectRoot(undefined, globalOpts.dir ?? process.cwd());
9
11
  const htpxDir = getHtpxDir(projectRoot);
10
12
  ensureHtpxDir(projectRoot);
11
13
  console.log(`Created ${htpxDir}`);
@@ -1 +1 @@
1
- {"version":3,"file":"project.js","sourceRoot":"","sources":["../../../src/cli/commands/project.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,W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CAAC,WAAW,CAAC,CAAC;IAC3B,OAAO,CAAC,GAAG,CAAC,WAAW,OAAO,EAAE,CAAC,CAAC;AACpC,CAAC,CAAC,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"restart.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/restart.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAWpC,eAAO,MAAM,cAAc,SAqCvB,CAAC"}
1
+ {"version":3,"file":"restart.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/restart.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAWpC,eAAO,MAAM,cAAc,SA+BvB,CAAC"}
@@ -1,19 +1,15 @@
1
1
  import { Command } from "commander";
2
- import { findProjectRoot } from "../../shared/project.js";
3
2
  import { isDaemonRunning, restartDaemon, startDaemon, getDaemonVersion, } from "../../shared/daemon.js";
4
3
  import { parseVerbosity } from "../../shared/logger.js";
5
4
  import { getHtpxVersion } from "../../shared/version.js";
5
+ import { requireProjectRoot, getErrorMessage, getGlobalOptions } from "./helpers.js";
6
6
  export const restartCommand = new Command("restart")
7
7
  .description("Restart the daemon")
8
8
  .action(async (_, command) => {
9
- const globalOpts = command.optsWithGlobals();
10
- const verbosity = globalOpts.verbose ?? 0;
9
+ const globalOpts = getGlobalOptions(command);
10
+ const verbosity = globalOpts.verbose;
11
11
  const logLevel = parseVerbosity(verbosity);
12
- const projectRoot = findProjectRoot();
13
- if (!projectRoot) {
14
- console.error("Not in a project directory (no .htpx or .git found)");
15
- process.exit(1);
16
- }
12
+ const projectRoot = requireProjectRoot(globalOpts.dir);
17
13
  try {
18
14
  const cliVersion = getHtpxVersion();
19
15
  if (await isDaemonRunning(projectRoot)) {
@@ -32,8 +28,7 @@ export const restartCommand = new Command("restart")
32
28
  }
33
29
  }
34
30
  catch (err) {
35
- const message = err instanceof Error ? err.message : "Unknown error";
36
- console.error(`Failed to restart daemon: ${message}`);
31
+ console.error(`Failed to restart daemon: ${getErrorMessage(err)}`);
37
32
  process.exit(1);
38
33
  }
39
34
  });
@@ -1 +1 @@
1
- {"version":3,"file":"restart.js","sourceRoot":"","sources":["../../../src/cli/commands/restart.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EACL,eAAe,EACf,aAAa,EACb,WAAW,EACX,gBAAgB,GACjB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAEzD,MAAM,CAAC,MAAM,cAAc,GAAG,IAAI,OAAO,CAAC,SAAS,CAAC;KACjD,WAAW,CAAC,oBAAoB,CAAC;KACjC,MAAM,CAAC,KAAK,EAAE,CAAC,EAAE,OAAgB,EAAE,EAAE;IACpC,MAAM,UAAU,GAAG,OAAO,CAAC,eAAe,EAA0B,CAAC;IACrE,MAAM,SAAS,GAAG,UAAU,CAAC,OAAO,IAAI,CAAC,CAAC;IAC1C,MAAM,QAAQ,GAAG,cAAc,CAAC,SAAS,CAAC,CAAC;IAE3C,MAAM,WAAW,GAAG,eAAe,EAAE,CAAC;IAEtC,IAAI,CAAC,WAAW,EAAE,CAAC;QACjB,OAAO,CAAC,KAAK,CAAC,qDAAqD,CAAC,CAAC;QACrE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;IAED,IAAI,CAAC;QACH,MAAM,UAAU,GAAG,cAAc,EAAE,CAAC;QAEpC,IAAI,MAAM,eAAe,CAAC,WAAW,CAAC,EAAE,CAAC;YACvC,MAAM,aAAa,GAAG,MAAM,gBAAgB,CAAC,WAAW,CAAC,CAAC;YAC1D,MAAM,WAAW,GACf,aAAa,IAAI,aAAa,KAAK,UAAU;gBAC3C,CAAC,CAAC,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AAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC,CAAC,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"status.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/status.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAKpC,eAAO,MAAM,aAAa,SAiCtB,CAAC"}
1
+ {"version":3,"file":"status.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/status.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAOpC,eAAO,MAAM,aAAa,SA4DtB,CAAC"}
@@ -1,36 +1,66 @@
1
1
  import { Command } from "commander";
2
- import { findProjectRoot, getHtpxPaths } from "../../shared/project.js";
2
+ import { getHtpxPaths } from "../../shared/project.js";
3
3
  import { isDaemonRunning } from "../../shared/daemon.js";
4
- import { ControlClient } from "../../daemon/control.js";
4
+ import { ControlClient } from "../../shared/control-client.js";
5
+ import { buildProxyInfo } from "../../shared/proxy-info.js";
6
+ import { requireProjectRoot, getErrorMessage, getGlobalOptions } from "./helpers.js";
5
7
  export const statusCommand = new Command("status")
6
- .description("Show daemon status")
7
- .action(async () => {
8
- // Find project root
9
- const projectRoot = findProjectRoot();
10
- if (!projectRoot) {
11
- console.log("Not in a project directory (no .htpx or .git found)");
12
- process.exit(1);
13
- }
8
+ .description("Show htpx status")
9
+ .action(async (_, command) => {
10
+ const globalOpts = getGlobalOptions(command);
11
+ const projectRoot = requireProjectRoot(globalOpts.dir);
14
12
  const paths = getHtpxPaths(projectRoot);
13
+ // Detect whether the current shell is intercepting
14
+ const sessionId = process.env["HTPX_SESSION_ID"];
15
+ const intercepting = sessionId !== undefined && sessionId !== "";
15
16
  // Check if daemon is running
16
17
  const running = await isDaemonRunning(projectRoot);
17
18
  if (!running) {
18
- console.log("Daemon is not running");
19
- process.exit(0);
19
+ console.log("Daemon: not running");
20
+ console.log(`Intercepting: no`);
21
+ return;
20
22
  }
23
+ const client = new ControlClient(paths.controlSocketFile);
21
24
  try {
22
- // Query daemon for status
23
- const client = new ControlClient(paths.controlSocketFile);
24
25
  const status = await client.status();
25
- console.log("Daemon is running");
26
- console.log(` Proxy port: ${status.proxyPort}`);
27
- console.log(` Sessions: ${status.sessionCount}`);
28
- console.log(` Requests captured: ${status.requestCount}`);
26
+ console.log("Daemon: running");
27
+ console.log(`Intercepting: ${intercepting ? `yes (session ${sessionId})` : "no"}`);
28
+ console.log(`Proxy port: ${status.proxyPort}`);
29
+ console.log(`Sessions: ${status.sessionCount}`);
30
+ console.log(`Requests: ${status.requestCount}`);
31
+ // Show interceptor info
32
+ try {
33
+ const interceptors = await client.listInterceptors();
34
+ if (interceptors.length > 0) {
35
+ const errorCount = interceptors.filter((i) => i.error).length;
36
+ const loadedCount = interceptors.length - errorCount;
37
+ if (errorCount > 0) {
38
+ console.log(`Interceptors: ${loadedCount} loaded (${errorCount} failed)`);
39
+ }
40
+ else {
41
+ console.log(`Interceptors: ${loadedCount} loaded`);
42
+ }
43
+ }
44
+ else {
45
+ console.log("Interceptors: none");
46
+ }
47
+ }
48
+ catch {
49
+ // Interceptor info not available — not critical
50
+ }
51
+ if (status.proxyPort) {
52
+ const info = buildProxyInfo(status.proxyPort, paths.caCertFile);
53
+ console.log("");
54
+ console.log(`Proxy URL: ${info.proxyUrl}`);
55
+ console.log(`CA cert: ${info.caCertPath}`);
56
+ }
29
57
  }
30
58
  catch (err) {
31
- const message = err instanceof Error ? err.message : "Unknown error";
32
- console.error(`Error querying daemon: ${message}`);
59
+ console.error(`Error querying daemon: ${getErrorMessage(err)}`);
33
60
  process.exit(1);
34
61
  }
62
+ finally {
63
+ client.close();
64
+ }
35
65
  });
36
66
  //# sourceMappingURL=status.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"status.js","sourceRoot":"","sources":["../../../src/cli/commands/status.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EA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AAC,kBAAkB,WAAW,SAAS,CAAC,CAAC;gBACtD,CAAC;YACH,CAAC;iBAAM,CAAC;gBACN,OAAO,CAAC,GAAG,CAAC,qBAAqB,CAAC,CAAC;YACrC,CAAC;QACH,CAAC;QAAC,MAAM,CAAC;YACP,gDAAgD;QAClD,CAAC;QAED,IAAI,MAAM,CAAC,SAAS,EAAE,CAAC;YACrB,MAAM,IAAI,GAAG,cAAc,CAAC,MAAM,CAAC,SAAS,EAAE,KAAK,CAAC,UAAU,CAAC,CAAC;YAChE,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;YAChB,OAAO,CAAC,GAAG,CAAC,kBAAkB,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC;YAC/C,OAAO,CAAC,GAAG,CAAC,kBAAkB,IAAI,CAAC,UAAU,EAAE,CAAC,CAAC;QACnD,CAAC;IACH,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,OAAO,CAAC,KAAK,CAAC,0BAA0B,eAAe,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QAChE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;YAAS,CAAC;QACT,MAAM,CAAC,KAAK,EAAE,CAAC;IACjB,CAAC;AACH,CAAC,CAAC,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"stop.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/stop.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAIpC,eAAO,MAAM,WAAW,SAuBtB,CAAC"}
1
+ {"version":3,"file":"stop.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/stop.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAIpC,eAAO,MAAM,WAAW,SAoBpB,CAAC"}
@@ -1,13 +1,11 @@
1
1
  import { Command } from "commander";
2
- import { findProjectRoot } from "../../shared/project.js";
3
2
  import { isDaemonRunning, stopDaemon } from "../../shared/daemon.js";
4
- export const stopCommand = new Command("stop").description("Stop the daemon").action(async () => {
5
- // Find project root
6
- const projectRoot = findProjectRoot();
7
- if (!projectRoot) {
8
- console.log("Not in a project directory (no .htpx or .git found)");
9
- process.exit(1);
10
- }
3
+ import { requireProjectRoot, getErrorMessage, getGlobalOptions } from "./helpers.js";
4
+ export const stopCommand = new Command("stop")
5
+ .description("Stop the daemon")
6
+ .action(async (_, command) => {
7
+ const globalOpts = getGlobalOptions(command);
8
+ const projectRoot = requireProjectRoot(globalOpts.dir);
11
9
  // Check if daemon is running
12
10
  const running = await isDaemonRunning(projectRoot);
13
11
  if (!running) {
@@ -19,8 +17,7 @@ export const stopCommand = new Command("stop").description("Stop the daemon").ac
19
17
  console.log("Daemon stopped");
20
18
  }
21
19
  catch (err) {
22
- const message = err instanceof Error ? err.message : "Unknown error";
23
- console.error(`Error stopping daemon: ${message}`);
20
+ console.error(`Error stopping daemon: ${getErrorMessage(err)}`);
24
21
  process.exit(1);
25
22
  }
26
23
  });