everything-dev 0.3.3 → 1.3.3

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 (313) hide show
  1. package/README.md +64 -0
  2. package/cli.js +10 -0
  3. package/dist/_virtual/_rolldown/runtime.cjs +29 -0
  4. package/dist/api-contract.cjs +172 -0
  5. package/dist/api-contract.cjs.map +1 -0
  6. package/dist/api-contract.mjs +171 -0
  7. package/dist/api-contract.mjs.map +1 -0
  8. package/dist/api.cjs +124 -0
  9. package/dist/api.cjs.map +1 -0
  10. package/dist/api.d.cts +36 -0
  11. package/dist/api.d.cts.map +1 -0
  12. package/dist/api.d.mts +36 -0
  13. package/dist/api.d.mts.map +1 -0
  14. package/dist/api.mjs +119 -0
  15. package/dist/api.mjs.map +1 -0
  16. package/dist/app.cjs +156 -0
  17. package/dist/app.cjs.map +1 -0
  18. package/dist/app.mjs +153 -0
  19. package/dist/app.mjs.map +1 -0
  20. package/dist/cli/catalog.cjs +30 -0
  21. package/dist/cli/catalog.cjs.map +1 -0
  22. package/dist/cli/catalog.mjs +29 -0
  23. package/dist/cli/catalog.mjs.map +1 -0
  24. package/dist/cli/help.cjs +16 -0
  25. package/dist/cli/help.cjs.map +1 -0
  26. package/dist/cli/help.mjs +16 -0
  27. package/dist/cli/help.mjs.map +1 -0
  28. package/dist/cli/init.cjs +287 -0
  29. package/dist/cli/init.cjs.map +1 -0
  30. package/dist/cli/init.d.cts +36 -0
  31. package/dist/cli/init.d.cts.map +1 -0
  32. package/dist/cli/init.d.mts +36 -0
  33. package/dist/cli/init.d.mts.map +1 -0
  34. package/dist/cli/init.mjs +279 -0
  35. package/dist/cli/init.mjs.map +1 -0
  36. package/dist/cli/parse.cjs +96 -0
  37. package/dist/cli/parse.cjs.map +1 -0
  38. package/dist/cli/parse.mjs +95 -0
  39. package/dist/cli/parse.mjs.map +1 -0
  40. package/dist/cli/prompts.cjs +42 -0
  41. package/dist/cli/prompts.cjs.map +1 -0
  42. package/dist/cli/prompts.mjs +41 -0
  43. package/dist/cli/prompts.mjs.map +1 -0
  44. package/dist/cli.cjs +167 -0
  45. package/dist/cli.cjs.map +1 -0
  46. package/dist/cli.d.cts +1 -0
  47. package/dist/cli.d.mts +1 -0
  48. package/dist/cli.mjs +166 -0
  49. package/dist/cli.mjs.map +1 -0
  50. package/dist/components/dev-view.cjs +307 -0
  51. package/dist/components/dev-view.cjs.map +1 -0
  52. package/dist/components/dev-view.mjs +306 -0
  53. package/dist/components/dev-view.mjs.map +1 -0
  54. package/dist/components/streaming-view.cjs +146 -0
  55. package/dist/components/streaming-view.cjs.map +1 -0
  56. package/dist/components/streaming-view.mjs +144 -0
  57. package/dist/components/streaming-view.mjs.map +1 -0
  58. package/dist/config.cjs +280 -0
  59. package/dist/config.cjs.map +1 -0
  60. package/dist/config.d.cts +35 -0
  61. package/dist/config.d.cts.map +1 -0
  62. package/dist/config.d.mts +35 -0
  63. package/dist/config.d.mts.map +1 -0
  64. package/dist/config.mjs +266 -0
  65. package/dist/config.mjs.map +1 -0
  66. package/dist/contract.cjs +209 -0
  67. package/dist/contract.cjs.map +1 -0
  68. package/dist/contract.d.cts +490 -0
  69. package/dist/contract.d.cts.map +1 -0
  70. package/dist/contract.d.mts +490 -0
  71. package/dist/contract.d.mts.map +1 -0
  72. package/dist/contract.meta.cjs +104 -0
  73. package/dist/contract.meta.cjs.map +1 -0
  74. package/dist/contract.meta.d.cts +141 -0
  75. package/dist/contract.meta.d.cts.map +1 -0
  76. package/dist/contract.meta.d.mts +141 -0
  77. package/dist/contract.meta.d.mts.map +1 -0
  78. package/dist/contract.meta.mjs +102 -0
  79. package/dist/contract.meta.mjs.map +1 -0
  80. package/dist/contract.mjs +186 -0
  81. package/dist/contract.mjs.map +1 -0
  82. package/dist/dev-logs.cjs +53 -0
  83. package/dist/dev-logs.cjs.map +1 -0
  84. package/dist/dev-logs.mjs +51 -0
  85. package/dist/dev-logs.mjs.map +1 -0
  86. package/dist/dev-session.cjs +195 -0
  87. package/dist/dev-session.cjs.map +1 -0
  88. package/dist/dev-session.mjs +194 -0
  89. package/dist/dev-session.mjs.map +1 -0
  90. package/dist/fastkv.cjs +89 -0
  91. package/dist/fastkv.cjs.map +1 -0
  92. package/dist/fastkv.d.cts +11 -0
  93. package/dist/fastkv.d.cts.map +1 -0
  94. package/dist/fastkv.d.mts +11 -0
  95. package/dist/fastkv.d.mts.map +1 -0
  96. package/dist/fastkv.mjs +82 -0
  97. package/dist/fastkv.mjs.map +1 -0
  98. package/dist/federation.server.cjs +27 -0
  99. package/dist/federation.server.cjs.map +1 -0
  100. package/dist/federation.server.mjs +27 -0
  101. package/dist/federation.server.mjs.map +1 -0
  102. package/dist/host.cjs +367 -0
  103. package/dist/host.cjs.map +1 -0
  104. package/dist/host.d.cts +22 -0
  105. package/dist/host.d.cts.map +1 -0
  106. package/dist/host.d.mts +22 -0
  107. package/dist/host.d.mts.map +1 -0
  108. package/dist/host.mjs +364 -0
  109. package/dist/host.mjs.map +1 -0
  110. package/dist/index.cjs +122 -0
  111. package/dist/index.d.cts +7 -0
  112. package/dist/index.d.mts +7 -0
  113. package/dist/index.mjs +9 -0
  114. package/dist/integrity.cjs +39 -0
  115. package/dist/integrity.cjs.map +1 -0
  116. package/dist/integrity.d.cts +7 -0
  117. package/dist/integrity.d.cts.map +1 -0
  118. package/dist/integrity.d.mts +7 -0
  119. package/dist/integrity.d.mts.map +1 -0
  120. package/dist/integrity.mjs +35 -0
  121. package/dist/integrity.mjs.map +1 -0
  122. package/dist/internal/manifest-normalizer.cjs +140 -0
  123. package/dist/internal/manifest-normalizer.cjs.map +1 -0
  124. package/dist/internal/manifest-normalizer.mjs +138 -0
  125. package/dist/internal/manifest-normalizer.mjs.map +1 -0
  126. package/dist/mf.cjs +77 -0
  127. package/dist/mf.cjs.map +1 -0
  128. package/dist/mf.d.cts +19 -0
  129. package/dist/mf.d.cts.map +1 -0
  130. package/dist/mf.d.mts +19 -0
  131. package/dist/mf.d.mts.map +1 -0
  132. package/dist/mf.mjs +71 -0
  133. package/dist/mf.mjs.map +1 -0
  134. package/dist/near-cli.cjs +196 -0
  135. package/dist/near-cli.cjs.map +1 -0
  136. package/dist/near-cli.mjs +193 -0
  137. package/dist/near-cli.mjs.map +1 -0
  138. package/dist/network.cjs +9 -0
  139. package/dist/network.cjs.map +1 -0
  140. package/dist/network.mjs +8 -0
  141. package/dist/network.mjs.map +1 -0
  142. package/dist/orchestrator.cjs +441 -0
  143. package/dist/orchestrator.cjs.map +1 -0
  144. package/dist/orchestrator.d.cts +40 -0
  145. package/dist/orchestrator.d.cts.map +1 -0
  146. package/dist/orchestrator.d.mts +40 -0
  147. package/dist/orchestrator.d.mts.map +1 -0
  148. package/dist/orchestrator.mjs +436 -0
  149. package/dist/orchestrator.mjs.map +1 -0
  150. package/dist/plugin.cjs +830 -0
  151. package/dist/plugin.cjs.map +1 -0
  152. package/dist/plugin.d.cts +347 -0
  153. package/dist/plugin.d.cts.map +1 -0
  154. package/dist/plugin.d.mts +348 -0
  155. package/dist/plugin.d.mts.map +1 -0
  156. package/dist/plugin.mjs +827 -0
  157. package/dist/plugin.mjs.map +1 -0
  158. package/dist/process-registry.cjs +120 -0
  159. package/dist/process-registry.cjs.map +1 -0
  160. package/dist/process-registry.d.cts +25 -0
  161. package/dist/process-registry.d.cts.map +1 -0
  162. package/dist/process-registry.d.mts +25 -0
  163. package/dist/process-registry.d.mts.map +1 -0
  164. package/dist/process-registry.mjs +119 -0
  165. package/dist/process-registry.mjs.map +1 -0
  166. package/dist/sdk.cjs +61 -0
  167. package/dist/sdk.d.cts +5 -0
  168. package/dist/sdk.d.mts +5 -0
  169. package/dist/sdk.mjs +6 -0
  170. package/dist/shared.cjs +143 -0
  171. package/dist/shared.cjs.map +1 -0
  172. package/dist/shared.d.cts +33 -0
  173. package/dist/shared.d.cts.map +1 -0
  174. package/dist/shared.d.mts +33 -0
  175. package/dist/shared.d.mts.map +1 -0
  176. package/dist/shared.mjs +140 -0
  177. package/dist/shared.mjs.map +1 -0
  178. package/dist/types.cjs +160 -0
  179. package/dist/types.cjs.map +1 -0
  180. package/dist/types.d.cts +269 -0
  181. package/dist/types.d.cts.map +1 -0
  182. package/dist/types.d.mts +269 -0
  183. package/dist/types.d.mts.map +1 -0
  184. package/dist/types.mjs +144 -0
  185. package/dist/types.mjs.map +1 -0
  186. package/dist/ui/head.cjs +67 -0
  187. package/dist/ui/head.cjs.map +1 -0
  188. package/dist/ui/head.d.cts +19 -0
  189. package/dist/ui/head.d.cts.map +1 -0
  190. package/dist/ui/head.d.mts +19 -0
  191. package/dist/ui/head.d.mts.map +1 -0
  192. package/dist/ui/head.mjs +61 -0
  193. package/dist/ui/head.mjs.map +1 -0
  194. package/dist/ui/index.cjs +32 -0
  195. package/dist/ui/index.d.cts +7 -0
  196. package/dist/ui/index.d.mts +7 -0
  197. package/dist/ui/index.mjs +6 -0
  198. package/dist/ui/metadata.cjs +106 -0
  199. package/dist/ui/metadata.cjs.map +1 -0
  200. package/dist/ui/metadata.d.cts +35 -0
  201. package/dist/ui/metadata.d.cts.map +1 -0
  202. package/dist/ui/metadata.d.mts +35 -0
  203. package/dist/ui/metadata.d.mts.map +1 -0
  204. package/dist/ui/metadata.mjs +100 -0
  205. package/dist/ui/metadata.mjs.map +1 -0
  206. package/dist/ui/router.cjs +56 -0
  207. package/dist/ui/router.cjs.map +1 -0
  208. package/dist/ui/router.d.cts +11 -0
  209. package/dist/ui/router.d.cts.map +1 -0
  210. package/dist/ui/router.d.mts +11 -0
  211. package/dist/ui/router.d.mts.map +1 -0
  212. package/dist/ui/router.mjs +51 -0
  213. package/dist/ui/router.mjs.map +1 -0
  214. package/dist/ui/runtime.cjs +65 -0
  215. package/dist/ui/runtime.cjs.map +1 -0
  216. package/dist/ui/runtime.d.cts +29 -0
  217. package/dist/ui/runtime.d.cts.map +1 -0
  218. package/dist/ui/runtime.d.mts +29 -0
  219. package/dist/ui/runtime.d.mts.map +1 -0
  220. package/dist/ui/runtime.mjs +53 -0
  221. package/dist/ui/runtime.mjs.map +1 -0
  222. package/dist/ui/types.cjs +0 -0
  223. package/dist/ui/types.d.cts +52 -0
  224. package/dist/ui/types.d.cts.map +1 -0
  225. package/dist/ui/types.d.mts +52 -0
  226. package/dist/ui/types.d.mts.map +1 -0
  227. package/dist/ui/types.mjs +1 -0
  228. package/dist/utils/banner.cjs +24 -0
  229. package/dist/utils/banner.cjs.map +1 -0
  230. package/dist/utils/banner.mjs +23 -0
  231. package/dist/utils/banner.mjs.map +1 -0
  232. package/dist/utils/linkify.cjs +15 -0
  233. package/dist/utils/linkify.cjs.map +1 -0
  234. package/dist/utils/linkify.mjs +14 -0
  235. package/dist/utils/linkify.mjs.map +1 -0
  236. package/dist/utils/run.cjs +40 -0
  237. package/dist/utils/run.cjs.map +1 -0
  238. package/dist/utils/run.mjs +39 -0
  239. package/dist/utils/run.mjs.map +1 -0
  240. package/dist/utils/theme.cjs +44 -0
  241. package/dist/utils/theme.cjs.map +1 -0
  242. package/dist/utils/theme.mjs +37 -0
  243. package/dist/utils/theme.mjs.map +1 -0
  244. package/package.json +269 -80
  245. package/src/api-contract.ts +309 -0
  246. package/src/api.ts +181 -0
  247. package/src/app.ts +346 -0
  248. package/src/cli/catalog.ts +49 -0
  249. package/src/cli/help.ts +13 -0
  250. package/src/cli/init.ts +386 -0
  251. package/src/cli/parse.ts +130 -0
  252. package/src/cli/prompts.ts +64 -0
  253. package/src/cli.ts +203 -1507
  254. package/src/components/dev-view.tsx +307 -255
  255. package/src/components/streaming-view.ts +164 -128
  256. package/src/config.ts +462 -532
  257. package/src/contract.meta.ts +96 -0
  258. package/src/contract.ts +164 -561
  259. package/src/dev-logs.ts +85 -0
  260. package/src/dev-session.ts +318 -0
  261. package/src/fastkv.ts +153 -0
  262. package/src/federation.server.ts +43 -0
  263. package/src/host.ts +526 -0
  264. package/src/index.ts +6 -3
  265. package/src/integrity.ts +54 -0
  266. package/src/internal/manifest-normalizer.ts +251 -0
  267. package/src/mf.ts +105 -0
  268. package/src/near-cli.ts +284 -0
  269. package/src/network.ts +3 -0
  270. package/src/orchestrator.ts +648 -0
  271. package/src/plugin.ts +1130 -2311
  272. package/src/process-registry.ts +154 -0
  273. package/src/scripts/sync-api-contract.ts +24 -0
  274. package/src/sdk.ts +14 -0
  275. package/src/shared.ts +206 -0
  276. package/src/types.ts +152 -206
  277. package/src/ui/head.ts +34 -27
  278. package/src/ui/index.ts +3 -3
  279. package/src/ui/metadata.ts +95 -0
  280. package/src/ui/router.ts +22 -6
  281. package/src/ui/runtime.ts +55 -6
  282. package/src/ui/types.ts +24 -11
  283. package/src/utils/banner.ts +10 -6
  284. package/src/utils/run.ts +26 -27
  285. package/src/utils/theme.ts +3 -66
  286. package/src/components/monitor-view.tsx +0 -475
  287. package/src/components/status-view.tsx +0 -173
  288. package/src/lib/env.ts +0 -109
  289. package/src/lib/near-cli.ts +0 -289
  290. package/src/lib/nova.ts +0 -266
  291. package/src/lib/orchestrator.ts +0 -276
  292. package/src/lib/process-registry.ts +0 -166
  293. package/src/lib/process.ts +0 -550
  294. package/src/lib/resource-monitor/assertions.ts +0 -234
  295. package/src/lib/resource-monitor/command.ts +0 -283
  296. package/src/lib/resource-monitor/diff.ts +0 -157
  297. package/src/lib/resource-monitor/errors.ts +0 -127
  298. package/src/lib/resource-monitor/index.ts +0 -305
  299. package/src/lib/resource-monitor/platform/darwin.ts +0 -306
  300. package/src/lib/resource-monitor/platform/index.ts +0 -35
  301. package/src/lib/resource-monitor/platform/linux.ts +0 -332
  302. package/src/lib/resource-monitor/platform/windows.ts +0 -298
  303. package/src/lib/resource-monitor/snapshot.ts +0 -217
  304. package/src/lib/resource-monitor/types.ts +0 -74
  305. package/src/lib/session-recorder/errors.ts +0 -102
  306. package/src/lib/session-recorder/flows/login.ts +0 -210
  307. package/src/lib/session-recorder/index.ts +0 -361
  308. package/src/lib/session-recorder/playwright.ts +0 -257
  309. package/src/lib/session-recorder/report.ts +0 -353
  310. package/src/lib/session-recorder/server.ts +0 -268
  311. package/src/lib/session-recorder/types.ts +0 -115
  312. package/src/lib/sync.ts +0 -1
  313. package/src/ui/files.ts +0 -134
