@vibelet/cli 0.1.38 → 1.0.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 (323) hide show
  1. package/README.md +80 -0
  2. package/bin/cloudflared-quick-tunnel.mjs +11 -0
  3. package/bin/cloudflared-resolver.mjs +171 -0
  4. package/bin/vibelet-runtime-policy.mjs +36 -0
  5. package/bin/vibelet.cjs +12 -0
  6. package/bin/vibelet.mjs +1062 -0
  7. package/dist/index.cjs +126 -0
  8. package/package.json +24 -22
  9. package/app.json +0 -5
  10. package/dist/advertised-hosts.d.ts +0 -34
  11. package/dist/advertised-hosts.d.ts.map +0 -1
  12. package/dist/advertised-hosts.js +0 -176
  13. package/dist/advertised-hosts.js.map +0 -1
  14. package/dist/advertised-hosts.test.d.ts +0 -2
  15. package/dist/advertised-hosts.test.d.ts.map +0 -1
  16. package/dist/advertised-hosts.test.js +0 -96
  17. package/dist/advertised-hosts.test.js.map +0 -1
  18. package/dist/audit.d.ts +0 -30
  19. package/dist/audit.d.ts.map +0 -1
  20. package/dist/audit.js +0 -73
  21. package/dist/audit.js.map +0 -1
  22. package/dist/audit.test.d.ts +0 -2
  23. package/dist/audit.test.d.ts.map +0 -1
  24. package/dist/audit.test.js +0 -33
  25. package/dist/audit.test.js.map +0 -1
  26. package/dist/auth.d.ts +0 -6
  27. package/dist/auth.d.ts.map +0 -1
  28. package/dist/auth.js +0 -27
  29. package/dist/auth.js.map +0 -1
  30. package/dist/claude-hooks.d.ts +0 -58
  31. package/dist/claude-hooks.d.ts.map +0 -1
  32. package/dist/claude-hooks.js +0 -129
  33. package/dist/claude-hooks.js.map +0 -1
  34. package/dist/cli-version.d.ts +0 -3
  35. package/dist/cli-version.d.ts.map +0 -1
  36. package/dist/cli-version.js +0 -35
  37. package/dist/cli-version.js.map +0 -1
  38. package/dist/cli-version.test.d.ts +0 -2
  39. package/dist/cli-version.test.d.ts.map +0 -1
  40. package/dist/cli-version.test.js +0 -38
  41. package/dist/cli-version.test.js.map +0 -1
  42. package/dist/config.d.ts +0 -30
  43. package/dist/config.d.ts.map +0 -1
  44. package/dist/config.js +0 -327
  45. package/dist/config.js.map +0 -1
  46. package/dist/config.test.d.ts +0 -2
  47. package/dist/config.test.d.ts.map +0 -1
  48. package/dist/config.test.js +0 -184
  49. package/dist/config.test.js.map +0 -1
  50. package/dist/dev-auth.test.d.ts +0 -2
  51. package/dist/dev-auth.test.d.ts.map +0 -1
  52. package/dist/dev-auth.test.js +0 -154
  53. package/dist/dev-auth.test.js.map +0 -1
  54. package/dist/dev-script.test.d.ts +0 -2
  55. package/dist/dev-script.test.d.ts.map +0 -1
  56. package/dist/dev-script.test.js +0 -412
  57. package/dist/dev-script.test.js.map +0 -1
  58. package/dist/drivers/claude.d.ts +0 -34
  59. package/dist/drivers/claude.d.ts.map +0 -1
  60. package/dist/drivers/claude.js +0 -413
  61. package/dist/drivers/claude.js.map +0 -1
  62. package/dist/drivers/claude.test.d.ts +0 -2
  63. package/dist/drivers/claude.test.d.ts.map +0 -1
  64. package/dist/drivers/claude.test.js +0 -951
  65. package/dist/drivers/claude.test.js.map +0 -1
  66. package/dist/drivers/codex.d.ts +0 -38
  67. package/dist/drivers/codex.d.ts.map +0 -1
  68. package/dist/drivers/codex.js +0 -771
  69. package/dist/drivers/codex.js.map +0 -1
  70. package/dist/drivers/codex.test.d.ts +0 -2
  71. package/dist/drivers/codex.test.d.ts.map +0 -1
  72. package/dist/drivers/codex.test.js +0 -939
  73. package/dist/drivers/codex.test.js.map +0 -1
  74. package/dist/drivers/types.d.ts +0 -14
  75. package/dist/drivers/types.d.ts.map +0 -1
  76. package/dist/drivers/types.js +0 -2
  77. package/dist/drivers/types.js.map +0 -1
  78. package/dist/e2e.test.d.ts +0 -2
  79. package/dist/e2e.test.d.ts.map +0 -1
  80. package/dist/e2e.test.js +0 -111
  81. package/dist/e2e.test.js.map +0 -1
  82. package/dist/identity.d.ts +0 -10
  83. package/dist/identity.d.ts.map +0 -1
  84. package/dist/identity.js +0 -66
  85. package/dist/identity.js.map +0 -1
  86. package/dist/identity.test.d.ts +0 -2
  87. package/dist/identity.test.d.ts.map +0 -1
  88. package/dist/identity.test.js +0 -25
  89. package/dist/identity.test.js.map +0 -1
  90. package/dist/index-entry.test.d.ts +0 -2
  91. package/dist/index-entry.test.d.ts.map +0 -1
  92. package/dist/index-entry.test.js +0 -272
  93. package/dist/index-entry.test.js.map +0 -1
  94. package/dist/index.d.ts +0 -2
  95. package/dist/index.d.ts.map +0 -1
  96. package/dist/index.js +0 -707
  97. package/dist/index.js.map +0 -1
  98. package/dist/logger.d.ts +0 -31
  99. package/dist/logger.d.ts.map +0 -1
  100. package/dist/logger.js +0 -75
  101. package/dist/logger.js.map +0 -1
  102. package/dist/metrics.d.ts +0 -52
  103. package/dist/metrics.d.ts.map +0 -1
  104. package/dist/metrics.js +0 -89
  105. package/dist/metrics.js.map +0 -1
  106. package/dist/pairing-store.d.ts +0 -29
  107. package/dist/pairing-store.d.ts.map +0 -1
  108. package/dist/pairing-store.js +0 -131
  109. package/dist/pairing-store.js.map +0 -1
  110. package/dist/pairing-store.test.d.ts +0 -2
  111. package/dist/pairing-store.test.d.ts.map +0 -1
  112. package/dist/pairing-store.test.js +0 -47
  113. package/dist/pairing-store.test.js.map +0 -1
  114. package/dist/paths.d.ts +0 -16
  115. package/dist/paths.d.ts.map +0 -1
  116. package/dist/paths.js +0 -18
  117. package/dist/paths.js.map +0 -1
  118. package/dist/perf-compare.d.ts +0 -13
  119. package/dist/perf-compare.d.ts.map +0 -1
  120. package/dist/perf-compare.js +0 -125
  121. package/dist/perf-compare.js.map +0 -1
  122. package/dist/port-conflict.d.ts +0 -9
  123. package/dist/port-conflict.d.ts.map +0 -1
  124. package/dist/port-conflict.js +0 -33
  125. package/dist/port-conflict.js.map +0 -1
  126. package/dist/port-conflict.test.d.ts +0 -2
  127. package/dist/port-conflict.test.d.ts.map +0 -1
  128. package/dist/port-conflict.test.js +0 -38
  129. package/dist/port-conflict.test.js.map +0 -1
  130. package/dist/process-scanner.d.ts +0 -43
  131. package/dist/process-scanner.d.ts.map +0 -1
  132. package/dist/process-scanner.js +0 -453
  133. package/dist/process-scanner.js.map +0 -1
  134. package/dist/process-scanner.perf.test.d.ts +0 -2
  135. package/dist/process-scanner.perf.test.d.ts.map +0 -1
  136. package/dist/process-scanner.perf.test.js +0 -186
  137. package/dist/process-scanner.perf.test.js.map +0 -1
  138. package/dist/process-scanner.test.d.ts +0 -2
  139. package/dist/process-scanner.test.d.ts.map +0 -1
  140. package/dist/process-scanner.test.js +0 -399
  141. package/dist/process-scanner.test.js.map +0 -1
  142. package/dist/push-protocol.d.ts +0 -15
  143. package/dist/push-protocol.d.ts.map +0 -1
  144. package/dist/push-protocol.js +0 -23
  145. package/dist/push-protocol.js.map +0 -1
  146. package/dist/push-protocol.test.d.ts +0 -2
  147. package/dist/push-protocol.test.d.ts.map +0 -1
  148. package/dist/push-protocol.test.js +0 -57
  149. package/dist/push-protocol.test.js.map +0 -1
  150. package/dist/push-store.d.ts +0 -22
  151. package/dist/push-store.d.ts.map +0 -1
  152. package/dist/push-store.js +0 -103
  153. package/dist/push-store.js.map +0 -1
  154. package/dist/push-store.test.d.ts +0 -2
  155. package/dist/push-store.test.d.ts.map +0 -1
  156. package/dist/push-store.test.js +0 -79
  157. package/dist/push-store.test.js.map +0 -1
  158. package/dist/push.d.ts +0 -65
  159. package/dist/push.d.ts.map +0 -1
  160. package/dist/push.js +0 -202
  161. package/dist/push.js.map +0 -1
  162. package/dist/push.test.d.ts +0 -2
  163. package/dist/push.test.d.ts.map +0 -1
  164. package/dist/push.test.js +0 -199
  165. package/dist/push.test.js.map +0 -1
  166. package/dist/safe-stdio.d.ts +0 -3
  167. package/dist/safe-stdio.d.ts.map +0 -1
  168. package/dist/safe-stdio.js +0 -46
  169. package/dist/safe-stdio.js.map +0 -1
  170. package/dist/scanner.d.ts +0 -30
  171. package/dist/scanner.d.ts.map +0 -1
  172. package/dist/scanner.js +0 -859
  173. package/dist/scanner.js.map +0 -1
  174. package/dist/scanner.perf.test.d.ts +0 -2
  175. package/dist/scanner.perf.test.d.ts.map +0 -1
  176. package/dist/scanner.perf.test.js +0 -320
  177. package/dist/scanner.perf.test.js.map +0 -1
  178. package/dist/scanner.test.d.ts +0 -2
  179. package/dist/scanner.test.d.ts.map +0 -1
  180. package/dist/scanner.test.js +0 -948
  181. package/dist/scanner.test.js.map +0 -1
  182. package/dist/session-inventory.d.ts +0 -63
  183. package/dist/session-inventory.d.ts.map +0 -1
  184. package/dist/session-inventory.js +0 -525
  185. package/dist/session-inventory.js.map +0 -1
  186. package/dist/session-inventory.perf.test.d.ts +0 -2
  187. package/dist/session-inventory.perf.test.d.ts.map +0 -1
  188. package/dist/session-inventory.perf.test.js +0 -220
  189. package/dist/session-inventory.perf.test.js.map +0 -1
  190. package/dist/session-inventory.test.d.ts +0 -2
  191. package/dist/session-inventory.test.d.ts.map +0 -1
  192. package/dist/session-inventory.test.js +0 -712
  193. package/dist/session-inventory.test.js.map +0 -1
  194. package/dist/session-manager.d.ts +0 -75
  195. package/dist/session-manager.d.ts.map +0 -1
  196. package/dist/session-manager.js +0 -1515
  197. package/dist/session-manager.js.map +0 -1
  198. package/dist/session-manager.test.d.ts +0 -2
  199. package/dist/session-manager.test.d.ts.map +0 -1
  200. package/dist/session-manager.test.js +0 -2861
  201. package/dist/session-manager.test.js.map +0 -1
  202. package/dist/session-store.d.ts +0 -42
  203. package/dist/session-store.d.ts.map +0 -1
  204. package/dist/session-store.js +0 -163
  205. package/dist/session-store.js.map +0 -1
  206. package/dist/session-store.test.d.ts +0 -2
  207. package/dist/session-store.test.d.ts.map +0 -1
  208. package/dist/session-store.test.js +0 -236
  209. package/dist/session-store.test.js.map +0 -1
  210. package/dist/session-title.d.ts +0 -6
  211. package/dist/session-title.d.ts.map +0 -1
  212. package/dist/session-title.js +0 -105
  213. package/dist/session-title.js.map +0 -1
  214. package/dist/session-title.perf.test.d.ts +0 -2
  215. package/dist/session-title.perf.test.d.ts.map +0 -1
  216. package/dist/session-title.perf.test.js +0 -99
  217. package/dist/session-title.perf.test.js.map +0 -1
  218. package/dist/session-title.test.d.ts +0 -2
  219. package/dist/session-title.test.d.ts.map +0 -1
  220. package/dist/session-title.test.js +0 -199
  221. package/dist/session-title.test.js.map +0 -1
  222. package/dist/shutdown-endpoint.test.d.ts +0 -2
  223. package/dist/shutdown-endpoint.test.d.ts.map +0 -1
  224. package/dist/shutdown-endpoint.test.js +0 -93
  225. package/dist/shutdown-endpoint.test.js.map +0 -1
  226. package/dist/storage-housekeeping.d.ts +0 -28
  227. package/dist/storage-housekeeping.d.ts.map +0 -1
  228. package/dist/storage-housekeeping.js +0 -76
  229. package/dist/storage-housekeeping.js.map +0 -1
  230. package/dist/storage-housekeeping.test.d.ts +0 -2
  231. package/dist/storage-housekeeping.test.d.ts.map +0 -1
  232. package/dist/storage-housekeeping.test.js +0 -65
  233. package/dist/storage-housekeeping.test.js.map +0 -1
  234. package/dist/test-daemon-harness.d.ts +0 -31
  235. package/dist/test-daemon-harness.d.ts.map +0 -1
  236. package/dist/test-daemon-harness.js +0 -337
  237. package/dist/test-daemon-harness.js.map +0 -1
  238. package/dist/token-auth.test.d.ts +0 -2
  239. package/dist/token-auth.test.d.ts.map +0 -1
  240. package/dist/token-auth.test.js +0 -52
  241. package/dist/token-auth.test.js.map +0 -1
  242. package/dist/utils.d.ts +0 -4
  243. package/dist/utils.d.ts.map +0 -1
  244. package/dist/utils.js +0 -40
  245. package/dist/utils.js.map +0 -1
  246. package/dist/utils.test.d.ts +0 -2
  247. package/dist/utils.test.d.ts.map +0 -1
  248. package/dist/utils.test.js +0 -54
  249. package/dist/utils.test.js.map +0 -1
  250. package/dist/ws-data.d.ts +0 -4
  251. package/dist/ws-data.d.ts.map +0 -1
  252. package/dist/ws-data.js +0 -20
  253. package/dist/ws-data.js.map +0 -1
  254. package/dist/ws-data.test.d.ts +0 -2
  255. package/dist/ws-data.test.d.ts.map +0 -1
  256. package/dist/ws-data.test.js +0 -17
  257. package/dist/ws-data.test.js.map +0 -1
  258. package/perf-reporter.mjs +0 -138
  259. package/scripts/build-release.mjs +0 -41
  260. package/scripts/dev.mjs +0 -537
  261. package/src/advertised-hosts.test.ts +0 -125
  262. package/src/advertised-hosts.ts +0 -225
  263. package/src/audit.test.ts +0 -38
  264. package/src/audit.ts +0 -117
  265. package/src/auth.ts +0 -31
  266. package/src/claude-hooks.ts +0 -195
  267. package/src/cli-version.test.ts +0 -36
  268. package/src/cli-version.ts +0 -46
  269. package/src/config.test.ts +0 -254
  270. package/src/config.ts +0 -324
  271. package/src/dev-auth.test.ts +0 -183
  272. package/src/dev-script.test.ts +0 -511
  273. package/src/drivers/claude.test.ts +0 -1186
  274. package/src/drivers/claude.ts +0 -443
  275. package/src/drivers/codex.test.ts +0 -1096
  276. package/src/drivers/codex.ts +0 -879
  277. package/src/drivers/types.ts +0 -15
  278. package/src/e2e.test.ts +0 -139
  279. package/src/identity.test.ts +0 -26
  280. package/src/identity.ts +0 -82
  281. package/src/index-entry.test.ts +0 -336
  282. package/src/index.ts +0 -781
  283. package/src/logger.ts +0 -112
  284. package/src/metrics.ts +0 -117
  285. package/src/pairing-store.test.ts +0 -53
  286. package/src/pairing-store.ts +0 -154
  287. package/src/paths.ts +0 -19
  288. package/src/perf-compare.ts +0 -164
  289. package/src/port-conflict.test.ts +0 -45
  290. package/src/port-conflict.ts +0 -44
  291. package/src/process-scanner.perf.test.ts +0 -222
  292. package/src/process-scanner.test.ts +0 -575
  293. package/src/process-scanner.ts +0 -514
  294. package/src/push-protocol.test.ts +0 -74
  295. package/src/push-protocol.ts +0 -36
  296. package/src/push-store.test.ts +0 -89
  297. package/src/push-store.ts +0 -126
  298. package/src/push.test.ts +0 -234
  299. package/src/push.ts +0 -318
  300. package/src/safe-stdio.ts +0 -51
  301. package/src/scanner.perf.test.ts +0 -359
  302. package/src/scanner.test.ts +0 -1045
  303. package/src/scanner.ts +0 -924
  304. package/src/session-inventory.perf.test.ts +0 -250
  305. package/src/session-inventory.test.ts +0 -1002
  306. package/src/session-inventory.ts +0 -721
  307. package/src/session-manager.test.ts +0 -3430
  308. package/src/session-manager.ts +0 -1775
  309. package/src/session-store.test.ts +0 -276
  310. package/src/session-store.ts +0 -202
  311. package/src/session-title.perf.test.ts +0 -118
  312. package/src/session-title.test.ts +0 -286
  313. package/src/session-title.ts +0 -108
  314. package/src/shutdown-endpoint.test.ts +0 -95
  315. package/src/storage-housekeeping.test.ts +0 -78
  316. package/src/storage-housekeeping.ts +0 -111
  317. package/src/test-daemon-harness.ts +0 -410
  318. package/src/token-auth.test.ts +0 -67
  319. package/src/utils.test.ts +0 -65
  320. package/src/utils.ts +0 -47
  321. package/src/ws-data.test.ts +0 -20
  322. package/src/ws-data.ts +0 -26
  323. package/tsconfig.json +0 -12
