@myrialabs/clopen 0.4.32 → 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 (102) 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/chat/stream-manager.ts +4 -1
  5. package/backend/database/migrations/069_create_ssh_client_tables.ts +116 -0
  6. package/backend/database/migrations/index.ts +7 -0
  7. package/backend/database/queries/db-client-connection-queries.ts +7 -2
  8. package/backend/database/queries/file-audit-log-queries.ts +1 -0
  9. package/backend/database/queries/index.ts +3 -0
  10. package/backend/database/queries/ssh-connection-queries.ts +244 -0
  11. package/backend/database/queries/ssh-known-host-queries.ts +67 -0
  12. package/backend/database/queries/ssh-port-forward-queries.ts +113 -0
  13. package/backend/db-client/connection-manager.ts +21 -1
  14. package/backend/engine/adapters/codex/message-converter.ts +18 -12
  15. package/backend/engine/adapters/codex/patch-rollout.test.ts +88 -0
  16. package/backend/engine/adapters/codex/patch-rollout.ts +120 -109
  17. package/backend/engine/adapters/codex/stream.ts +33 -4
  18. package/backend/engine/adapters/copilot/stream.ts +1 -1
  19. package/backend/engine/adapters/cursor/stream.ts +1 -1
  20. package/backend/engine/adapters/qwen/stream.ts +1 -1
  21. package/backend/engine/docs/adapter-contract.md +7 -0
  22. package/backend/files/file-watcher.ts +283 -51
  23. package/backend/files/git-events.test.ts +110 -0
  24. package/backend/git/git-dirs.test.ts +132 -0
  25. package/backend/git/git-dirs.ts +0 -0
  26. package/backend/git/nested-repos.test.ts +108 -5
  27. package/backend/git/nested-repos.ts +103 -18
  28. package/backend/http/audio.ts +5 -32
  29. package/backend/http/bearer-auth.ts +47 -0
  30. package/backend/http/files-download.test.ts +146 -0
  31. package/backend/http/files-download.ts +109 -0
  32. package/backend/http/files-upload.ts +3 -29
  33. package/backend/http/ssh-sftp.ts +133 -0
  34. package/backend/index.ts +25 -2
  35. package/backend/mcp/README.md +34 -6
  36. package/backend/mcp/index.ts +8 -8
  37. package/backend/mcp/internal/config.ts +69 -19
  38. package/backend/mcp/internal/project-context.test.ts +40 -0
  39. package/backend/mcp/internal/project-context.ts +80 -7
  40. package/backend/mcp/internal/remote-server.test.ts +17 -2
  41. package/backend/mcp/internal/remote-server.ts +36 -3
  42. package/backend/mcp/internal/servers/helper.ts +48 -18
  43. package/backend/middleware/security.test.ts +95 -0
  44. package/backend/middleware/security.ts +114 -0
  45. package/backend/ports/attribute.test.ts +231 -0
  46. package/backend/ports/attribute.ts +444 -0
  47. package/backend/ports/kill.ts +203 -0
  48. package/backend/ports/monitor.ts +365 -0
  49. package/backend/ports/processes.test.ts +98 -0
  50. package/backend/ports/processes.ts +374 -0
  51. package/backend/ports/registry.ts +165 -0
  52. package/backend/ports/runner.ts +195 -0
  53. package/backend/ports/scan-host.ts +260 -0
  54. package/backend/ports/scan.test.ts +341 -0
  55. package/backend/ports/scan.ts +687 -0
  56. package/backend/ports/ssh-lineage.ts +318 -0
  57. package/backend/preview/browser/browser-video-capture.ts +51 -4
  58. package/backend/ssh/client-pool.ts +196 -0
  59. package/backend/ssh/connect.ts +375 -0
  60. package/backend/ssh/disk-usage.test.ts +134 -0
  61. package/backend/ssh/disk-usage.ts +214 -0
  62. package/backend/ssh/forwards.ts +340 -0
  63. package/backend/ssh/health.ts +141 -0
  64. package/backend/ssh/known-hosts.ts +96 -0
  65. package/backend/ssh/pty-backend.ts +215 -0
  66. package/backend/ssh/ptykit.ts +66 -0
  67. package/backend/ssh/sftp.test.ts +242 -0
  68. package/backend/ssh/sftp.ts +967 -0
  69. package/backend/ssh/socks5.test.ts +167 -0
  70. package/backend/ssh/socks5.ts +164 -0
  71. package/backend/ssh/tunnel.ts +87 -0
  72. package/backend/ws/auth/device.ts +1 -1
  73. package/backend/ws/auth/login.ts +8 -4
  74. package/backend/ws/db-client/connections.ts +1 -0
  75. package/backend/ws/files/watch.ts +5 -1
  76. package/backend/ws/index.ts +6 -0
  77. package/backend/ws/ports/index.ts +19 -0
  78. package/backend/ws/ports/kill.ts +80 -0
  79. package/backend/ws/ports/list.ts +60 -0
  80. package/backend/ws/ssh/access.ts +31 -0
  81. package/backend/ws/ssh/connections.ts +224 -0
  82. package/backend/ws/ssh/forwards.ts +109 -0
  83. package/backend/ws/ssh/index.ts +18 -0
  84. package/backend/ws/ssh/sftp.ts +259 -0
  85. package/backend/ws/ssh/tunnel.ts +93 -0
  86. package/dist/assets/{index-hu17G6tX.js → index-gGTMFUa8.js} +1 -1
  87. package/dist/assets/{index-DSvGoxp2.js → index-vW2RpdHu.js} +1 -1
  88. package/dist/assets/main-CYCMEbXB.css +1 -0
  89. package/dist/assets/{main-BccclZsC.js → main-ZCojSzvW.js} +506 -477
  90. package/dist/index.html +2 -2
  91. package/package.json +1 -1
  92. package/shared/types/database/schema.ts +49 -0
  93. package/shared/types/db-client/connection.ts +6 -0
  94. package/shared/types/ports/index.ts +5 -0
  95. package/shared/types/ports/port.ts +192 -0
  96. package/shared/types/ssh/connection.ts +80 -0
  97. package/shared/types/ssh/forward.ts +46 -0
  98. package/shared/types/ssh/index.ts +8 -0
  99. package/shared/types/ssh/known-host.ts +19 -0
  100. package/shared/types/ssh/sftp.ts +141 -0
  101. package/shared/utils/logger.ts +2 -0
  102. package/dist/assets/main-Ciuw0wF0.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-BccclZsC.js"></script>
