@vibelet/cli 0.1.37 → 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 +25 -24
  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,125 +0,0 @@
1
- import test from 'node:test';
2
- import assert from 'node:assert/strict';
3
- import type { NetworkInterfaceInfo } from 'os';
4
- import {
5
- computeAdvertisedConnectionTarget,
6
- computeAdvertisedHosts,
7
- parseTailscaleStatus,
8
- readConfiguredFallbackHosts,
9
- readTailscaleHosts,
10
- } from './advertised-hosts.js';
11
-
12
- function ipv4(address: string): NetworkInterfaceInfo {
13
- return {
14
- address,
15
- netmask: '255.255.255.0',
16
- family: 'IPv4',
17
- mac: '00:00:00:00:00:00',
18
- internal: false,
19
- cidr: `${address}/24`,
20
- };
21
- }
22
-
23
- test('computeAdvertisedHosts prefers configured canonical host and prioritizes Tailscale IPs', () => {
24
- const advertised = computeAdvertisedHosts({
25
- canonicalHost: 'desk-mac.local',
26
- configuredCanonicalHost: 'desk.tailnet.ts.net',
27
- configuredFallbackHosts: ['100.88.1.9'],
28
- tailscaleCanonicalHost: '100.77.2.3',
29
- tailscaleFallbackHosts: ['desk.ts.net'],
30
- interfaces: {
31
- en0: [ipv4('192.168.31.20')],
32
- utun8: [ipv4('100.77.2.3')],
33
- },
34
- });
35
-
36
- assert.equal(advertised.canonicalHost, 'desk.tailnet.ts.net');
37
- assert.deepStrictEqual(advertised.fallbackHosts, ['desk-mac.local', '100.88.1.9', 'desk.ts.net', '100.77.2.3', '192.168.31.20']);
38
- });
39
-
40
- test('computeAdvertisedHosts removes duplicates and excludes the canonical host', () => {
41
- const advertised = computeAdvertisedHosts({
42
- canonicalHost: '100.77.2.3',
43
- configuredFallbackHosts: ['100.77.2.3', '192.168.31.20', '192.168.31.20'],
44
- interfaces: {
45
- utun8: [ipv4('100.77.2.3')],
46
- en0: [ipv4('192.168.31.20')],
47
- },
48
- });
49
-
50
- assert.equal(advertised.canonicalHost, '100.77.2.3');
51
- assert.deepStrictEqual(advertised.fallbackHosts, ['192.168.31.20']);
52
- });
53
-
54
- test('computeAdvertisedHosts filters out link-local and benchmark addresses', () => {
55
- const advertised = computeAdvertisedHosts({
56
- canonicalHost: 'desk-mac.local',
57
- interfaces: {
58
- en0: [ipv4('192.168.31.20'), ipv4('169.254.12.2')],
59
- utun4: [ipv4('198.19.0.1')],
60
- },
61
- });
62
-
63
- assert.equal(advertised.canonicalHost, 'desk-mac.local');
64
- assert.deepStrictEqual(advertised.fallbackHosts, ['192.168.31.20']);
65
- });
66
-
67
- test('parseTailscaleStatus prefers the first Tailscale IP and keeps MagicDNS as fallback', () => {
68
- const advertised = parseTailscaleStatus(JSON.stringify({
69
- Self: {
70
- DNSName: 'desk.tailnet.ts.net.',
71
- TailscaleIPs: ['100.88.1.9', '100.99.2.4'],
72
- },
73
- }));
74
-
75
- assert.deepStrictEqual(advertised, {
76
- canonicalHost: '100.88.1.9',
77
- fallbackHosts: ['desk.tailnet.ts.net', '100.99.2.4'],
78
- });
79
- });
80
-
81
- test('readTailscaleHosts returns empty data when tailscale is unavailable', () => {
82
- const advertised = readTailscaleHosts(() => {
83
- throw new Error('tailscale unavailable');
84
- });
85
-
86
- assert.deepStrictEqual(advertised, { fallbackHosts: [] });
87
- });
88
-
89
- test('readConfiguredFallbackHosts parses comma separated env values', () => {
90
- assert.deepStrictEqual(
91
- readConfiguredFallbackHosts(' 100.77.2.3, desk.tailnet.ts.net , 192.168.31.20 '),
92
- ['100.77.2.3', 'desk.tailnet.ts.net', '192.168.31.20'],
93
- );
94
- });
95
-
96
- test('computeAdvertisedConnectionTarget keeps the base host and port without a relay', () => {
97
- assert.deepStrictEqual(
98
- computeAdvertisedConnectionTarget({
99
- canonicalHost: 'desk-mac.local',
100
- fallbackHosts: ['100.88.1.9', '192.168.31.20'],
101
- port: 9876,
102
- }),
103
- {
104
- canonicalHost: 'desk-mac.local',
105
- fallbackHosts: ['100.88.1.9', '192.168.31.20'],
106
- port: 9876,
107
- },
108
- );
109
- });
110
-
111
- test('computeAdvertisedConnectionTarget prefers the relay host and preserves local fallbacks', () => {
112
- assert.deepStrictEqual(
113
- computeAdvertisedConnectionTarget({
114
- canonicalHost: 'desk-mac.local',
115
- fallbackHosts: ['desk-mac.local', '100.88.1.9', '100.88.1.9', '192.168.31.20'],
116
- port: 9876,
117
- relayUrl: 'https://relay.example.com',
118
- }),
119
- {
120
- canonicalHost: 'relay.example.com',
121
- fallbackHosts: ['desk-mac.local', '100.88.1.9', '192.168.31.20'],
122
- port: 443,
123
- },
124
- );
125
- });
@@ -1,225 +0,0 @@
1
- import { execFileSync } from 'child_process';
2
- import type { NetworkInterfaceInfo } from 'os';
3
-
4
- export interface AdvertisedHostsOptions {
5
- canonicalHost: string;
6
- configuredCanonicalHost?: string;
7
- configuredFallbackHosts?: string[];
8
- tailscaleCanonicalHost?: string;
9
- tailscaleFallbackHosts?: string[];
10
- interfaces: NodeJS.Dict<NetworkInterfaceInfo[]>;
11
- }
12
-
13
- interface TailscaleStatusPayload {
14
- Self?: {
15
- DNSName?: string;
16
- TailscaleIPs?: string[];
17
- };
18
- }
19
-
20
- export interface TailscaleHosts {
21
- canonicalHost?: string;
22
- fallbackHosts: string[];
23
- }
24
-
25
- export interface AdvertisedConnectionTargetOptions {
26
- canonicalHost: string;
27
- fallbackHosts?: string[];
28
- port: number;
29
- relayUrl?: string;
30
- }
31
-
32
- export interface AdvertisedConnectionTarget {
33
- canonicalHost: string;
34
- fallbackHosts: string[];
35
- port: number;
36
- }
37
-
38
- function isIpv4(address: string): boolean {
39
- const parts = address.split('.');
40
- if (parts.length !== 4) return false;
41
- return parts.every((part) => /^\d+$/.test(part) && Number(part) >= 0 && Number(part) <= 255);
42
- }
43
-
44
- function isTailscaleIpv4(address: string): boolean {
45
- if (!isIpv4(address)) return false;
46
- const [first, second] = address.split('.').map(Number);
47
- return first === 100 && second >= 64 && second <= 127;
48
- }
49
-
50
- function isLinkLocalIpv4(address: string): boolean {
51
- if (!isIpv4(address)) return false;
52
- const [first, second] = address.split('.').map(Number);
53
- return first === 169 && second === 254;
54
- }
55
-
56
- function isBenchmarkIpv4(address: string): boolean {
57
- if (!isIpv4(address)) return false;
58
- const [first, second] = address.split('.').map(Number);
59
- return first === 198 && (second === 18 || second === 19);
60
- }
61
-
62
- function isUsableHost(address: string): boolean {
63
- return Boolean(address)
64
- && !isLinkLocalIpv4(address)
65
- && !isBenchmarkIpv4(address);
66
- }
67
-
68
- function normalizeHost(host: string | undefined): string | undefined {
69
- if (!host) return undefined;
70
- const trimmed = host.trim().replace(/\.$/, '');
71
- return trimmed ? trimmed.toLowerCase() : undefined;
72
- }
73
-
74
- function normalizeFallbackHosts(
75
- hosts: string[] | undefined,
76
- canonicalHost: string,
77
- ): string[] {
78
- return (hosts ?? [])
79
- .map((host) => normalizeHost(host))
80
- .filter((host): host is string => Boolean(host))
81
- .filter((host) => isUsableHost(host))
82
- .filter((host, index, all) => host !== canonicalHost && all.indexOf(host) === index);
83
- }
84
-
85
- export function readConfiguredFallbackHosts(rawValue: string | undefined): string[] {
86
- if (!rawValue) return [];
87
- return rawValue
88
- .split(',')
89
- .map((entry) => entry.trim())
90
- .filter(Boolean);
91
- }
92
-
93
- function collectInterfaceHosts(interfaces: NodeJS.Dict<NetworkInterfaceInfo[]>): string[] {
94
- const tailscaleHosts: string[] = [];
95
- const lanHosts: string[] = [];
96
-
97
- for (const entries of Object.values(interfaces)) {
98
- if (!entries) continue;
99
- for (const entry of entries) {
100
- if (entry.internal || entry.family !== 'IPv4') continue;
101
- if (!isUsableHost(entry.address)) continue;
102
- if (isTailscaleIpv4(entry.address)) {
103
- tailscaleHosts.push(entry.address);
104
- } else {
105
- lanHosts.push(entry.address);
106
- }
107
- }
108
- }
109
-
110
- return [...tailscaleHosts, ...lanHosts];
111
- }
112
-
113
- export function parseTailscaleStatus(rawStatus: string): TailscaleHosts {
114
- const parsed = JSON.parse(rawStatus) as TailscaleStatusPayload;
115
- const dnsName = normalizeHost(parsed.Self?.DNSName);
116
- const tailscaleIps = (parsed.Self?.TailscaleIPs ?? [])
117
- .map((host) => normalizeHost(host))
118
- .filter((host): host is string => Boolean(host))
119
- .filter((host) => isTailscaleIpv4(host) && isUsableHost(host));
120
- const canonicalHost = tailscaleIps[0] ?? dnsName;
121
- const fallbackHosts = [
122
- ...(dnsName && dnsName !== canonicalHost ? [dnsName] : []),
123
- ...tailscaleIps.filter((host) => host !== canonicalHost),
124
- ];
125
-
126
- return {
127
- canonicalHost,
128
- fallbackHosts,
129
- };
130
- }
131
-
132
- export function readTailscaleHosts(runCommand: typeof execFileSync = execFileSync): TailscaleHosts {
133
- const socketPaths = [
134
- process.env.TAILSCALE_SOCKET,
135
- '/tmp/tailscale.sock',
136
- ].filter(Boolean) as string[];
137
-
138
- // Try with custom socket paths first
139
- for (const socket of socketPaths) {
140
- try {
141
- const rawStatus = runCommand('tailscale', ['--socket', socket, 'status', '--json'], {
142
- encoding: 'utf8',
143
- stdio: ['ignore', 'pipe', 'pipe'],
144
- timeout: 1500,
145
- });
146
- return parseTailscaleStatus(rawStatus);
147
- } catch { /* try next */ }
148
- }
149
-
150
- // Fallback to default socket
151
- try {
152
- const rawStatus = runCommand('tailscale', ['status', '--json'], {
153
- encoding: 'utf8',
154
- stdio: ['ignore', 'pipe', 'pipe'],
155
- timeout: 1500,
156
- });
157
- return parseTailscaleStatus(rawStatus);
158
- } catch {
159
- return { fallbackHosts: [] };
160
- }
161
- }
162
-
163
- export function computeAdvertisedConnectionTarget(
164
- options: AdvertisedConnectionTargetOptions,
165
- ): AdvertisedConnectionTarget {
166
- const baseCanonicalHost = normalizeHost(options.canonicalHost) || 'localhost';
167
- const baseFallbackHosts = normalizeFallbackHosts(options.fallbackHosts, baseCanonicalHost);
168
-
169
- if (!options.relayUrl) {
170
- return {
171
- canonicalHost: baseCanonicalHost,
172
- fallbackHosts: baseFallbackHosts,
173
- port: options.port,
174
- };
175
- }
176
-
177
- try {
178
- const relay = new URL(options.relayUrl);
179
- const relayCanonicalHost = normalizeHost(relay.hostname);
180
- if (!relayCanonicalHost) {
181
- throw new Error('invalid relay hostname');
182
- }
183
-
184
- const relayPort = relay.port
185
- ? Number(relay.port)
186
- : (relay.protocol === 'https:' ? 443 : 80);
187
-
188
- return {
189
- canonicalHost: relayCanonicalHost,
190
- fallbackHosts: normalizeFallbackHosts([baseCanonicalHost, ...baseFallbackHosts], relayCanonicalHost),
191
- port: Number.isFinite(relayPort) && relayPort > 0 ? Math.floor(relayPort) : options.port,
192
- };
193
- } catch {
194
- return {
195
- canonicalHost: baseCanonicalHost,
196
- fallbackHosts: baseFallbackHosts,
197
- port: options.port,
198
- };
199
- }
200
- }
201
-
202
- export function computeAdvertisedHosts(options: AdvertisedHostsOptions): { canonicalHost: string; fallbackHosts: string[] } {
203
- const baseCanonicalHost = normalizeHost(options.canonicalHost);
204
- const canonicalHost = normalizeHost(options.configuredCanonicalHost)
205
- || normalizeHost(options.tailscaleCanonicalHost)
206
- || baseCanonicalHost
207
- || 'localhost';
208
- const fallbackHosts = [
209
- ...(baseCanonicalHost && baseCanonicalHost !== canonicalHost
210
- ? [baseCanonicalHost]
211
- : []),
212
- ...(options.configuredFallbackHosts ?? []),
213
- ...(options.tailscaleFallbackHosts ?? []),
214
- ...collectInterfaceHosts(options.interfaces),
215
- ]
216
- .map((host) => normalizeHost(host))
217
- .filter((host): host is string => Boolean(host))
218
- .filter((host) => isUsableHost(host))
219
- .filter((host, index, all) => host !== canonicalHost && all.indexOf(host) === index);
220
-
221
- return {
222
- canonicalHost,
223
- fallbackHosts,
224
- };
225
- }
package/src/audit.test.ts DELETED
@@ -1,38 +0,0 @@
1
- import test from 'node:test';
2
- import assert from 'node:assert/strict';
3
- import { buildAppAuditEntry, sanitizeAppAuditData } from './audit.js';
4
-
5
- test('sanitizeAppAuditData strips reserved audit fields from client payloads', () => {
6
- assert.deepEqual(
7
- sanitizeAppAuditData({
8
- event: 'override',
9
- source: 'app',
10
- level: 'debug',
11
- appEvent: 'fake',
12
- ts: '2026-01-01T00:00:00.000Z',
13
- sessionId: 'session-123',
14
- agent: 'codex',
15
- }),
16
- {
17
- sessionId: 'session-123',
18
- agent: 'codex',
19
- },
20
- );
21
- });
22
-
23
- test('buildAppAuditEntry preserves the audit envelope while keeping client data', () => {
24
- const entry = buildAppAuditEntry('app.session.send', 'info', {
25
- sessionId: 'session-123',
26
- event: 'override',
27
- level: 'debug',
28
- }, '2026-03-21T12:00:00.000Z');
29
-
30
- assert.deepEqual(entry, {
31
- ts: '2026-03-21T12:00:00.000Z',
32
- event: 'app.log',
33
- source: 'app',
34
- appEvent: 'app.session.send',
35
- level: 'info',
36
- sessionId: 'session-123',
37
- });
38
- });
package/src/audit.ts DELETED
@@ -1,117 +0,0 @@
1
- /**
2
- * Size-bounded audit log for session lifecycle events.
3
- *
4
- * Writes JSONL to ~/.vibelet/data/audit.jsonl.
5
- * Each line is a self-contained event with timestamp, event type, and context.
6
- *
7
- * Usage:
8
- * import { audit } from './audit.js';
9
- * audit.emit('session.create', { sessionId, agent, cwd });
10
- * audit.emit('session.done', { sessionId, cost, usage });
11
- */
12
-
13
- import { appendFileSync, mkdirSync } from 'fs';
14
- import { dirname } from 'path';
15
- import { AUDIT_PATH } from './paths.js';
16
- import { config } from './config.js';
17
- import { trimFileTailSync } from './storage-housekeeping.js';
18
-
19
- export type AuditEvent =
20
- | 'session.create'
21
- | 'session.resume'
22
- | 'session.reconnect'
23
- | 'session.send'
24
- | 'session.done'
25
- | 'session.interrupted'
26
- | 'session.stop'
27
- | 'session.delete'
28
- | 'session.interrupt'
29
- | 'driver.spawn'
30
- | 'driver.init'
31
- | 'driver.exit'
32
- | 'driver.error'
33
- | 'driver.idle_timeout'
34
- | 'driver.stall_timeout'
35
- | 'approval.request'
36
- | 'approval.response'
37
- | 'ws.connect'
38
- | 'ws.disconnect'
39
- | 'daemon.start'
40
- | 'daemon.shutdown'
41
- | 'daemon.error'
42
- | 'app.log';
43
-
44
- export type AuditSource = 'daemon' | 'app';
45
-
46
- interface AuditEntry {
47
- ts: string;
48
- event: AuditEvent | string;
49
- source?: AuditSource;
50
- [key: string]: unknown;
51
- }
52
-
53
- let initialized = false;
54
- const APP_AUDIT_RESERVED_FIELDS = new Set(['ts', 'event', 'source', 'appEvent', 'level']);
55
-
56
- function isTestRuntime(): boolean {
57
- return process.env.VIBE_TEST === '1' || process.argv.includes('--test');
58
- }
59
-
60
- export function sanitizeAppAuditData(data: Record<string, unknown> = {}): Record<string, unknown> {
61
- const sanitized: Record<string, unknown> = {};
62
- for (const [key, value] of Object.entries(data)) {
63
- if (APP_AUDIT_RESERVED_FIELDS.has(key)) continue;
64
- sanitized[key] = value;
65
- }
66
- return sanitized;
67
- }
68
-
69
- export function buildAppAuditEntry(
70
- appEvent: string,
71
- level: string,
72
- data: Record<string, unknown> = {},
73
- clientTs?: string,
74
- ): AuditEntry {
75
- return {
76
- ts: clientTs ?? new Date().toISOString(),
77
- event: 'app.log',
78
- source: 'app' as AuditSource,
79
- appEvent,
80
- level,
81
- ...sanitizeAppAuditData(data),
82
- };
83
- }
84
-
85
- function ensureDir(): void {
86
- if (initialized) return;
87
- mkdirSync(dirname(AUDIT_PATH), { recursive: true });
88
- initialized = true;
89
- }
90
-
91
- class AuditLog {
92
- emit(event: AuditEvent, data: Record<string, unknown> = {}): void {
93
- this.write({ ts: new Date().toISOString(), event, ...data });
94
- }
95
-
96
- /** Write an app-reported log entry. Preserves client-side timestamp if provided. */
97
- emitApp(appEvent: string, level: string, data: Record<string, unknown> = {}, clientTs?: string): void {
98
- this.write(buildAppAuditEntry(appEvent, level, data, clientTs));
99
- }
100
-
101
- private write(entry: Record<string, unknown>): void {
102
- if (isTestRuntime()) return;
103
- ensureDir();
104
- try {
105
- const line = JSON.stringify(entry) + '\n';
106
- trimFileTailSync(AUDIT_PATH, {
107
- maxBytes: config.auditMaxBytes,
108
- incomingBytes: Buffer.byteLength(line),
109
- });
110
- appendFileSync(AUDIT_PATH, line);
111
- } catch {
112
- // Audit log is best-effort — never crash the daemon
113
- }
114
- }
115
- }
116
-
117
- export const audit = new AuditLog();
package/src/auth.ts DELETED
@@ -1,31 +0,0 @@
1
- export function isLoopbackAddress(address: string | undefined): boolean {
2
- if (!address) return false;
3
- return address === '127.0.0.1'
4
- || address === '::1'
5
- || address === '::ffff:127.0.0.1';
6
- }
7
-
8
- export function readBearerToken(header: string | undefined): string | null {
9
- if (!header) return null;
10
- const match = header.match(/^Bearer\s+(.+)$/i);
11
- return match?.[1]?.trim() || null;
12
- }
13
-
14
- export function resolveRequestToken(authHeader: string | undefined, queryToken: string | null): string | null {
15
- return readBearerToken(authHeader) ?? queryToken;
16
- }
17
-
18
- export function isLegacyToken(token: string | null, legacyToken: string): boolean {
19
- return Boolean(token && legacyToken && token === legacyToken);
20
- }
21
-
22
- export function isAuthorizedToken(
23
- token: string | null,
24
- legacyToken: string,
25
- validatePairToken: (token: string, touch?: boolean) => unknown,
26
- touch = true,
27
- ): boolean {
28
- if (!token) return false;
29
- if (isLegacyToken(token, legacyToken)) return true;
30
- return Boolean(validatePairToken(token, touch));
31
- }