@@ -1,195 +0,0 @@
1
- import { mkdirSync, rmSync, writeFileSync } from 'fs';
2
- import { tmpdir } from 'os';
3
- import { join } from 'path';
4
- import { randomUUID } from 'crypto';
5
-
6
- export const CLAUDE_HOOK_APPROVAL_PREFIX = 'claude-hook:';
7
- export const CLAUDE_HOOK_SECRET_HEADER = 'x-vibelet-claude-hook-secret';
8
-
9
- export type ClaudeSessionHookData = {
10
- session_id?: string;
11
- sessionId?: string;
12
- transcript_path?: string;
13
- transcriptPath?: string;
14
- cwd?: string;
15
- hook_event_name?: string;
16
- hookEventName?: string;
17
- source?: string;
18
- [key: string]: unknown;
19
- };
20
-
21
- export type ClaudePermissionHookData = {
22
- session_id?: string;
23
- sessionId?: string;
24
- transcript_path?: string;
25
- transcriptPath?: string;
26
- cwd?: string;
27
- hook_event_name?: string;
28
- hookEventName?: string;
29
- permission_mode?: string;
30
- permissionMode?: string;
31
- tool_name?: string;
32
- toolName?: string;
33
- tool_input?: unknown;
34
- toolInput?: unknown;
35
- tool_use_id?: string;
36
- toolUseId?: string;
37
- permission_suggestions?: unknown;
38
- permissionSuggestions?: unknown;
39
- [key: string]: unknown;
40
- };
41
-
42
- export type ClaudePermissionHookResponse = {
43
- continue: boolean;
44
- suppressOutput?: boolean;
45
- stopReason?: string;
46
- systemMessage?: string;
47
- hookSpecificOutput?: {
48
- hookEventName?: 'PreToolUse';
49
- permissionDecision?: 'allow' | 'deny' | 'ask';
50
- permissionDecisionReason?: string;
51
- updatedInput?: unknown;
52
- [key: string]: unknown;
53
- };
54
- [key: string]: unknown;
55
- };
56
-
57
- export type ClaudeHookFiles = {
58
- secret: string;
59
- dirPath: string;
60
- settingsPath: string;
61
- sessionScriptPath: string;
62
- permissionScriptPath: string;
63
- };
64
-
65
- export const DEFAULT_CLAUDE_PERMISSION_HOOK_RESPONSE: ClaudePermissionHookResponse = {
66
- continue: true,
67
- suppressOutput: true,
68
- hookSpecificOutput: {
69
- hookEventName: 'PreToolUse',
70
- },
71
- };
72
-
73
- function buildSessionForwarderScript(port: number, secret: string): string {
74
- return `#!/usr/bin/env node
75
- const http = require('http');
76
- const chunks = [];
77
- process.stdin.on('data', (chunk) => chunks.push(chunk));
78
- process.stdin.on('end', () => {
79
- const body = Buffer.concat(chunks);
80
- const req = http.request({
81
- host: '127.0.0.1',
82
- port: ${port},
83
- method: 'POST',
84
- path: '/hook/claude/session-start',
85
- headers: {
86
- 'Content-Type': 'application/json',
87
- 'Content-Length': body.length,
88
- '${CLAUDE_HOOK_SECRET_HEADER}': ${JSON.stringify(secret)}
89
- }
90
- }, (res) => { res.resume(); });
91
- req.on('error', () => {});
92
- req.end(body);
93
- });
94
- process.stdin.resume();
95
- `;
96
- }
97
-
98
- function buildPermissionForwarderScript(port: number, secret: string): string {
99
- return `#!/usr/bin/env node
100
- const http = require('http');
101
- const fallback = ${JSON.stringify(JSON.stringify(DEFAULT_CLAUDE_PERMISSION_HOOK_RESPONSE))};
102
- const chunks = [];
103
- process.stdin.on('data', (chunk) => chunks.push(chunk));
104
- process.stdin.on('end', () => {
105
- const body = Buffer.concat(chunks);
106
- const req = http.request({
107
- host: '127.0.0.1',
108
- port: ${port},
109
- method: 'POST',
110
- path: '/hook/claude/permission-request',
111
- headers: {
112
- 'Content-Type': 'application/json',
113
- 'Content-Length': body.length,
114
- '${CLAUDE_HOOK_SECRET_HEADER}': ${JSON.stringify(secret)}
115
- }
116
- }, (res) => {
117
- const responseChunks = [];
118
- res.on('data', (chunk) => responseChunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk)));
119
- res.on('end', () => {
120
- const statusCode = res.statusCode || 0;
121
- if (statusCode < 200 || statusCode >= 300) {
122
- process.stdout.write(fallback);
123
- return;
124
- }
125
- const payload = Buffer.concat(responseChunks).toString('utf8').trim();
126
- process.stdout.write(payload || fallback);
127
- });
128
- });
129
- req.on('error', () => {
130
- process.stdout.write(fallback);
131
- });
132
- req.end(body);
133
- });
134
- process.stdin.resume();
135
- `;
136
- }
137
-
138
- export function createClaudeHookFiles(port: number, secret: string): ClaudeHookFiles {
139
- const dirPath = join(tmpdir(), `vibelet-claude-hooks-${process.pid}-${randomUUID()}`);
140
- mkdirSync(dirPath, { recursive: true });
141
-
142
- const settingsPath = join(dirPath, 'settings.json');
143
- const sessionScriptPath = join(dirPath, 'session_hook_forwarder.cjs');
144
- const permissionScriptPath = join(dirPath, 'permission_hook_forwarder.cjs');
145
-
146
- writeFileSync(sessionScriptPath, buildSessionForwarderScript(port, secret), 'utf8');
147
- writeFileSync(permissionScriptPath, buildPermissionForwarderScript(port, secret), 'utf8');
148
- writeFileSync(
149
- settingsPath,
150
- JSON.stringify({
151
- hooks: {
152
- SessionStart: [
153
- {
154
- matcher: '*',
155
- hooks: [
156
- {
157
- type: 'command',
158
- command: `${JSON.stringify(process.execPath)} ${JSON.stringify(sessionScriptPath)}`,
159
- },
160
- ],
161
- },
162
- ],
163
- PreToolUse: [
164
- {
165
- matcher: '*',
166
- hooks: [
167
- {
168
- type: 'command',
169
- command: `${JSON.stringify(process.execPath)} ${JSON.stringify(permissionScriptPath)}`,
170
- },
171
- ],
172
- },
173
- ],
174
- },
175
- }, null, 2),
176
- 'utf8',
177
- );
178
-
179
- return {
180
- secret,
181
- dirPath,
182
- settingsPath,
183
- sessionScriptPath,
184
- permissionScriptPath,
185
- };
186
- }
187
-
188
- export function cleanupClaudeHookFiles(hookFiles: ClaudeHookFiles | null | undefined): void {
189
- if (!hookFiles) return;
190
- try {
191
- rmSync(hookFiles.dirPath, { recursive: true, force: true });
192
- } catch {
193
- // best effort cleanup
194
- }
195
- }
@@ -1,36 +0,0 @@
1
- import test from 'node:test';
2
- import assert from 'node:assert/strict';
3
- import { createRequire } from 'node:module';
4
- import { fileURLToPath } from 'node:url';
5
- import { resolveCliVersion } from './cli-version.js';
6
-
7
- const require = createRequire(import.meta.url);
8
- const packageJson = require('../../../package.json') as { version?: string };
9
- const daemonPackageDir = fileURLToPath(new URL('..', import.meta.url));
10
-
11
- test('resolveCliVersion prefers VIBELET_CLI_VERSION when provided', () => {
12
- const original = process.env.VIBELET_CLI_VERSION;
13
- process.env.VIBELET_CLI_VERSION = '9.9.9-test';
14
-
15
- try {
16
- assert.equal(resolveCliVersion(), '9.9.9-test');
17
- } finally {
18
- if (original === undefined) delete process.env.VIBELET_CLI_VERSION;
19
- else process.env.VIBELET_CLI_VERSION = original;
20
- }
21
- });
22
-
23
- test('resolveCliVersion falls back to the root package version', () => {
24
- const original = process.env.VIBELET_CLI_VERSION;
25
- const originalCwd = process.cwd();
26
- delete process.env.VIBELET_CLI_VERSION;
27
- process.chdir(daemonPackageDir);
28
-
29
- try {
30
- assert.equal(resolveCliVersion(), packageJson.version);
31
- } finally {
32
- process.chdir(originalCwd);
33
- if (original === undefined) delete process.env.VIBELET_CLI_VERSION;
34
- else process.env.VIBELET_CLI_VERSION = original;
35
- }
36
- });
@@ -1,46 +0,0 @@
1
- import { readFileSync } from 'node:fs';
2
- import { resolve } from 'node:path';
3
-
4
- type RootPackageJson = {
5
- name?: string;
6
- version?: string;
7
- };
8
-
9
- const ROOT_PACKAGE_NAME = '@vibelet/cli';
10
-
11
- function readVersionFromPackageJson(path: string): string | null {
12
- try {
13
- const packageJson = JSON.parse(readFileSync(path, 'utf8')) as RootPackageJson;
14
- if (packageJson.name === ROOT_PACKAGE_NAME && typeof packageJson.version === 'string' && packageJson.version.length > 0) {
15
- return packageJson.version;
16
- }
17
- } catch {
18
- // Continue through the fallback chain.
19
- }
20
-
21
- return null;
22
- }
23
-
24
- export function resolveCliVersion(): string {
25
- if (process.env.VIBELET_CLI_VERSION) {
26
- return process.env.VIBELET_CLI_VERSION;
27
- }
28
-
29
- let currentDir = process.cwd();
30
- for (let depth = 0; depth < 4; depth += 1) {
31
- const version = readVersionFromPackageJson(resolve(currentDir, 'package.json'));
32
- if (version) {
33
- return version;
34
- }
35
-
36
- const parentDir = resolve(currentDir, '..');
37
- if (parentDir === currentDir) {
38
- break;
39
- }
40
- currentDir = parentDir;
41
- }
42
-
43
- return '0.0.0';
44
- }
45
-
46
- export const CLI_VERSION = resolveCliVersion();
@@ -1,254 +0,0 @@
1
- import test from 'node:test';
2
- import assert from 'node:assert/strict';
3
- import { execFileSync } from 'node:child_process';
4
- import { join } from 'path';
5
- import { homedir } from 'os';
6
- import { isTransientPath, buildSanitizedEnv, execViaLoginShell, config } from './config.js';
7
-
8
- const configModuleUrl = new URL('./config.ts', import.meta.url).href;
9
-
10
- function buildChildEnv(overrides: Record<string, string | undefined>): NodeJS.ProcessEnv {
11
- const nextEnv: NodeJS.ProcessEnv = { ...process.env };
12
- for (const [key, value] of Object.entries(overrides)) {
13
- if (value === undefined) {
14
- delete nextEnv[key];
15
- } else {
16
- nextEnv[key] = value;
17
- }
18
- }
19
- return nextEnv;
20
- }
21
-
22
- function readConfigValueInIsolatedProcess(
23
- overrides: Record<string, string | undefined>,
24
- expression: string,
25
- ): string {
26
- return execFileSync(
27
- process.execPath,
28
- [
29
- '--import',
30
- 'tsx',
31
- '-e',
32
- `import { config } from ${JSON.stringify(configModuleUrl)}; process.stdout.write(String(${expression}));`,
33
- ],
34
- {
35
- env: buildChildEnv(overrides),
36
- encoding: 'utf8',
37
- },
38
- ).trim();
39
- }
40
-
41
- test('isTransientPath: detects fnm_multishells as transient', () => {
42
- assert.equal(isTransientPath('/tmp/fnm_multishells/12345/bin/codex'), true);
43
- });
44
-
45
- test('isTransientPath: returns false for normal paths', () => {
46
- assert.equal(isTransientPath('/usr/local/bin/codex'), false);
47
- });
48
-
49
- test('isTransientPath: returns false for home directory paths', () => {
50
- assert.equal(isTransientPath('/Users/test/.local/bin/claude'), false);
51
- });
52
-
53
- test('isTransientPath: returns false for empty string', () => {
54
- assert.equal(isTransientPath(''), false);
55
- });
56
-
57
- // buildSanitizedEnv tests
58
-
59
- test('buildSanitizedEnv: returns an object with PATH key', () => {
60
- const env = buildSanitizedEnv();
61
- assert.ok('PATH' in env);
62
- assert.equal(typeof env.PATH, 'string');
63
- assert.ok(env.PATH.length > 0);
64
- });
65
-
66
- test('buildSanitizedEnv: PATH includes extra directories', () => {
67
- const env = buildSanitizedEnv();
68
- assert.ok(env.PATH.includes('/usr/local/bin'));
69
- });
70
-
71
- test('buildSanitizedEnv: HOME is set', () => {
72
- const env = buildSanitizedEnv();
73
- assert.ok('HOME' in env);
74
- assert.equal(typeof env.HOME, 'string');
75
- assert.ok(env.HOME.length > 0);
76
- });
77
-
78
- test('buildSanitizedEnv: CLAUDE_CODE_ENTRYPOINT is removed', () => {
79
- process.env.CLAUDE_CODE_ENTRYPOINT = 'test_value';
80
- const env = buildSanitizedEnv();
81
- assert.equal(env.CLAUDE_CODE_ENTRYPOINT, undefined);
82
- delete process.env.CLAUDE_CODE_ENTRYPOINT;
83
- });
84
-
85
- test('buildSanitizedEnv: CLAUDECODE is removed', () => {
86
- process.env.CLAUDECODE = 'test_value';
87
- const env = buildSanitizedEnv();
88
- assert.equal(env.CLAUDECODE, undefined);
89
- delete process.env.CLAUDECODE;
90
- });
91
-
92
- test('buildSanitizedEnv: contains process.env values', () => {
93
- const testKey = 'VIBE_TEST_UNIQUE_KEY_' + Date.now();
94
- process.env[testKey] = 'test_value_123';
95
- const env = buildSanitizedEnv();
96
- assert.equal(env[testKey], 'test_value_123');
97
- delete process.env[testKey];
98
- });
99
-
100
- // execViaLoginShell tests
101
-
102
- test('execViaLoginShell: returns correct command (a shell path)', () => {
103
- const result = execViaLoginShell('claude', ['--help']);
104
- assert.equal(typeof result.command, 'string');
105
- assert.ok(result.command.startsWith('/'));
106
- });
107
-
108
- test('execViaLoginShell: args contain -lc flag', () => {
109
- const result = execViaLoginShell('claude', ['--help']);
110
- assert.equal(result.args[0], '-lc');
111
- });
112
-
113
- test('execViaLoginShell: includes the passed cmd in the shell command string', () => {
114
- const result = execViaLoginShell('claude', ['--help', '--verbose']);
115
- assert.ok(result.args[1].includes('claude'));
116
- });
117
-
118
- test('execViaLoginShell: includes the passed args after -- separator', () => {
119
- const result = execViaLoginShell('claude', ['--help', '--verbose']);
120
- const dashDashIndex = result.args.indexOf('--');
121
- assert.ok(dashDashIndex >= 0);
122
- assert.equal(result.args[dashDashIndex + 1], '--help');
123
- assert.equal(result.args[dashDashIndex + 2], '--verbose');
124
- });
125
-
126
- // config object tests
127
-
128
- test('config.port: defaults to 9876 when VIBE_PORT not set', () => {
129
- assert.equal(config.port, 9876);
130
- });
131
-
132
- test('config.legacyToken: defaults to an empty string', () => {
133
- assert.equal(config.legacyToken, '');
134
- });
135
-
136
- test('config.legacyToken: respects VIBE_TOKEN env override on fresh import', async () => {
137
- const original = process.env.VIBE_TOKEN;
138
- process.env.VIBE_TOKEN = 'legacy-secret';
139
- try {
140
- const freshModule = await import(`./config.ts?test=${Date.now()}`);
141
- assert.equal(freshModule.config.legacyToken, 'legacy-secret');
142
- } finally {
143
- if (original == null) {
144
- delete process.env.VIBE_TOKEN;
145
- } else {
146
- process.env.VIBE_TOKEN = original;
147
- }
148
- }
149
- });
150
-
151
- test('config.idleTimeoutMs: allows disabling idle sweep with 0', () => {
152
- assert.equal(
153
- readConfigValueInIsolatedProcess(
154
- { VIBE_IDLE_TIMEOUT_MS: '0' },
155
- 'config.idleTimeoutMs',
156
- ),
157
- '0',
158
- );
159
- });
160
-
161
- test('config.turnStallTimeoutMs: defaults to 5 minutes', () => {
162
- assert.equal(config.turnStallTimeoutMs, 5 * 60 * 1000);
163
- });
164
-
165
- test('config.turnStallTimeoutMs: allows disabling stall sweep with 0', () => {
166
- assert.equal(
167
- readConfigValueInIsolatedProcess(
168
- { VIBE_TURN_STALL_TIMEOUT_MS: '0' },
169
- 'config.turnStallTimeoutMs',
170
- ),
171
- '0',
172
- );
173
- });
174
-
175
- test('config.turnStallTimeoutMs: respects env override on fresh import', () => {
176
- assert.equal(
177
- readConfigValueInIsolatedProcess(
178
- { VIBE_TURN_STALL_TIMEOUT_MS: '120000' },
179
- 'config.turnStallTimeoutMs',
180
- ),
181
- '120000',
182
- );
183
- });
184
-
185
- test('config.isTransientPath: is the isTransientPath function', () => {
186
- assert.equal(config.isTransientPath, isTransientPath);
187
- });
188
-
189
- test('config.buildSanitizedEnv: is the buildSanitizedEnv function', () => {
190
- assert.equal(config.buildSanitizedEnv, buildSanitizedEnv);
191
- });
192
-
193
- // Binary detection / cached resolver tests
194
-
195
- test('config.claudePath: returns a path string', () => {
196
- // This may resolve to a real path or fall back to 'claude'
197
- const path = config.claudePath;
198
- assert.equal(typeof path, 'string');
199
- assert.ok(path.length > 0);
200
- });
201
-
202
- test('config.codexPath: returns a path string', () => {
203
- const path = config.codexPath;
204
- assert.equal(typeof path, 'string');
205
- assert.ok(path.length > 0);
206
- });
207
-
208
- test('config.claudePath: respects CLAUDE_PATH env override', () => {
209
- assert.equal(
210
- readConfigValueInIsolatedProcess(
211
- { CLAUDE_PATH: '/custom/path/to/claude' },
212
- 'config.claudePath',
213
- ),
214
- '/custom/path/to/claude',
215
- );
216
- });
217
-
218
- test('config.codexPath: respects CODEX_PATH env override', () => {
219
- assert.equal(
220
- readConfigValueInIsolatedProcess(
221
- { CODEX_PATH: '/custom/path/to/codex' },
222
- 'config.codexPath',
223
- ),
224
- '/custom/path/to/codex',
225
- );
226
- });
227
-
228
- test('buildSanitizedEnv: PATH includes all required extra directories', () => {
229
- const env = buildSanitizedEnv();
230
- const home = homedir();
231
- const requiredDirs = [
232
- '/usr/local/bin',
233
- '/opt/homebrew/bin',
234
- join(home, '.npm-global', 'bin'),
235
- join(home, '.local', 'bin'),
236
- join(home, '.claude', 'bin'),
237
- ];
238
- for (const dir of requiredDirs) {
239
- assert.ok(env.PATH.includes(dir), `PATH should include ${dir}`);
240
- }
241
- });
242
-
243
- test('buildSanitizedEnv: includes home-relative paths', () => {
244
- const env = buildSanitizedEnv();
245
- const home = homedir();
246
- assert.ok(env.PATH.includes(join(home, '.local', 'bin')) || env.PATH.includes('.local/bin'));
247
- });
248
-
249
- test('execViaLoginShell: works with codex command', () => {
250
- const result = execViaLoginShell('codex', ['app-server', '--listen', 'stdio://']);
251
- assert.ok(result.args[1].includes('codex'));
252
- const dashDashIndex = result.args.indexOf('--');
253
- assert.equal(result.args[dashDashIndex + 1], 'app-server');
254
- });