62
- <link rel="stylesheet" crossorigin href="/assets/main-Ciuw0wF0.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.32",
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",
@@ -203,8 +203,57 @@ export interface DBDbClientConnectionRow {
203
203
  options_json: string | null;
204
204
  color: string | null;
205
205
  owner_user_id: string | null;
206
+ /** When set, the SSH tunnel settings come from this saved SSH connection. */
207
+ ssh_connection_id: string | null;
206
208
  created_at: string;
207
209
  updated_at: string;
208
210
  last_used_at: string | null;
209
211
  }
210
212
 
213
+ export interface DBSshConnectionRow {
214
+ id: string;
215
+ name: string;
216
+ host: string;
217
+ port: number;
218
+ username: string;
219
+ auth_method: 'password' | 'key' | 'key-file' | 'agent';
220
+ password: string | null;
221
+ private_key: string | null;
222
+ private_key_path: string | null;
223
+ passphrase: string | null;
224
+ agent_socket: string | null;
225
+ jump_connection_id: string | null;
226
+ initial_path: string | null;
227
+ keepalive_seconds: number;
228
+ strict_host_key: number;
229
+ color: string | null;
230
+ owner_user_id: string | null;
231
+ created_at: string;
232
+ updated_at: string;
233
+ last_used_at: string | null;
234
+ }
235
+
236
+ export interface DBSshKnownHostRow {
237
+ id: string;
238
+ host: string;
239
+ port: number;
240
+ key_type: string;
241
+ fingerprint: string;
242
+ added_at: string;
243
+ last_seen_at: string | null;
244
+ }
245
+
246
+ export interface DBSshPortForwardRow {
247
+ id: string;
248
+ connection_id: string;
249
+ name: string;
250
+ type: 'local' | 'remote' | 'dynamic';
251
+ listen_host: string;
252
+ listen_port: number;
253
+ dest_host: string | null;
254
+ dest_port: number | null;
255
+ auto_start: number;
256
+ created_at: string;
257
+ updated_at: string;
258
+ }
259
+
@@ -8,6 +8,12 @@ export type DbSshAuthMethod = 'password' | 'key';
8
8
 
