@myrialabs/clopen 0.4.33 → 0.4.35
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.
- package/backend/auth/permissions.ts +10 -0
- package/backend/auth/rate-limiter.test.ts +115 -0
- package/backend/auth/rate-limiter.ts +25 -12
- package/backend/containers/actions.ts +316 -0
- package/backend/containers/disk-usage.test.ts +68 -0
- package/backend/containers/disk-usage.ts +170 -0
- package/backend/containers/logs.ts +335 -0
- package/backend/containers/monitor.ts +410 -0
- package/backend/containers/parse.test.ts +599 -0
- package/backend/containers/parse.ts +905 -0
- package/backend/containers/port-index.test.ts +91 -0
- package/backend/containers/port-index.ts +198 -0
- package/backend/containers/prune-job.test.ts +148 -0
- package/backend/containers/prune-job.ts +129 -0
- package/backend/containers/pty-backend.ts +337 -0
- package/backend/containers/pty.ts +114 -0
- package/backend/containers/runtime.ts +218 -0
- package/backend/containers/scan.ts +293 -0
- package/backend/db-client/connection-manager.ts +13 -0
- package/backend/files/file-watcher.test.ts +105 -0
- package/backend/files/file-watcher.ts +45 -1
- package/backend/git/git-service.test.ts +33 -0
- package/backend/git/git-service.ts +7 -3
- package/backend/git/nested-repos.test.ts +292 -1
- package/backend/git/nested-repos.ts +330 -17
- package/backend/host/runner.ts +204 -0
- package/backend/index.ts +20 -2
- package/backend/middleware/security.test.ts +95 -0
- package/backend/middleware/security.ts +114 -0
- package/backend/ports/attribute.test.ts +231 -0
- package/backend/ports/attribute.ts +444 -0
- package/backend/ports/kill.ts +203 -0
- package/backend/ports/monitor.ts +365 -0
- package/backend/ports/processes.test.ts +98 -0
- package/backend/ports/processes.ts +374 -0
- package/backend/ports/registry.ts +165 -0
- package/backend/ports/scan-host.ts +329 -0
- package/backend/ports/scan.test.ts +341 -0
- package/backend/ports/scan.ts +687 -0
- package/backend/ports/ssh-lineage.ts +318 -0
- package/backend/preview/browser/browser-video-capture.ts +84 -31
- package/backend/ssh/forwards.ts +31 -0
- package/backend/ws/auth/device.ts +1 -1
- package/backend/ws/auth/login.ts +8 -4
- package/backend/ws/containers/actions.ts +156 -0
- package/backend/ws/containers/index.ts +43 -0
- package/backend/ws/containers/list.ts +146 -0
- package/backend/ws/containers/logs.ts +43 -0
- package/backend/ws/containers/tunnel.ts +101 -0
- package/backend/ws/git/log.ts +3 -1
- package/backend/ws/git/status.ts +37 -27
- package/backend/ws/index.ts +4 -0
- package/backend/ws/message-rate-limiter.test.ts +45 -0
- package/backend/ws/message-rate-limiter.ts +34 -3
- package/backend/ws/ports/index.ts +19 -0
- package/backend/ws/ports/kill.ts +80 -0
- package/backend/ws/ports/list.ts +60 -0
- package/backend/ws/ssh/connections.ts +8 -0
- package/backend/ws/system/device-info.ts +99 -43
- package/dist/assets/{index-BF4buYmI.js → index-B0iIhSO9.js} +1 -1
- package/dist/assets/{index-BW0DA8NV.js → index-BRJqss6F.js} +1 -1
- package/dist/assets/main-Buko4D0t.css +1 -0
- package/dist/assets/{main-BbwWLJRN.js → main-C_iGUZyL.js} +468 -447
- package/dist/index.html +2 -2
- package/dist/manifest.json +9 -2
- package/package.json +1 -1
- package/shared/types/containers/container.ts +366 -0
- package/shared/types/containers/index.ts +5 -0
- package/shared/types/host/index.ts +18 -0
- package/shared/types/ports/index.ts +5 -0
- package/shared/types/ports/port.ts +230 -0
- package/shared/utils/logger.ts +3 -0
- package/shared/utils/ws-client.ts +67 -12
- package/shared/utils/ws-server.ts +64 -13
- 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-
|
|
62
|
-
<link rel="stylesheet" crossorigin href="/assets/main-
|
|
61
|
+
<script type="module" crossorigin src="/assets/main-C_iGUZyL.js"></script>
|
|
62
|
+
<link rel="stylesheet" crossorigin href="/assets/main-Buko4D0t.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/dist/manifest.json
CHANGED
|
@@ -1,16 +1,23 @@
|
|
|
1
1
|
{
|
|
2
|
+
"id": "/",
|
|
2
3
|
"name": "Clopen",
|
|
3
4
|
"short_name": "Clopen",
|
|
4
|
-
"description": "All-in-one web workspace for Claude Code
|
|
5
|
+
"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
6
|
"start_url": "/",
|
|
7
|
+
"scope": "/",
|
|
8
|
+
"lang": "en",
|
|
9
|
+
"dir": "ltr",
|
|
6
10
|
"display": "standalone",
|
|
11
|
+
"orientation": "any",
|
|
12
|
+
"categories": ["developer", "productivity", "utilities"],
|
|
7
13
|
"background_color": "#0e172b",
|
|
8
14
|
"theme_color": "#0e172b",
|
|
9
15
|
"icons": [
|
|
10
16
|
{
|
|
11
17
|
"src": "/favicon.svg",
|
|
12
18
|
"sizes": "any",
|
|
13
|
-
"type": "image/svg+xml"
|
|
19
|
+
"type": "image/svg+xml",
|
|
20
|
+
"purpose": "any"
|
|
14
21
|
}
|
|
15
22
|
]
|
|
16
23
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@myrialabs/clopen",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.35",
|
|
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,366 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Containers — the shape of "what is running on this host, and how to reach it".
|
|
3
|
+
*
|
|
4
|
+
* One model serves the machine Clopen runs on and any saved SSH host, so the
|
|
5
|
+
* same table, detail pane, log view and shell render either. Docker and Podman
|
|
6
|
+
* answer the same questions in slightly different words; the differences are
|
|
7
|
+
* flattened here rather than pushed into the UI, and anything a runtime cannot
|
|
8
|
+
* report is `null` with the reason carried in `limitations` — never a guess
|
|
9
|
+
* dressed as a fact.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { LOCAL_HOST_ID, type HostId } from '../host';
|
|
13
|
+
|
|
14
|
+
/** The runtimes Clopen knows how to drive. Detected, never configured. */
|
|
15
|
+
export type ContainerRuntime = 'docker' | 'podman';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Lifecycle states, normalised across both runtimes. `unknown` is kept rather
|
|
19
|
+
* than folded into `exited`: a state Clopen does not recognise must not be
|
|
20
|
+
* rendered as one it does.
|
|
21
|
+
*/
|
|
22
|
+
export type ContainerState =
|
|
23
|
+
| 'running'
|
|
24
|
+
| 'paused'
|
|
25
|
+
| 'restarting'
|
|
26
|
+
| 'created'
|
|
27
|
+
| 'exited'
|
|
28
|
+
| 'dead'
|
|
29
|
+
| 'removing'
|
|
30
|
+
| 'unknown';
|
|
31
|
+
|
|
32
|
+
/** A healthcheck verdict. `none` means the image declares no healthcheck. */
|
|
33
|
+
export type ContainerHealth = 'healthy' | 'unhealthy' | 'starting' | 'none';
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* One published port. `hostPort` is null when the port is exposed by the image
|
|
37
|
+
* but not published to the host — the container can be reached from its own
|
|
38
|
+
* network and nowhere else, which is worth showing rather than hiding.
|
|
39
|
+
*/
|
|
40
|
+
export interface ContainerPortBinding {
|
|
41
|
+
/** The address on the host the port is bound to, e.g. `0.0.0.0`. */
|
|
42
|
+
hostAddress: string | null;
|
|
43
|
+
hostPort: number | null;
|
|
44
|
+
containerPort: number;
|
|
45
|
+
protocol: 'tcp' | 'udp';
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** One row in the container table. */
|
|
49
|
+
export interface ContainerEntry {
|
|
50
|
+
/** Stable across scans, so the UI can diff without rebuilding the table. */
|
|
51
|
+
key: string;
|
|
52
|
+
/** Full id, used for every action so a name collision cannot misfire. */
|
|
53
|
+
id: string;
|
|
54
|
+
/** Twelve characters of the id, which is how the runtime prints it. */
|
|
55
|
+
shortId: string;
|
|
56
|
+
name: string;
|
|
57
|
+
image: string;
|
|
58
|
+
state: ContainerState;
|
|
59
|
+
/** The runtime's own words, e.g. `Up 3 hours (healthy)`. */
|
|
60
|
+
statusText: string;
|
|
61
|
+
health: ContainerHealth;
|
|
62
|
+
/** ISO timestamp, or null when the runtime printed a date nothing can parse. */
|
|
63
|
+
createdAt: string | null;
|
|
64
|
+
/** ISO timestamp of the current run; null unless the container is running. */
|
|
65
|
+
startedAt: string | null;
|
|
66
|
+
ports: ContainerPortBinding[];
|
|
67
|
+
/** Set from the compose labels, so a stack reads as a stack. */
|
|
68
|
+
composeProject: string | null;
|
|
69
|
+
composeService: string | null;
|
|
70
|
+
/** The entrypoint command, as the runtime reports it. */
|
|
71
|
+
command: string | null;
|
|
72
|
+
/**
|
|
73
|
+
* False when this host would refuse the action anyway — a container the
|
|
74
|
+
* account cannot touch is shown, but not offered as something to stop.
|
|
75
|
+
*/
|
|
76
|
+
canManage: boolean;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** An image on the host. Read-only: building and pulling are out of scope. */
|
|
80
|
+
export interface ContainerImageEntry {
|
|
81
|
+
key: string;
|
|
82
|
+
id: string;
|
|
83
|
+
repository: string;
|
|
84
|
+
tag: string;
|
|
85
|
+
/** Human size exactly as the runtime printed it. */
|
|
86
|
+
size: string;
|
|
87
|
+
createdAt: string | null;
|
|
88
|
+
/** True for `<none>:<none>` layers left behind by a rebuild. */
|
|
89
|
+
dangling: boolean;
|
|
90
|
+
/** Names of containers currently using it, so deleting is never a surprise. */
|
|
91
|
+
usedBy: string[];
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** A network on the host. */
|
|
95
|
+
export interface ContainerNetworkEntry {
|
|
96
|
+
key: string;
|
|
97
|
+
id: string;
|
|
98
|
+
name: string;
|
|
99
|
+
driver: string;
|
|
100
|
+
scope: string;
|
|
101
|
+
internal: boolean;
|
|
102
|
+
createdAt: string | null;
|
|
103
|
+
usedBy: string[];
|
|
104
|
+
/**
|
|
105
|
+
* True for the networks the runtime creates itself — `bridge`, `host`,
|
|
106
|
+
* `none`, `podman`. They cannot be removed, and offering to would only
|
|
107
|
+
* produce an error the user cannot act on.
|
|
108
|
+
*/
|
|
109
|
+
predefined: boolean;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** A volume on the host. */
|
|
113
|
+
export interface ContainerVolumeEntry {
|
|
114
|
+
key: string;
|
|
115
|
+
name: string;
|
|
116
|
+
driver: string;
|
|
117
|
+
mountpoint: string | null;
|
|
118
|
+
createdAt: string | null;
|
|
119
|
+
usedBy: string[];
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* A capability this host could not deliver. Surfaced in the UI so an empty
|
|
124
|
+
* table reads as "this host cannot tell us" rather than "nothing is running".
|
|
125
|
+
*/
|
|
126
|
+
export type ContainerLimitationCode =
|
|
127
|
+
| 'no-runtime'
|
|
128
|
+
| 'daemon-unreachable'
|
|
129
|
+
| 'permission-denied'
|
|
130
|
+
| 'images-unavailable'
|
|
131
|
+
| 'volumes-unavailable'
|
|
132
|
+
| 'networks-unavailable'
|
|
133
|
+
| 'no-start-times';
|
|
134
|
+
|
|
135
|
+
export interface ContainerLimitation {
|
|
136
|
+
code: ContainerLimitationCode;
|
|
137
|
+
message: string;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/** How the host answered when asked what runtime it has. */
|
|
141
|
+
export interface ContainerRuntimeInfo {
|
|
142
|
+
runtime: ContainerRuntime | null;
|
|
143
|
+
version: string | null;
|
|
144
|
+
/**
|
|
145
|
+
* Why there is no usable runtime. Split out because the three causes need
|
|
146
|
+
* three different things from the user, and "no containers" is the wrong
|
|
147
|
+
* answer to all of them.
|
|
148
|
+
*/
|
|
149
|
+
problem: 'none' | 'not-installed' | 'daemon-unreachable' | 'permission-denied';
|
|
150
|
+
/** The runtime's own error, when it gave one. */
|
|
151
|
+
detail: string | null;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
export interface ContainerScanResult {
|
|
155
|
+
hostId: HostId;
|
|
156
|
+
/** ISO timestamp of the scan that produced this. */
|
|
157
|
+
scannedAt: string;
|
|
158
|
+
runtime: ContainerRuntime | null;
|
|
159
|
+
runtimeVersion: string | null;
|
|
160
|
+
runtimeProblem: ContainerRuntimeInfo['problem'];
|
|
161
|
+
entries: ContainerEntry[];
|
|
162
|
+
images: ContainerImageEntry[];
|
|
163
|
+
volumes: ContainerVolumeEntry[];
|
|
164
|
+
networks: ContainerNetworkEntry[];
|
|
165
|
+
limitations: ContainerLimitation[];
|
|
166
|
+
/** Set when the scan failed outright; the lists are then empty. */
|
|
167
|
+
error: string | null;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/** What a row offers to do. All of these are admin-only on the server. */
|
|
171
|
+
export type ContainerAction =
|
|
172
|
+
| 'start'
|
|
173
|
+
| 'stop'
|
|
174
|
+
| 'restart'
|
|
175
|
+
| 'pause'
|
|
176
|
+
| 'unpause'
|
|
177
|
+
| 'remove'
|
|
178
|
+
/** `remove` on something still running: it is stopped first, by the runtime. */
|
|
179
|
+
| 'force-remove';
|
|
180
|
+
|
|
181
|
+
export interface ContainerActionResult {
|
|
182
|
+
ok: boolean;
|
|
183
|
+
error: string | null;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/** The four things a host holds that this feature can remove. */
|
|
187
|
+
export type ContainerResourceKind = 'container' | 'image' | 'volume' | 'network';
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* The three that are removed as themselves. A container is removed through its
|
|
191
|
+
* own lifecycle instead, because whether it is still running changes both the
|
|
192
|
+
* command and what the confirmation has to say.
|
|
193
|
+
*/
|
|
194
|
+
export type RemovableResourceKind = Exclude<ContainerResourceKind, 'container'>;
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* What a clean-up sweep can reclaim.
|
|
198
|
+
*
|
|
199
|
+
* Split by what each one costs to get back rather than lumped into one button.
|
|
200
|
+
* Removing a stopped container is nothing; removing an unused image means
|
|
201
|
+
* pulling or building it again, which on a slow connection is an afternoon.
|
|
202
|
+
*/
|
|
203
|
+
export type PruneKind =
|
|
204
|
+
| 'containers'
|
|
205
|
+
| 'dangling-images'
|
|
206
|
+
| 'images'
|
|
207
|
+
| 'volumes'
|
|
208
|
+
| 'networks'
|
|
209
|
+
| 'build-cache';
|
|
210
|
+
|
|
211
|
+
export interface PruneOutcome {
|
|
212
|
+
kind: PruneKind;
|
|
213
|
+
ok: boolean;
|
|
214
|
+
/** Entries the runtime listed as removed. Zero is a normal answer. */
|
|
215
|
+
removed: number;
|
|
216
|
+
/** Space the runtime says it freed, in its own words. Null if it did not say. */
|
|
217
|
+
reclaimed: string | null;
|
|
218
|
+
error: string | null;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* A cleanup sweep, as the server remembers it.
|
|
223
|
+
*
|
|
224
|
+
* The sweep belongs to the host, not to the dialog that started it. Closing the
|
|
225
|
+
* dialog — or refreshing the browser, or opening the panel on another device —
|
|
226
|
+
* must not lose track of a `prune` that is still deleting, and must not invite
|
|
227
|
+
* a second one on top of it. So the server owns the job and the dialog attaches
|
|
228
|
+
* to whatever it finds.
|
|
229
|
+
*/
|
|
230
|
+
export interface PruneJob {
|
|
231
|
+
hostId: string;
|
|
232
|
+
kinds: PruneKind[];
|
|
233
|
+
startedAt: string;
|
|
234
|
+
/** Null while the sweep is still running. */
|
|
235
|
+
finishedAt: string | null;
|
|
236
|
+
/** One line per kind, filled in when the sweep ends. */
|
|
237
|
+
outcomes: PruneOutcome[] | null;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/** One line of `system df`: how much of a resource is in use, and how much is not. */
|
|
241
|
+
export interface ContainerDiskUsageRow {
|
|
242
|
+
kind: 'images' | 'containers' | 'volumes' | 'build-cache';
|
|
243
|
+
total: number | null;
|
|
244
|
+
active: number | null;
|
|
245
|
+
/** Sizes stay as the runtime printed them — it is the authority on its own units. */
|
|
246
|
+
size: string;
|
|
247
|
+
reclaimable: string;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
export interface ContainerDiskUsage {
|
|
251
|
+
rows: ContainerDiskUsageRow[];
|
|
252
|
+
error: string | null;
|
|
253
|
+
/**
|
|
254
|
+
* When this reading was taken, so the dialog can say how old it is.
|
|
255
|
+
*
|
|
256
|
+
* A reading is shown from cache rather than re-measured on every open,
|
|
257
|
+
* because `system df` is the one container command whose cost is set by how
|
|
258
|
+
* much disk the host holds rather than by how many containers it runs: the
|
|
259
|
+
* daemon walks every image layer and every volume to answer it. On a host
|
|
260
|
+
* with a few hundred volumes on a virtualised filesystem that is over a
|
|
261
|
+
* minute, and almost all of it is the volumes.
|
|
262
|
+
*/
|
|
263
|
+
measuredAt: string | null;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* How long each container command may run, and therefore how long a caller has
|
|
268
|
+
* to be prepared to wait for it.
|
|
269
|
+
*
|
|
270
|
+
* Both ends read these. The backend hands them to the runtime as the command
|
|
271
|
+
* budget; the frontend hands them to `ws.http` as the request budget, plus
|
|
272
|
+
* `TRANSPORT_GRACE_MS`. They have to come from one place, because a transport
|
|
273
|
+
* that gives up before the command does turns every slow-but-successful run
|
|
274
|
+
* into a reported failure — a prune that is still deleting, a container that is
|
|
275
|
+
* still stopping — and the caller then has no way to find out it worked.
|
|
276
|
+
*/
|
|
277
|
+
export const CONTAINER_TIMEOUTS = {
|
|
278
|
+
/** `stop` waits out the container's grace period, which can be long. */
|
|
279
|
+
action: 120_000,
|
|
280
|
+
/** A prune walks and unlinks everything it removes. */
|
|
281
|
+
prune: 300_000,
|
|
282
|
+
/** One `ps`, `images`, `volume ls` or `network ls`. */
|
|
283
|
+
list: 20_000,
|
|
284
|
+
/** A full listing: the four above, plus detecting the runtime. */
|
|
285
|
+
scan: 90_000,
|
|
286
|
+
/** `stats` samples over a window before it prints. */
|
|
287
|
+
stats: 30_000,
|
|
288
|
+
inspect: 20_000
|
|
289
|
+
} as const;
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* The extra the transport allows on top of the command's own budget.
|
|
293
|
+
*
|
|
294
|
+
* Enough to cover the round trip and the runtime's own teardown, so the command
|
|
295
|
+
* is always the thing that gives up first and the caller always hears why.
|
|
296
|
+
*/
|
|
297
|
+
export const TRANSPORT_GRACE_MS = 15_000;
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* How long a disk reading stays good before the dialog measures again.
|
|
301
|
+
*
|
|
302
|
+
* The figures only move when something is created or removed, and a prune
|
|
303
|
+
* invalidates them outright, so re-measuring on every open would spend a minute
|
|
304
|
+
* of the daemon's time to redraw numbers that had not changed.
|
|
305
|
+
*/
|
|
306
|
+
export const DISK_USAGE_STALE_MS = 300_000;
|
|
307
|
+
|
|
308
|
+
/**
|
|
309
|
+
* How long the measurement itself may run before it is abandoned.
|
|
310
|
+
*
|
|
311
|
+
* Nothing waits on this — it is pushed when it lands — so the budget is here to
|
|
312
|
+
* stop a wedged daemon holding a slot forever, not to bound anyone's spinner.
|
|
313
|
+
*/
|
|
314
|
+
export const DISK_USAGE_TIMEOUT_MS = 600_000;
|
|
315
|
+
|
|
316
|
+
/** A single sample of what one container is consuming, read on demand. */
|
|
317
|
+
export interface ContainerStats {
|
|
318
|
+
cpuPercent: number | null;
|
|
319
|
+
memoryUsage: string | null;
|
|
320
|
+
memoryPercent: number | null;
|
|
321
|
+
networkIO: string | null;
|
|
322
|
+
blockIO: string | null;
|
|
323
|
+
pids: number | null;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
/** Everything `inspect` adds to a row, fetched only when a detail pane opens. */
|
|
327
|
+
export interface ContainerDetail {
|
|
328
|
+
id: string;
|
|
329
|
+
name: string;
|
|
330
|
+
image: string;
|
|
331
|
+
imageId: string | null;
|
|
332
|
+
command: string | null;
|
|
333
|
+
createdAt: string | null;
|
|
334
|
+
startedAt: string | null;
|
|
335
|
+
finishedAt: string | null;
|
|
336
|
+
state: ContainerState;
|
|
337
|
+
health: ContainerHealth;
|
|
338
|
+
exitCode: number | null;
|
|
339
|
+
restartCount: number | null;
|
|
340
|
+
restartPolicy: string | null;
|
|
341
|
+
pid: number | null;
|
|
342
|
+
workingDir: string | null;
|
|
343
|
+
user: string | null;
|
|
344
|
+
networks: Array<{ name: string; ipAddress: string | null }>;
|
|
345
|
+
mounts: Array<{ source: string; destination: string; readOnly: boolean; kind: string }>;
|
|
346
|
+
ports: ContainerPortBinding[];
|
|
347
|
+
env: string[];
|
|
348
|
+
labels: Array<{ key: string; value: string }>;
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
/** One push of container output while a log stream is being followed. */
|
|
352
|
+
export interface ContainerLogChunk {
|
|
353
|
+
streamId: string;
|
|
354
|
+
hostId: HostId;
|
|
355
|
+
containerId: string;
|
|
356
|
+
/** Newline-terminated text exactly as the container wrote it. */
|
|
357
|
+
data: string;
|
|
358
|
+
/** Set once when the stream ends, with the reason if it was not asked for. */
|
|
359
|
+
done?: boolean;
|
|
360
|
+
error?: string | null;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
export const LOCAL_CONTAINER_HOST: HostId = LOCAL_HOST_ID;
|
|
364
|
+
|
|
365
|
+
/** Lines kept per stream. A chatty container must not grow without limit. */
|
|
366
|
+
export const CONTAINER_LOG_BUFFER_LINES = 2000;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The identity of a machine Clopen can act on.
|
|
3
|
+
*
|
|
4
|
+
* Ports, containers and everything host-scoped that follows them address a
|
|
5
|
+
* machine the same way: `local` is the machine Clopen itself runs on, and any
|
|
6
|
+
* other id is a saved SSH connection. `local` is not a special case — it is
|
|
7
|
+
* simply the host whose id happens to be `local`, which is what lets one store
|
|
8
|
+
* and one scan serve both the More Tools panel and the SSH Client tab.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
export type HostId = string;
|
|
12
|
+
|
|
13
|
+
export const LOCAL_HOST_ID: HostId = 'local';
|
|
14
|
+
|
|
15
|
+
/** True when this id names the machine Clopen is running on. */
|
|
16
|
+
export function isLocalHost(hostId: HostId): boolean {
|
|
17
|
+
return hostId === LOCAL_HOST_ID;
|
|
18
|
+
}
|
|
@@ -0,0 +1,230 @@
|
|
|
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
|
+
import { LOCAL_HOST_ID, type HostId } from '../host';
|
|
12
|
+
|
|
13
|
+
export type PortProtocol = 'tcp' | 'udp';
|
|
14
|
+
|
|
15
|
+
export type PortIpVersion = 'v4' | 'v6';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Only the three states worth acting on. Everything transient (TIME_WAIT,
|
|
19
|
+
* SYN_SENT, the rest of the TCP state machine) collapses into `other` — it
|
|
20
|
+
* describes a socket that is closing, not a port anyone owns.
|
|
21
|
+
*/
|
|
22
|
+
export type PortSocketState = 'listen' | 'established' | 'other';
|
|
23
|
+
|
|
24
|
+
/** A socket row exactly as the OS probe reported it, before any attribution. */
|
|
25
|
+
export interface PortSocket {
|
|
26
|
+
protocol: PortProtocol;
|
|
27
|
+
ipVersion: PortIpVersion;
|
|
28
|
+
/** Local bind address. `*` means every interface. */
|
|
29
|
+
address: string;
|
|
30
|
+
port: number;
|
|
31
|
+
state: PortSocketState;
|
|
32
|
+
/** Null when the probe could not see the owner — see `PortLimitationCode`. */
|
|
33
|
+
pid: number | null;
|
|
34
|
+
/** Short on Linux `ss`, full path on macOS `lsof`, absent on Windows netstat. */
|
|
35
|
+
processName: string | null;
|
|
36
|
+
user: string | null;
|
|
37
|
+
peerAddress: string | null;
|
|
38
|
+
peerPort: number | null;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** Process facts behind a socket, resolved once per pid and cached. */
|
|
42
|
+
export interface PortProcess {
|
|
43
|
+
pid: number;
|
|
44
|
+
parentPid: number | null;
|
|
45
|
+
user: string | null;
|
|
46
|
+
/** Full argv when the platform exposes it, else the executable name. */
|
|
47
|
+
command: string;
|
|
48
|
+
/** ISO timestamp. Also disambiguates a reused pid from the cached one. */
|
|
49
|
+
startedAt: string | null;
|
|
50
|
+
/**
|
|
51
|
+
* Working directory — the strongest hint at *which project* a dev server
|
|
52
|
+
* belongs to. Unavailable on Windows, and on Unix only for our own user.
|
|
53
|
+
*/
|
|
54
|
+
cwd: string | null;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* How confident the attribution is. `certain` means Clopen either opened the
|
|
59
|
+
* listener itself or watched the process being born; `guess` means the label
|
|
60
|
+
* was inferred from the command line and may be wrong.
|
|
61
|
+
*/
|
|
62
|
+
export type PortOriginConfidence = 'certain' | 'guess';
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* The four tiers the UI groups by:
|
|
66
|
+
* - `clopen` — a listener Clopen opened, registered by the feature that owns it
|
|
67
|
+
* - `session` — a process descended from a Clopen terminal session
|
|
68
|
+
* - `container` — a port a container runtime publishes on this host
|
|
69
|
+
* - `external` — everything else on the machine
|
|
70
|
+
*/
|
|
71
|
+
export type PortOriginKind = 'clopen' | 'session' | 'container' | 'external';
|
|
72
|
+
|
|
73
|
+
/** Which Clopen feature owns a `clopen` port, so it can be stopped properly. */
|
|
74
|
+
export type PortOwnerFeature =
|
|
75
|
+
| 'server'
|
|
76
|
+
| 'tunnel'
|
|
77
|
+
| 'ssh-forward'
|
|
78
|
+
| 'db-client-tunnel'
|
|
79
|
+
| 'preview-browser'
|
|
80
|
+
| 'mcp'
|
|
81
|
+
| 'engine';
|
|
82
|
+
|
|
83
|
+
export interface PortOrigin {
|
|
84
|
+
kind: PortOriginKind;
|
|
85
|
+
confidence: PortOriginConfidence;
|
|
86
|
+
/** Short human label, e.g. "Clopen server" or "Vite dev server". */
|
|
87
|
+
label: string;
|
|
88
|
+
/** Second line: the host being forwarded to, the project, the raw command. */
|
|
89
|
+
detail: string | null;
|
|
90
|
+
/** Set when `kind` is `clopen`. */
|
|
91
|
+
ownerFeature?: PortOwnerFeature;
|
|
92
|
+
/** Identifies the owning record (forward id, tunnel id, …) for the stop path. */
|
|
93
|
+
ownerId?: string;
|
|
94
|
+
/** Set when `kind` is `session` — the PTY session the process descends from. */
|
|
95
|
+
sessionId?: string;
|
|
96
|
+
/** Project the session belongs to, so the UI can name it. */
|
|
97
|
+
projectId?: string;
|
|
98
|
+
/** Set when the lineage ends at an sshd session rather than a Clopen one. */
|
|
99
|
+
remoteSessionUser?: string;
|
|
100
|
+
/** Set when `kind` is `container` — the container publishing this port. */
|
|
101
|
+
containerId?: string;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* The container publishing a port, when one does.
|
|
106
|
+
*
|
|
107
|
+
* A published port is a fact the runtime states outright, so this is never a
|
|
108
|
+
* guess. It is also the only owner worth naming: the listening process is
|
|
109
|
+
* `docker-proxy` or the daemon itself, and with the userland proxy disabled
|
|
110
|
+
* there is no listening socket at all — the port is reached through a firewall
|
|
111
|
+
* rule. Either way the thing to act on is the container.
|
|
112
|
+
*/
|
|
113
|
+
export interface PortContainerRef {
|
|
114
|
+
runtime: 'docker' | 'podman';
|
|
115
|
+
/** Full container id, so an action can address it unambiguously. */
|
|
116
|
+
id: string;
|
|
117
|
+
/** Twelve-character id, which is how the runtime's own output reads. */
|
|
118
|
+
shortId: string;
|
|
119
|
+
name: string;
|
|
120
|
+
image: string;
|
|
121
|
+
/** The port inside the container this host port is mapped to. */
|
|
122
|
+
containerPort: number;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/** A peer currently connected to a listening port. */
|
|
126
|
+
export interface PortPeer {
|
|
127
|
+
address: string;
|
|
128
|
+
port: number;
|
|
129
|
+
/** Present when the probe could attribute the peer socket to a process. */
|
|
130
|
+
processName: string | null;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/** Why a port cannot be stopped from here. */
|
|
134
|
+
export type PortKillBlockedReason =
|
|
135
|
+
| 'is-clopen-itself'
|
|
136
|
+
| 'unknown-pid'
|
|
137
|
+
| 'not-permitted'
|
|
138
|
+
| 'system-process'
|
|
139
|
+
| 'managed-by-container';
|
|
140
|
+
|
|
141
|
+
/** One row in the table: a port, its owner, and what is connected to it. */
|
|
142
|
+
export interface PortEntry {
|
|
143
|
+
/** Stable across scans, so the UI can diff without rebuilding the table. */
|
|
144
|
+
key: string;
|
|
145
|
+
protocol: PortProtocol;
|
|
146
|
+
port: number;
|
|
147
|
+
/** Every address this pid binds the port on, e.g. `127.0.0.1` and `::1`. */
|
|
148
|
+
addresses: string[];
|
|
149
|
+
ipVersions: PortIpVersion[];
|
|
150
|
+
pid: number | null;
|
|
151
|
+
process: PortProcess | null;
|
|
152
|
+
/**
|
|
153
|
+
* Every process holding this port, when a server pre-forks workers that
|
|
154
|
+
* inherit the listening socket. One row is reported for the group, and this
|
|
155
|
+
* says how wide the group is.
|
|
156
|
+
*/
|
|
157
|
+
workerPids: number[];
|
|
158
|
+
origin: PortOrigin;
|
|
159
|
+
peers: PortPeer[];
|
|
160
|
+
peerCount: number;
|
|
161
|
+
/**
|
|
162
|
+
* Set when a Cloudflare tunnel points at this port. A tunnel dials the port
|
|
163
|
+
* rather than binding it, so this is exposure, not ownership — the port
|
|
164
|
+
* still belongs to whatever process is listening, and this says it is also
|
|
165
|
+
* reachable from the public internet.
|
|
166
|
+
*/
|
|
167
|
+
publicUrl: string | null;
|
|
168
|
+
/**
|
|
169
|
+
* Set when a container runtime publishes this port. Like `publicUrl` this
|
|
170
|
+
* describes how the port is reached rather than replacing whoever holds it,
|
|
171
|
+
* and it is what lets the row point at the container instead of offering to
|
|
172
|
+
* signal a proxy process that would only come back.
|
|
173
|
+
*/
|
|
174
|
+
container: PortContainerRef | null;
|
|
175
|
+
canKill: boolean;
|
|
176
|
+
killBlockedReason: PortKillBlockedReason | null;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* A capability the scan could not deliver on this host. Surfaced in the UI so
|
|
181
|
+
* a missing owner reads as "this platform cannot tell us" rather than a bug.
|
|
182
|
+
*/
|
|
183
|
+
export type PortLimitationCode =
|
|
184
|
+
| 'pids-need-root'
|
|
185
|
+
| 'no-cwd-support'
|
|
186
|
+
| 'no-process-args'
|
|
187
|
+
| 'no-session-attribution'
|
|
188
|
+
| 'probe-fallback';
|
|
189
|
+
|
|
190
|
+
export interface PortLimitation {
|
|
191
|
+
code: PortLimitationCode;
|
|
192
|
+
message: string;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* `local` is the machine running Clopen; any other id is an SSH connection.
|
|
197
|
+
* Both names point at the same value: host identity is shared by every
|
|
198
|
+
* host-scoped feature, and ports keep their own spelling only for readability.
|
|
199
|
+
*/
|
|
200
|
+
export type PortHostId = HostId;
|
|
201
|
+
|
|
202
|
+
export const LOCAL_PORT_HOST: PortHostId = LOCAL_HOST_ID;
|
|
203
|
+
|
|
204
|
+
export interface PortScanResult {
|
|
205
|
+
hostId: PortHostId;
|
|
206
|
+
/** ISO timestamp of the scan that produced these entries. */
|
|
207
|
+
scannedAt: string;
|
|
208
|
+
platform: string;
|
|
209
|
+
/**
|
|
210
|
+
* Which probe actually read the socket table. Reported because how much a
|
|
211
|
+
* row can say depends entirely on this — `netstat` on Windows names no
|
|
212
|
+
* process, `/proc/net` needs a second lookup for one — and because a host
|
|
213
|
+
* that answers with less than expected is otherwise impossible to explain.
|
|
214
|
+
*/
|
|
215
|
+
probe: string;
|
|
216
|
+
entries: PortEntry[];
|
|
217
|
+
limitations: PortLimitation[];
|
|
218
|
+
/** Set when the scan failed outright; `entries` is then empty. */
|
|
219
|
+
error: string | null;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/** What a kill attempt did, reported honestly including refusals. */
|
|
223
|
+
export interface PortKillResult {
|
|
224
|
+
ok: boolean;
|
|
225
|
+
/** Pids actually signalled, children first. */
|
|
226
|
+
killedPids: number[];
|
|
227
|
+
/** Set when the port belonged to a feature and was stopped, not signalled. */
|
|
228
|
+
stoppedFeature: PortOwnerFeature | null;
|
|
229
|
+
error: string | null;
|
|
230
|
+
}
|