@myrialabs/clopen 0.4.33 → 0.4.34

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 (36) hide show
  1. package/backend/auth/permissions.ts +3 -0
  2. package/backend/auth/rate-limiter.test.ts +115 -0
  3. package/backend/auth/rate-limiter.ts +25 -12
  4. package/backend/db-client/connection-manager.ts +13 -0
  5. package/backend/index.ts +9 -0
  6. package/backend/middleware/security.test.ts +95 -0
  7. package/backend/middleware/security.ts +114 -0
  8. package/backend/ports/attribute.test.ts +231 -0
  9. package/backend/ports/attribute.ts +444 -0
  10. package/backend/ports/kill.ts +203 -0
  11. package/backend/ports/monitor.ts +365 -0
  12. package/backend/ports/processes.test.ts +98 -0
  13. package/backend/ports/processes.ts +374 -0
  14. package/backend/ports/registry.ts +165 -0
  15. package/backend/ports/runner.ts +195 -0
  16. package/backend/ports/scan-host.ts +260 -0
  17. package/backend/ports/scan.test.ts +341 -0
  18. package/backend/ports/scan.ts +687 -0
  19. package/backend/ports/ssh-lineage.ts +318 -0
  20. package/backend/ssh/forwards.ts +31 -0
  21. package/backend/ws/auth/device.ts +1 -1
  22. package/backend/ws/auth/login.ts +8 -4
  23. package/backend/ws/index.ts +2 -0
  24. package/backend/ws/ports/index.ts +19 -0
  25. package/backend/ws/ports/kill.ts +80 -0
  26. package/backend/ws/ports/list.ts +60 -0
  27. package/dist/assets/{index-BW0DA8NV.js → index-gGTMFUa8.js} +1 -1
  28. package/dist/assets/{index-BF4buYmI.js → index-vW2RpdHu.js} +1 -1
  29. package/dist/assets/main-CYCMEbXB.css +1 -0
  30. package/dist/assets/{main-BbwWLJRN.js → main-ZCojSzvW.js} +409 -406
  31. package/dist/index.html +2 -2
  32. package/package.json +1 -1
  33. package/shared/types/ports/index.ts +5 -0
  34. package/shared/types/ports/port.ts +192 -0
  35. package/shared/utils/logger.ts +1 -0
  36. package/dist/assets/main-CCvRMXlP.css +0 -1
package/dist/index.html CHANGED
@@ -58,8 +58,8 @@
58
58
  }
59
59
  })();
60
60
  </script>
61
- <script type="module" crossorigin src="/assets/main-BbwWLJRN.js"></script>
62
- <link rel="stylesheet" crossorigin href="/assets/main-CCvRMXlP.css">
61
+ <script type="module" crossorigin src="/assets/main-ZCojSzvW.js"></script>
62
+ <link rel="stylesheet" crossorigin href="/assets/main-CYCMEbXB.css">
63
63
  </head>
64
64
  <body
65
65
  class="min-h-dvh bg-white text-slate-900 dark:bg-slate-950 dark:text-slate-100 transition-colors duration-200"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@myrialabs/clopen",
3
- "version": "0.4.33",
3
+ "version": "0.4.34",
4
4
  "description": "All-in-one web workspace for AI coding agents — Claude Code, OpenCode, Codex, Copilot, Qwen Code, Pi, Cline, and Cursor — with chat, terminal, git, browser preview, database client, checkpoints, and real-time collaboration",
5
5
  "author": "Myria Labs",