9
9
  export interface DbClientSshConfig {
10
10
  enabled: boolean;
11
+ /**
12
+ * When set, the tunnel is opened through this saved SSH connection and every
13
+ * field below is ignored. Keeping both modes means existing connections that
14
+ * carry their own credentials keep working untouched.
15
+ */
16
+ connectionId?: string | null;
11
17
  host: string;
12
18
  port: number;
13
19
  username: string;
@@ -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
+ }
@@ -0,0 +1,80 @@
1
+ /**
2
+ * ssh-client — connection types shared between backend and frontend.
3
+ */
4
+
5
+ /**
6
+ * How Clopen authenticates to the remote host.
7
+ *
8
+ * - `password` — a stored password. Clopen also answers `keyboard-interactive`
9
+ * prompts with it, so servers that disable plain password auth
10
+ * (`KbdInteractiveAuthentication yes`) still work.
11
+ * - `key` — a private key pasted into Clopen and stored in the database.
12
+ * - `key-file` — a private key read from the Clopen server's filesystem at
13
+ * connect time, so the key material never enters the database.
14
+ * - `agent` — delegate to a running ssh-agent (`SSH_AUTH_SOCK`, or the
15
+ * explicit socket path on the connection).
16
+ */
17
+ export type SshAuthMethod = 'password' | 'key' | 'key-file' | 'agent';
18
+
19
+ export interface SshConnection {
20
+ id: string;
21
+ name: string;
22
+ host: string;
23
+ port: number;
24
+ username: string;
25
+ authMethod: SshAuthMethod;
26
+ password: string | null;
27
+ privateKey: string | null;
28
+ privateKeyPath: string | null;
29
+ passphrase: string | null;
30
+ agentSocket: string | null;
31
+ /** Another saved connection to tunnel through (ProxyJump). */
32
+ jumpConnectionId: string | null;
33
+ /** Remote directory the shell and the file browser start in. */
34
+ initialPath: string | null;
35
+ /** Seconds between keepalive packets. 0 disables them. */
36
+ keepaliveSeconds: number;
37
+ /** Refuse to connect when the host key does not match the trusted one. */
38
+ strictHostKey: boolean;
39
+ color: string | null;
40
+ createdAt: string;
41
+ updatedAt: string;
42
+ lastUsedAt: string | null;
43
+ }
44
+
45
+ export interface SshConnectionInput {
46
+ name: string;
47
+ host: string;
48
+ port?: number;
49
+ username: string;
50
+ authMethod?: SshAuthMethod;
51
+ password?: string;
52
+ privateKey?: string;
53
+ privateKeyPath?: string;
54
+ passphrase?: string;
55
+ agentSocket?: string;
56
+ jumpConnectionId?: string | null;
57
+ initialPath?: string;
58
+ keepaliveSeconds?: number;
59
+ strictHostKey?: boolean;
60
+ color?: string;
61
+ }
62
+
63
+ export interface SshHealth {
64
+ ok: boolean;
65
+ latencyMs: number | null;
66
+ /** The remote SSH banner, e.g. `SSH-2.0-OpenSSH_9.6`. */
67
+ serverBanner: string | null;
68
+ /** `uname -sr` output, when the host let us run it. */
69
+ remoteOs: string | null;
70
+ /** SHA256 fingerprint of the key the host presented. */
71
+ hostKeyFingerprint: string | null;
72
+ /** True when the presented key differs from the one Clopen already trusts. */
73
+ hostKeyChanged: boolean;
74
+ /**
75
+ * True when the user disconnected this host. The pool dials on demand, so
76
+ * this is what distinguishes "deliberately closed" from "failed to connect".
77
+ */
78
+ suspended: boolean;
79
+ error: string | null;
80
+ }
@@ -0,0 +1,46 @@
1
+ /**
2
+ * ssh-client — port forwarding types.
3
+ *
4
+ * The three shapes mirror OpenSSH's flags:
5
+ * - `local` (-L) listen locally, forward each connection to `dest` via the host
6
+ * - `remote` (-R) ask the host to listen, forward what arrives back to `dest`
7
+ * - `dynamic` (-D) listen locally as a SOCKS5 proxy, destination per request
8
+ */
9
+
10
+ export type SshForwardType = 'local' | 'remote' | 'dynamic';
11
+
12
+ export interface SshForward {
13
+ id: string;
14
+ connectionId: string;
15
+ name: string;
16
+ type: SshForwardType;
17
+ listenHost: string;
18
+ listenPort: number;
19
+ /** Unused for `dynamic` — the SOCKS client names the destination per request. */
20
+ destHost: string | null;
21
+ destPort: number | null;
22
+ /** Start this forward automatically whenever the connection opens. */
23
+ autoStart: boolean;
24
+ createdAt: string;
25
+ updatedAt: string;
26
+ }
27
+
28
+ export interface SshForwardInput {
29
+ name: string;
30
+ type: SshForwardType;
31
+ listenHost?: string;
32
+ listenPort: number;
33
+ destHost?: string;
34
+ destPort?: number;
35
+ autoStart?: boolean;
36
+ }
37
+
38
+ export interface SshForwardStatus {
39
+ id: string;
40
+ running: boolean;
41
+ /** The port actually bound. Differs from `listenPort` when 0 was requested. */
42
+ boundPort: number | null;
43
+ /** Connections handled since the forward started. */
44
+ connectionCount: number;
45
+ error: string | null;
46
+ }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * ssh-client types barrel export.
3
+ */
4
+
5
+ export * from './connection';
6
+ export * from './sftp';
7
+ export * from './forward';
8
+ export * from './known-host';
@@ -0,0 +1,19 @@
1
+ /**
2
+ * ssh-client — trusted host keys.
3
+ *
4
+ * Clopen trusts on first use: the first key a host presents is recorded, and
5
+ * every later connection must present the same one. A mismatch stops the
6
+ * connection and surfaces both fingerprints so the user can decide.
7
+ */
8
+
9
+ export interface SshKnownHost {
10
+ id: string;
11
+ host: string;
12
+ port: number;
13
+ /** e.g. `ssh-ed25519`, `ssh-rsa`. */
14
+ keyType: string;
15
+ /** `SHA256:…`, the same rendering OpenSSH prints. */
16
+ fingerprint: string;
17
+ addedAt: string;
18
+ lastSeenAt: string | null;
19
+ }
@@ -0,0 +1,141 @@
1
+ /**
2
+ * ssh-client — SFTP browsing types.
3
+ */
4
+
5
+ export type SftpEntryType = 'file' | 'directory' | 'symlink' | 'other';
6
+
7
+ export interface SftpEntry {
8
+ name: string;
9
+ /** Absolute POSIX path on the remote host. */
10
+ path: string;
11
+ type: SftpEntryType;
12
+ size: number;
13
+ /** Unix mode bits, e.g. 0o644. */
14
+ mode: number;
15
+ /** `rwxr-xr-x` rendering of `mode`, built server-side so every view agrees. */
16
+ permissions: string;
17
+ uid: number;
18
+ gid: number;
19
+ /** Modification time, ISO 8601. */
20
+ modifiedAt: string;
21
+ /** For symlinks: what the link resolves to, and the type of the target. */
22
+ linkTarget: string | null;
23
+ targetType: SftpEntryType | null;
24
+ }
25
+
26
+ export interface SftpListing {
27
+ path: string;
28
+ entries: SftpEntry[];
29
+ }
30
+
31
+ export interface SftpFileContent {
32
+ path: string;
33
+ /** Decoded UTF-8 text. Only returned when the file is text and small enough. */
34
+ text: string;
35
+ size: number;
36
+ /** True when the file was truncated to the read limit. */
37
+ truncated: boolean;
38
+ }
39
+
40
+ /**
41
+ * Where a disk figure came from. It matters: on shared hosting the filesystem
42
+ * has hundreds of free gigabytes while the account is capped at a few, so
43
+ * labelling the number is the difference between useful and misleading.
44
+ */
45
+ export type SftpUsageSource = 'account-quota' | 'user-quota' | 'filesystem' | 'unknown';
46
+
47
+ export interface SftpDiskUsage {
48
+ path: string;
49
+ totalBytes: number | null;
50
+ usedBytes: number | null;
51
+ availableBytes: number | null;
52
+ source: SftpUsageSource;
53
+ /** Human label for the source, e.g. "Account quota" or "Filesystem". */
54
+ sourceLabel: string;
55
+ /** Inodes (files) used and allowed, when the source reports them. */
56
+ inodesUsed: number | null;
57
+ inodeLimit: number | null;
58
+ }
59
+
60
+ /** What an archive is written as. */
61
+ export type SftpArchiveFormat = 'zip' | 'tar.gz';
62
+
63
+ /**
64
+ * What to do when the name an item would take at its destination is already
65
+ * used. `skip` leaves the existing entry alone, `overwrite` replaces it, and
66
+ * `rename` gives the arriving item a free name — `notes (2).txt`.
67
+ */
68
+ export type SftpConflictStrategy = 'skip' | 'overwrite' | 'rename';
69
+
70
+ /** One destination name a copy or move would land on top of. */
71
+ export interface SftpConflict {
72
+ /** The source path that would collide. */
73
+ path: string;
74
+ /** The name it would take at the destination. */
75
+ name: string;
76
+ /** The destination path that is already occupied. */
77
+ targetPath: string;
78
+ /** Type of the entry already sitting there, so the prompt can name it. */
79
+ targetType: SftpEntryType;
80
+ }
81
+
82
+ /** Outcome of an operation applied to many paths at once. */
83
+ export interface SftpBulkResult {
84
+ succeeded: string[];
85
+ /** Paths left untouched because something was already there. */
86
+ skipped: string[];
87
+ /** Paths that landed under a free name instead of the one they asked for. */
88
+ renamed: Array<{ path: string; toPath: string }>;
89
+ failed: Array<{ path: string; error: string }>;
90
+ }
91
+
92
+ /** Where an archive was actually written. */
93
+ export interface SftpCompressResult {
94
+ /** The archive's path — not necessarily the requested one, if it was taken. */
95
+ archivePath: string;
96
+ /** True when the requested name was in use and a free one was found. */
97
+ renamed: boolean;
98
+ }
99
+
100
+ /**
101
+ * Where an archive's contents land. `here` unpacks into the current directory,
102
+ * `folder` wraps them in a new one, and `smart` picks between the two by what
103
+ * the archive actually holds — wrapping only archives that would otherwise
104
+ * scatter loose files across the directory.
105
+ */
106
+ export type SftpExtractMode = 'smart' | 'here' | 'folder';
107
+
108
+ /** What an archive would create, read before extracting so the user can choose. */
109
+ export interface SftpArchiveInfo {
110
+ path: string;
111
+ /** Names the archive would create in the destination, top level only. */
112
+ topLevelNames: string[];
113
+ /** True when the archive holds more entries than the listing read. */
114
+ truncated: boolean;
115
+ /** Wrapper folder name to offer: the archive's name without its suffix. */
116
+ suggestedFolderName: string;
117
+ /** Top-level names that are already taken in the destination directory. */
118
+ conflictingNames: string[];
119
+ /** What `smart` resolves to for this archive. */
120
+ smartMode: 'here' | 'folder';
121
+ }
122
+
123
+ /** How an archive is unpacked. */
124
+ export interface SftpExtractOptions {
125
+ mode: SftpExtractMode;
126
+ /** Wrapper folder name for `folder` mode. Defaults to the archive's stem. */
127
+ folderName?: string;
128
+ /**
129
+ * Applied to the wrapper folder in `folder` mode and to the individual files
130
+ * in `here` mode, where `rename` has no meaning and is refused — tar and
131
+ * unzip can keep or replace what is there, but cannot rename around it.
132
+ */
133
+ onConflict: SftpConflictStrategy;
134
+ }
135
+
136
+ export interface SftpExtractResult {
137
+ /** The directory the contents actually landed in. */
138
+ destination: string;
139
+ /** True when a wrapper folder was created for them. */
140
+ createdFolder: boolean;
141
+ }
@@ -46,6 +46,8 @@ export type LogLabel =
46
46
  | 'tunnel'
47
47
  | 'remote-access'
48
48
  | 'db-client'
49
+ | 'ssh'
50
+ | 'ports'
49
51
 
50
52
  // User
51
53
  | 'user'