@@ -1,306 +0,0 @@
1
- import { Effect, Layer } from "effect";
2
- import { execShellSafe } from "../command";
3
- import type {
4
- MemoryInfo,
5
- PlatformOperations,
6
- PortInfo,
7
- ProcessInfo,
8
- } from "../types";
9
- import { PlatformService } from "../types";
10
-
11
- const parseLsofLine = (
12
- line: string,
13
- ports: number[]
14
- ): { port: number; pid: number; command: string } | null => {
15
- const parts = line.split(/\s+/);
16
- if (parts.length < 9) return null;
17
-
18
- const command = parts[0];
19
- const pid = parseInt(parts[1], 10);
20
- const nameCol = parts[8] || parts[7];
21
-
22
- const portMatch = nameCol.match(/:(\d+)$/);
23
- if (!portMatch) return null;
24
-
25
- const port = parseInt(portMatch[1], 10);
26
- if (!ports.includes(port)) return null;
27
-
28
- return { port, pid, command };
29
- };
30
-
31
- const getPortInfo = (
32
- ports: number[]
33
- ): Effect.Effect<Record<number, PortInfo>, never> =>
34
- Effect.gen(function* () {
35
- yield* Effect.logInfo(`[darwin] Checking ${ports.length} ports`);
36
-
37
- const result: Record<number, PortInfo> = {};
38
- for (const port of ports) {
39
- result[port] = { port, pid: null, command: null, state: "FREE" };
40
- }
41
-
42
- if (ports.length === 0) return result;
43
-
44
- const output = yield* execShellSafe(
45
- "lsof -i -P -n -sTCP:LISTEN 2>/dev/null || true"
46
- );
47
- if (!output) {
48
- yield* Effect.logDebug("[darwin] No lsof output, all ports appear free");
49
- return result;
50
- }
51
-
52
- const lines = output.split("\n").filter(Boolean);
53
- yield* Effect.logDebug(`[darwin] Parsing ${lines.length} lsof lines`);
54
-
55
- for (const line of lines.slice(1)) {
56
- const parsed = parseLsofLine(line, ports);
57
- if (parsed) {
58
- result[parsed.port] = {
59
- port: parsed.port,
60
- pid: parsed.pid,
61
- command: parsed.command,
62
- state: "LISTEN",
63
- };
64
- yield* Effect.logDebug(
65
- `[darwin] Port :${parsed.port} bound to PID ${parsed.pid} (${parsed.command})`
66
- );
67
- }
68
- }
69
-
70
- const boundCount = Object.values(result).filter(
71
- (p) => p.state === "LISTEN"
72
- ).length;
73
- yield* Effect.logInfo(
74
- `[darwin] Found ${boundCount}/${ports.length} ports in use`
75
- );
76
-
77
- return result;
78
- });
79
-
80
- const getProcessTree = (
81
- rootPids: number[]
82
- ): Effect.Effect<ProcessInfo[], never> =>
83
- Effect.gen(function* () {
84
- yield* Effect.logInfo(
85
- `[darwin] Building process tree for ${rootPids.length} root PIDs`
86
- );
87
-
88
- const processes: ProcessInfo[] = [];
89
- const visited = new Set<number>();
90
-
91
- const getProcess = (
92
- pid: number
93
- ): Effect.Effect<ProcessInfo | null, never> =>
94
- Effect.gen(function* () {
95
- if (visited.has(pid)) return null;
96
- visited.add(pid);
97
-
98
- const output = yield* execShellSafe(
99
- `ps -p ${pid} -o pid=,ppid=,rss=,comm=,args= 2>/dev/null || true`
100
- );
101
- if (!output) return null;
102
-
103
- const parts = output.trim().split(/\s+/);
104
- if (parts.length < 4) return null;
105
-
106
- const [pidStr, ppidStr, rssStr, ...rest] = parts;
107
- const command = rest[0] || "";
108
- const args = rest.slice(1);
109
-
110
- yield* Effect.logDebug(
111
- `[darwin] Process ${pid}: ${command} (RSS: ${rssStr}KB)`
112
- );
113
-
114
- return {
115
- pid: parseInt(pidStr, 10),
116
- ppid: parseInt(ppidStr, 10),
117
- command,
118
- args,
119
- rss: parseInt(rssStr, 10) * 1024,
120
- children: [],
121
- };
122
- });
123
-
124
- const getChildren = (pid: number): Effect.Effect<number[], never> =>
125
- Effect.gen(function* () {
126
- const output = yield* execShellSafe(
127
- `pgrep -P ${pid} 2>/dev/null || true`
128
- );
129
- if (!output) return [];
130
-
131
- const children = output
132
- .split("\n")
133
- .filter(Boolean)
134
- .map((s) => parseInt(s, 10))
135
- .filter((n) => !isNaN(n));
136
-
137
- if (children.length > 0) {
138
- yield* Effect.logDebug(
139
- `[darwin] PID ${pid} has ${children.length} children: ${children.join(", ")}`
140
- );
141
- }
142
-
143
- return children;
144
- });
145
-
146
- const traverse = (pid: number): Effect.Effect<void, never> =>
147
- Effect.gen(function* () {
148
- const proc = yield* getProcess(pid);
149
- if (!proc) return;
150
-
151
- const children = yield* getChildren(pid);
152
- proc.children = children;
153
- processes.push(proc);
154
-
155
- for (const child of children) {
156
- yield* traverse(child);
157
- }
158
- });
159
-
160
- for (const pid of rootPids) {
161
- yield* traverse(pid);
162
- }
163
-
164
- yield* Effect.logInfo(
165
- `[darwin] Process tree contains ${processes.length} processes`
166
- );
167
-
168
- return processes;
169
- });
170
-
171
- const getMemoryInfo = (): Effect.Effect<MemoryInfo, never> =>
172
- Effect.gen(function* () {
173
- yield* Effect.logDebug("[darwin] Getting memory info");
174
-
175
- const sysctlMem = yield* execShellSafe(
176
- "sysctl -n hw.memsize 2>/dev/null || echo 0"
177
- );
178
- const total = parseInt(sysctlMem, 10) || 16 * 1024 * 1024 * 1024;
179
-
180
- const pageSizeOutput = yield* execShellSafe(
181
- "sysctl -n hw.pagesize 2>/dev/null || echo 16384"
182
- );
183
- const pageSize = parseInt(pageSizeOutput.trim(), 10) || 16384;
184
-
185
- const vmStat = yield* execShellSafe("vm_stat 2>/dev/null || true");
186
-
187
- let freePages = 0;
188
- let activePages = 0;
189
- let inactivePages = 0;
190
- let wiredPages = 0;
191
- let speculativePages = 0;
192
-
193
- for (const line of vmStat.split("\n")) {
194
- const match = line.match(/^(.+?):\s+(\d+)/);
195
- if (!match) continue;
196
-
197
- const [, key, value] = match;
198
- const pages = parseInt(value, 10);
199
-
200
- if (key.includes("Pages free")) freePages = pages;
201
- else if (key.includes("Pages active")) activePages = pages;
202
- else if (key.includes("Pages inactive")) inactivePages = pages;
203
- else if (key.includes("Pages wired")) wiredPages = pages;
204
- else if (key.includes("Pages speculative")) speculativePages = pages;
205
- }
206
-
207
- const free = freePages * pageSize;
208
- const active = activePages * pageSize;
209
- const inactive = inactivePages * pageSize;
210
- const wired = wiredPages * pageSize;
211
- const speculative = speculativePages * pageSize;
212
-
213
- const used = active + inactive + wired + speculative;
214
-
215
- const effectiveFree = free > 0 ? free : Math.max(0, total - used);
216
-
217
- const totalMB = (total / 1024 / 1024).toFixed(0);
218
- const usedMB = (used / 1024 / 1024).toFixed(0);
219
- const freeMB = (effectiveFree / 1024 / 1024).toFixed(0);
220
- yield* Effect.logDebug(
221
- `[darwin] Memory: ${usedMB}MB used / ${freeMB}MB free / ${totalMB}MB total`
222
- );
223
-
224
- return {
225
- total,
226
- used,
227
- free: effectiveFree,
228
- processRss: 0,
229
- };
230
- });
231
-
232
- const getAllProcesses = (): Effect.Effect<ProcessInfo[], never> =>
233
- Effect.gen(function* () {
234
- yield* Effect.logDebug("[darwin] Getting all processes");
235
-
236
- const processes: ProcessInfo[] = [];
237
-
238
- const output = yield* execShellSafe(
239
- "ps -axo pid=,ppid=,rss=,comm= 2>/dev/null || true"
240
- );
241
- for (const line of output.split("\n").filter(Boolean)) {
242
- const parts = line.trim().split(/\s+/);
243
- if (parts.length < 4) continue;
244
-
245
- const [pidStr, ppidStr, rssStr, ...rest] = parts;
246
- processes.push({
247
- pid: parseInt(pidStr, 10),
248
- ppid: parseInt(ppidStr, 10),
249
- command: rest.join(" "),
250
- args: [],
251
- rss: parseInt(rssStr, 10) * 1024,
252
- children: [],
253
- });
254
- }
255
-
256
- yield* Effect.logDebug(`[darwin] Found ${processes.length} total processes`);
257
-
258
- return processes;
259
- });
260
-
261
- const findChildProcesses = (pid: number): Effect.Effect<number[], never> =>
262
- Effect.gen(function* () {
263
- yield* Effect.logDebug(`[darwin] Finding all children of PID ${pid}`);
264
-
265
- const children: number[] = [];
266
- const visited = new Set<number>();
267
-
268
- const recurse = (parentPid: number): Effect.Effect<void, never> =>
269
- Effect.gen(function* () {
270
- if (visited.has(parentPid)) return;
271
- visited.add(parentPid);
272
-
273
- const output = yield* execShellSafe(
274
- `pgrep -P ${parentPid} 2>/dev/null || true`
275
- );
276
- if (!output) return;
277
-
278
- for (const line of output.split("\n").filter(Boolean)) {
279
- const childPid = parseInt(line, 10);
280
- if (!isNaN(childPid)) {
281
- children.push(childPid);
282
- yield* recurse(childPid);
283
- }
284
- }
285
- });
286
-
287
- yield* recurse(pid);
288
-
289
- if (children.length > 0) {
290
- yield* Effect.logDebug(
291
- `[darwin] PID ${pid} has ${children.length} descendants`
292
- );
293
- }
294
-
295
- return children;
296
- });
297
-
298
- const darwinOperations: PlatformOperations = {
299
- getPortInfo,
300
- getProcessTree,
301
- getMemoryInfo,
302
- getAllProcesses,
303
- findChildProcesses,
304
- };
305
-
306
- export const DarwinLayer = Layer.succeed(PlatformService, darwinOperations);
@@ -1,35 +0,0 @@
1
- import { Effect, Layer } from "effect";
2
- import { PlatformService } from "../types";
3
- import { DarwinLayer } from "./darwin";
4
- import { LinuxLayer } from "./linux";
5
- import { WindowsLayer } from "./windows";
6
-
7
- export const makePlatformLayer = (): Layer.Layer<PlatformService> => {
8
- const platform = process.platform;
9
-
10
- switch (platform) {
11
- case "darwin":
12
- return DarwinLayer;
13
- case "linux":
14
- return LinuxLayer;
15
- case "win32":
16
- return WindowsLayer;
17
- default:
18
- console.warn(`Unsupported platform: ${platform}, falling back to linux`);
19
- return LinuxLayer;
20
- }
21
- };
22
-
23
- export const PlatformLive = makePlatformLayer();
24
-
25
- export const withPlatform = <A, E, R>(
26
- effect: Effect.Effect<A, E, R | PlatformService>
27
- ): Effect.Effect<A, E, Exclude<R, PlatformService>> =>
28
- effect.pipe(Effect.provide(PlatformLive)) as Effect.Effect<
29
- A,
30
- E,
31
- Exclude<R, PlatformService>
32
- >;
33
-
34
- export { DarwinLayer, LinuxLayer, WindowsLayer };
35
- export { PlatformService };
@@ -1,332 +0,0 @@
1
- import { Effect, Layer } from "effect";
2
- import { readFile } from "node:fs/promises";
3
- import { execShellSafe } from "../command";
4
- import type {
5
- MemoryInfo,
6
- PlatformOperations,
7
- PortInfo,
8
- ProcessInfo,
9
- } from "../types";
10
- import { PlatformService } from "../types";
11
-
12
- const readFileSafe = (path: string): Effect.Effect<string | null, never> =>
13
- Effect.tryPromise({
14
- try: () => readFile(path, "utf-8"),
15
- catch: () => new Error("file not found"),
16
- }).pipe(
17
- Effect.catchAll(() => Effect.succeed(null))
18
- );
19
-
20
- const getPortInfo = (
21
- ports: number[]
22
- ): Effect.Effect<Record<number, PortInfo>, never> =>
23
- Effect.gen(function* () {
24
- yield* Effect.logInfo(`[linux] Checking ${ports.length} ports`);
25
-
26
- const result: Record<number, PortInfo> = {};
27
- for (const port of ports) {
28
- result[port] = { port, pid: null, command: null, state: "FREE" };
29
- }
30
-
31
- if (ports.length === 0) return result;
32
-
33
- const output = yield* execShellSafe(
34
- "ss -tlnp 2>/dev/null || netstat -tlnp 2>/dev/null || true"
35
- );
36
- if (!output) {
37
- yield* Effect.logDebug("[linux] No ss/netstat output, all ports appear free");
38
- return result;
39
- }
40
-
41
- const lines = output.split("\n").filter(Boolean);
42
- yield* Effect.logDebug(`[linux] Parsing ${lines.length} ss/netstat lines`);
43
-
44
- for (const line of lines) {
45
- const portMatch = line.match(/:(\d+)\s/);
46
- if (!portMatch) continue;
47
-
48
- const port = parseInt(portMatch[1], 10);
49
- if (!ports.includes(port)) continue;
50
-
51
- const pidMatch = line.match(/pid=(\d+)/);
52
- const pid = pidMatch ? parseInt(pidMatch[1], 10) : null;
53
-
54
- let command: string | null = null;
55
- if (pid) {
56
- const commContent = yield* readFileSafe(`/proc/${pid}/comm`);
57
- command = commContent?.trim() ?? null;
58
- }
59
-
60
- result[port] = {
61
- port,
62
- pid,
63
- command,
64
- state: "LISTEN",
65
- };
66
-
67
- yield* Effect.logDebug(
68
- `[linux] Port :${port} bound to PID ${pid} (${command})`
69
- );
70
- }
71
-
72
- const boundCount = Object.values(result).filter(
73
- (p) => p.state === "LISTEN"
74
- ).length;
75
- yield* Effect.logInfo(
76
- `[linux] Found ${boundCount}/${ports.length} ports in use`
77
- );
78
-
79
- return result;
80
- });
81
-
82
- const getProcessTree = (
83
- rootPids: number[]
84
- ): Effect.Effect<ProcessInfo[], never> =>
85
- Effect.gen(function* () {
86
- yield* Effect.logInfo(
87
- `[linux] Building process tree for ${rootPids.length} root PIDs`
88
- );
89
-
90
- const processes: ProcessInfo[] = [];
91
- const visited = new Set<number>();
92
-
93
- const getProcess = (
94
- pid: number
95
- ): Effect.Effect<ProcessInfo | null, never> =>
96
- Effect.gen(function* () {
97
- if (visited.has(pid)) return null;
98
- visited.add(pid);
99
-
100
- const stat = yield* readFileSafe(`/proc/${pid}/stat`);
101
- const status = yield* readFileSafe(`/proc/${pid}/status`);
102
- const cmdline = yield* readFileSafe(`/proc/${pid}/cmdline`);
103
-
104
- if (!stat || !status) return null;
105
-
106
- const statParts = stat.split(" ");
107
- const ppid = parseInt(statParts[3], 10);
108
-
109
- let rss = 0;
110
- for (const line of status.split("\n")) {
111
- if (line.startsWith("VmRSS:")) {
112
- const match = line.match(/(\d+)/);
113
- if (match) rss = parseInt(match[1], 10) * 1024;
114
- break;
115
- }
116
- }
117
-
118
- const args = cmdline?.split("\0").filter(Boolean) ?? [];
119
- const command = args[0] || statParts[1].replace(/[()]/g, "");
120
-
121
- yield* Effect.logDebug(
122
- `[linux] Process ${pid}: ${command} (RSS: ${(rss / 1024).toFixed(0)}KB)`
123
- );
124
-
125
- return {
126
- pid,
127
- ppid,
128
- command,
129
- args: args.slice(1),
130
- rss,
131
- children: [],
132
- };
133
- });
134
-
135
- const getChildren = (pid: number): Effect.Effect<number[], never> =>
136
- Effect.gen(function* () {
137
- const childrenFile = yield* readFileSafe(
138
- `/proc/${pid}/task/${pid}/children`
139
- );
140
-
141
- if (childrenFile) {
142
- const children = childrenFile
143
- .trim()
144
- .split(/\s+/)
145
- .filter(Boolean)
146
- .map((s) => parseInt(s, 10));
147
-
148
- if (children.length > 0) {
149
- yield* Effect.logDebug(
150
- `[linux] PID ${pid} has ${children.length} children: ${children.join(", ")}`
151
- );
152
- }
153
-
154
- return children;
155
- }
156
-
157
- const output = yield* execShellSafe(
158
- `pgrep -P ${pid} 2>/dev/null || true`
159
- );
160
- if (!output) return [];
161
-
162
- const children = output
163
- .split("\n")
164
- .filter(Boolean)
165
- .map((s) => parseInt(s, 10));
166
-
167
- if (children.length > 0) {
168
- yield* Effect.logDebug(
169
- `[linux] PID ${pid} has ${children.length} children (via pgrep)`
170
- );
171
- }
172
-
173
- return children;
174
- });
175
-
176
- const traverse = (pid: number): Effect.Effect<void, never> =>
177
- Effect.gen(function* () {
178
- const proc = yield* getProcess(pid);
179
- if (!proc) return;
180
-
181
- const children = yield* getChildren(pid);
182
- proc.children = children;
183
- processes.push(proc);
184
-
185
- for (const child of children) {
186
- yield* traverse(child);
187
- }
188
- });
189
-
190
- for (const pid of rootPids) {
191
- yield* traverse(pid);
192
- }
193
-
194
- yield* Effect.logInfo(
195
- `[linux] Process tree contains ${processes.length} processes`
196
- );
197
-
198
- return processes;
199
- });
200
-
201
- const getMemoryInfo = (): Effect.Effect<MemoryInfo, never> =>
202
- Effect.gen(function* () {
203
- yield* Effect.logDebug("[linux] Getting memory info");
204
-
205
- const meminfo = yield* readFileSafe("/proc/meminfo");
206
-
207
- if (!meminfo) {
208
- yield* Effect.logWarning("[linux] Could not read /proc/meminfo");
209
- return { total: 0, used: 0, free: 0, processRss: 0 };
210
- }
211
-
212
- let total = 0;
213
- let free = 0;
214
- let available = 0;
215
-
216
- for (const line of meminfo.split("\n")) {
217
- const [key, value] = line.split(":");
218
- if (!value) continue;
219
-
220
- const kb = parseInt(value.trim().split(/\s+/)[0], 10) * 1024;
221
-
222
- if (key === "MemTotal") total = kb;
223
- else if (key === "MemFree") free = kb;
224
- else if (key === "MemAvailable") available = kb;
225
- }
226
-
227
- const totalMB = (total / 1024 / 1024).toFixed(0);
228
- const usedMB = ((total - (available || free)) / 1024 / 1024).toFixed(0);
229
- yield* Effect.logDebug(
230
- `[linux] Memory: ${usedMB}MB used / ${totalMB}MB total`
231
- );
232
-
233
- return {
234
- total,
235
- used: total - (available || free),
236
- free: available || free,
237
- processRss: 0,
238
- };
239
- });
240
-
241
- const getAllProcesses = (): Effect.Effect<ProcessInfo[], never> =>
242
- Effect.gen(function* () {
243
- yield* Effect.logDebug("[linux] Getting all processes");
244
-
245
- const processes: ProcessInfo[] = [];
246
-
247
- const output = yield* execShellSafe(
248
- "ps -eo pid=,ppid=,rss=,comm= 2>/dev/null || true"
249
- );
250
- for (const line of output.split("\n").filter(Boolean)) {
251
- const parts = line.trim().split(/\s+/);
252
- if (parts.length < 4) continue;
253
-
254
- const [pidStr, ppidStr, rssStr, ...rest] = parts;
255
- processes.push({
256
- pid: parseInt(pidStr, 10),
257
- ppid: parseInt(ppidStr, 10),
258
- command: rest.join(" "),
259
- args: [],
260
- rss: parseInt(rssStr, 10) * 1024,
261
- children: [],
262
- });
263
- }
264
-
265
- yield* Effect.logDebug(`[linux] Found ${processes.length} total processes`);
266
-
267
- return processes;
268
- });
269
-
270
- const findChildProcesses = (pid: number): Effect.Effect<number[], never> =>
271
- Effect.gen(function* () {
272
- yield* Effect.logDebug(`[linux] Finding all children of PID ${pid}`);
273
-
274
- const children: number[] = [];
275
- const visited = new Set<number>();
276
-
277
- const recurse = (parentPid: number): Effect.Effect<void, never> =>
278
- Effect.gen(function* () {
279
- if (visited.has(parentPid)) return;
280
- visited.add(parentPid);
281
-
282
- const childrenFile = yield* readFileSafe(
283
- `/proc/${parentPid}/task/${parentPid}/children`
284
- );
285
-
286
- let childPids: number[] = [];
287
- if (childrenFile) {
288
- childPids = childrenFile
289
- .trim()
290
- .split(/\s+/)
291
- .filter(Boolean)
292
- .map((s) => parseInt(s, 10));
293
- } else {
294
- const output = yield* execShellSafe(
295
- `pgrep -P ${parentPid} 2>/dev/null || true`
296
- );
297
- if (output) {
298
- childPids = output
299
- .split("\n")
300
- .filter(Boolean)
301
- .map((s) => parseInt(s, 10));
302
- }
303
- }
304
-
305
- for (const childPid of childPids) {
306
- if (!isNaN(childPid)) {
307
- children.push(childPid);
308
- yield* recurse(childPid);
309
- }
310
- }
311
- });
312
-
313
- yield* recurse(pid);
314
-
315
- if (children.length > 0) {
316
- yield* Effect.logDebug(
317
- `[linux] PID ${pid} has ${children.length} descendants`
318
- );
319
- }
320
-
321
- return children;
322
- });
323
-
324
- const linuxOperations: PlatformOperations = {
325
- getPortInfo,
326
- getProcessTree,
327
- getMemoryInfo,
328
- getAllProcesses,
329
- findChildProcesses,
330
- };
331
-
332
- export const LinuxLayer = Layer.succeed(PlatformService, linuxOperations);