6
6
  "license": "MIT",
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Port manager types barrel export.
3
+ */
4
+
5
+ export * from './port';
@@ -0,0 +1,192 @@
1
+ /**
2
+ * Port manager — the shape of "what is listening, and who opened it".
3
+ *
4
+ * One model serves both the machine running Clopen and any saved SSH host, so
5
+ * the same table, the same attribution and the same detail pane render either.
6
+ * Where a platform cannot answer a question the field is `null` and the reason
7
+ * is reported in `limitations` — a port with an unknown owner says so rather
8
+ * than guessing.
9
+ */
10
+
11
+ export type PortProtocol = 'tcp' | 'udp';
12
+
13
+ export type PortIpVersion = 'v4' | 'v6';
14
+
15
+ /**
16
+ * Only the three states worth acting on. Everything transient (TIME_WAIT,
17
+ * SYN_SENT, the rest of the TCP state machine) collapses into `other` — it
18
+ * describes a socket that is closing, not a port anyone owns.
19
+ */
20
+ export type PortSocketState = 'listen' | 'established' | 'other';
21
+
22
+ /** A socket row exactly as the OS probe reported it, before any attribution. */
23
+ export interface PortSocket {
24
+ protocol: PortProtocol;
25
+ ipVersion: PortIpVersion;
26
+ /** Local bind address. `*` means every interface. */
27
+ address: string;
28
+ port: number;
29
+ state: PortSocketState;
30
+ /** Null when the probe could not see the owner — see `PortLimitationCode`. */
31
+ pid: number | null;
32
+ /** Short on Linux `ss`, full path on macOS `lsof`, absent on Windows netstat. */
33
+ processName: string | null;
34
+ user: string | null;
35
+ peerAddress: string | null;
36
+ peerPort: number | null;
37
+ }
38
+
39
+ /** Process facts behind a socket, resolved once per pid and cached. */
40
+ export interface PortProcess {
41
+ pid: number;
42
+ parentPid: number | null;
43
+ user: string | null;
44
+ /** Full argv when the platform exposes it, else the executable name. */
45
+ command: string;
46
+ /** ISO timestamp. Also disambiguates a reused pid from the cached one. */
47
+ startedAt: string | null;
48
+ /**
49
+ * Working directory — the strongest hint at *which project* a dev server
50
+ * belongs to. Unavailable on Windows, and on Unix only for our own user.
51
+ */
52
+ cwd: string | null;
53
+ }
54
+
55
+ /**
56
+ * How confident the attribution is. `certain` means Clopen either opened the
57
+ * listener itself or watched the process being born; `guess` means the label
58
+ * was inferred from the command line and may be wrong.
59
+ */
60
+ export type PortOriginConfidence = 'certain' | 'guess';
61
+
62
+ /**
63
+ * The three tiers the UI groups by:
64
+ * - `clopen` — a listener Clopen opened, registered by the feature that owns it
65
+ * - `session` — a process descended from a Clopen terminal session
66
+ * - `external` — everything else on the machine
67
+ */
68
+ export type PortOriginKind = 'clopen' | 'session' | 'external';
69
+
70
+ /** Which Clopen feature owns a `clopen` port, so it can be stopped properly. */
71
+ export type PortOwnerFeature =
72
+ | 'server'
73
+ | 'tunnel'
74
+ | 'ssh-forward'
75
+ | 'db-client-tunnel'
76
+ | 'preview-browser'
77
+ | 'mcp'
78
+ | 'engine';
79
+
80
+ export interface PortOrigin {
81
+ kind: PortOriginKind;
82
+ confidence: PortOriginConfidence;
83
+ /** Short human label, e.g. "Clopen server" or "Vite dev server". */
84
+ label: string;
85
+ /** Second line: the host being forwarded to, the project, the raw command. */
86
+ detail: string | null;
87
+ /** Set when `kind` is `clopen`. */
88
+ ownerFeature?: PortOwnerFeature;
89
+ /** Identifies the owning record (forward id, tunnel id, …) for the stop path. */
90
+ ownerId?: string;
91
+ /** Set when `kind` is `session` — the PTY session the process descends from. */
92
+ sessionId?: string;
93
+ /** Project the session belongs to, so the UI can name it. */
94
+ projectId?: string;
95
+ /** Set when the lineage ends at an sshd session rather than a Clopen one. */
96
+ remoteSessionUser?: string;
97
+ }
98
+
99
+ /** A peer currently connected to a listening port. */
100
+ export interface PortPeer {
101
+ address: string;
102
+ port: number;
103
+ /** Present when the probe could attribute the peer socket to a process. */
104
+ processName: string | null;
105
+ }
106
+
107
+ /** Why a port cannot be stopped from here. */
108
+ export type PortKillBlockedReason =
109
+ | 'is-clopen-itself'
110
+ | 'unknown-pid'
111
+ | 'not-permitted'
112
+ | 'system-process';
113
+
114
+ /** One row in the table: a port, its owner, and what is connected to it. */
115
+ export interface PortEntry {
116
+ /** Stable across scans, so the UI can diff without rebuilding the table. */
117
+ key: string;
118
+ protocol: PortProtocol;
119
+ port: number;
120
+ /** Every address this pid binds the port on, e.g. `127.0.0.1` and `::1`. */
121
+ addresses: string[];
122
+ ipVersions: PortIpVersion[];
123
+ pid: number | null;
124
+ process: PortProcess | null;
125
+ /**
126
+ * Every process holding this port, when a server pre-forks workers that
127
+ * inherit the listening socket. One row is reported for the group, and this
128
+ * says how wide the group is.
129
+ */
130
+ workerPids: number[];
131
+ origin: PortOrigin;
132
+ peers: PortPeer[];
133
+ peerCount: number;
134
+ /**
135
+ * Set when a Cloudflare tunnel points at this port. A tunnel dials the port
136
+ * rather than binding it, so this is exposure, not ownership — the port
137
+ * still belongs to whatever process is listening, and this says it is also
138
+ * reachable from the public internet.
139
+ */
140
+ publicUrl: string | null;
141
+ canKill: boolean;
142
+ killBlockedReason: PortKillBlockedReason | null;
143
+ }
144
+
145
+ /**
146
+ * A capability the scan could not deliver on this host. Surfaced in the UI so
147
+ * a missing owner reads as "this platform cannot tell us" rather than a bug.
148
+ */
149
+ export type PortLimitationCode =
150
+ | 'pids-need-root'
151
+ | 'no-cwd-support'
152
+ | 'no-process-args'
153
+ | 'no-session-attribution'
154
+ | 'probe-fallback';
155
+
156
+ export interface PortLimitation {
157
+ code: PortLimitationCode;
158
+ message: string;
159
+ }
160
+
161
+ /** `local` is the machine running Clopen; any other id is an SSH connection. */
162
+ export type PortHostId = string;
163
+
164
+ export const LOCAL_PORT_HOST: PortHostId = 'local';
165
+
166
+ export interface PortScanResult {
167
+ hostId: PortHostId;
168
+ /** ISO timestamp of the scan that produced these entries. */
169
+ scannedAt: string;
170
+ platform: string;
171
+ /**
172
+ * Which probe actually read the socket table. Reported because how much a
173
+ * row can say depends entirely on this — `netstat` on Windows names no
174
+ * process, `/proc/net` needs a second lookup for one — and because a host
175
+ * that answers with less than expected is otherwise impossible to explain.
176
+ */
177
+ probe: string;
178
+ entries: PortEntry[];
179
+ limitations: PortLimitation[];
180
+ /** Set when the scan failed outright; `entries` is then empty. */
181
+ error: string | null;
182
+ }
183
+
184
+ /** What a kill attempt did, reported honestly including refusals. */
185
+ export interface PortKillResult {
186
+ ok: boolean;
187
+ /** Pids actually signalled, children first. */
188
+ killedPids: number[];
189
+ /** Set when the port belonged to a feature and was stopped, not signalled. */
190
+ stoppedFeature: PortOwnerFeature | null;
191
+ error: string | null;
192
+ }
@@ -47,6 +47,7 @@ export type LogLabel =
47
47
  | 'remote-access'
48
48
  | 'db-client'
49
49
  | 'ssh'
50
+ | 'ports'
50
51
 
51
52
  // User
52
53
  | 'user'