@myrialabs/clopen 0.4.31 → 0.4.33

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 (114) hide show
  1. package/backend/auth/permissions.test.ts +0 -1
  2. package/backend/auth/permissions.ts +0 -4
  3. package/backend/chat/stream-manager.ts +31 -12
  4. package/backend/database/migrations/068_create_engine_config_revision.test.ts +121 -0
  5. package/backend/database/migrations/068_create_engine_config_revision.ts +117 -0
  6. package/backend/database/migrations/069_create_ssh_client_tables.ts +116 -0
  7. package/backend/database/migrations/index.ts +14 -0
  8. package/backend/database/queries/db-client-connection-queries.ts +7 -2
  9. package/backend/database/queries/file-audit-log-queries.ts +1 -0
  10. package/backend/database/queries/index.ts +3 -0
  11. package/backend/database/queries/ssh-connection-queries.ts +244 -0
  12. package/backend/database/queries/ssh-known-host-queries.ts +67 -0
  13. package/backend/database/queries/ssh-port-forward-queries.ts +113 -0
  14. package/backend/db-client/connection-manager.ts +8 -1
  15. package/backend/engine/README.md +16 -0
  16. package/backend/engine/adapters/claude/stream.ts +89 -49
  17. package/backend/engine/adapters/cline/stream.ts +62 -24
  18. package/backend/engine/adapters/codex/message-converter.ts +18 -12
  19. package/backend/engine/adapters/codex/patch-rollout.test.ts +88 -0
  20. package/backend/engine/adapters/codex/patch-rollout.ts +120 -109
  21. package/backend/engine/adapters/codex/stream.ts +78 -22
  22. package/backend/engine/adapters/copilot/stream.ts +97 -53
  23. package/backend/engine/adapters/cursor/stream.ts +75 -35
  24. package/backend/engine/adapters/opencode/server.ts +511 -134
  25. package/backend/engine/adapters/opencode/stream.ts +131 -79
  26. package/backend/engine/adapters/pi/stream.ts +63 -24
  27. package/backend/engine/adapters/qwen/stream.ts +92 -59
  28. package/backend/engine/adapters/run-registry.test.ts +75 -0
  29. package/backend/engine/adapters/run-registry.ts +63 -0
  30. package/backend/engine/config-revision.ts +150 -0
  31. package/backend/engine/docs/adapter-contract.md +47 -9
  32. package/backend/engine/docs/adding-an-engine.md +8 -0
  33. package/backend/engine/docs/frontend-and-chat.md +39 -0
  34. package/backend/engine/docs/lessons-learned.md +70 -0
  35. package/backend/engine/docs/quick-reference.md +3 -1
  36. package/backend/engine/hot-reload.ts +99 -0
  37. package/backend/engine/index.ts +96 -24
  38. package/backend/engine/types.ts +17 -5
  39. package/backend/files/file-watcher.ts +283 -51
  40. package/backend/files/git-events.test.ts +110 -0
  41. package/backend/git/git-dirs.test.ts +132 -0
  42. package/backend/git/git-dirs.ts +0 -0
  43. package/backend/git/git-executor.ts +22 -3
  44. package/backend/git/git-service.ts +1 -1
  45. package/backend/git/nested-repos.test.ts +224 -0
  46. package/backend/git/nested-repos.ts +386 -0
  47. package/backend/http/audio.ts +5 -32
  48. package/backend/http/bearer-auth.ts +47 -0
  49. package/backend/http/files-download.test.ts +146 -0
  50. package/backend/http/files-download.ts +109 -0
  51. package/backend/http/files-upload.ts +3 -29
  52. package/backend/http/ssh-sftp.ts +133 -0
  53. package/backend/index.ts +23 -2
  54. package/backend/mcp/README.md +34 -6
  55. package/backend/mcp/index.ts +8 -8
  56. package/backend/mcp/internal/config.ts +69 -19
  57. package/backend/mcp/internal/project-context.test.ts +40 -0
  58. package/backend/mcp/internal/project-context.ts +80 -7
  59. package/backend/mcp/internal/remote-server.test.ts +17 -2
  60. package/backend/mcp/internal/remote-server.ts +36 -3
  61. package/backend/mcp/internal/servers/helper.ts +48 -18
  62. package/backend/preview/browser/browser-video-capture.ts +51 -4
  63. package/backend/snapshot/gitignore.ts +10 -174
  64. package/backend/ssh/client-pool.ts +196 -0
  65. package/backend/ssh/connect.ts +375 -0
  66. package/backend/ssh/disk-usage.test.ts +134 -0
  67. package/backend/ssh/disk-usage.ts +214 -0
  68. package/backend/ssh/forwards.ts +309 -0
  69. package/backend/ssh/health.ts +141 -0
  70. package/backend/ssh/known-hosts.ts +96 -0
  71. package/backend/ssh/pty-backend.ts +215 -0
  72. package/backend/ssh/ptykit.ts +66 -0
  73. package/backend/ssh/sftp.test.ts +242 -0
  74. package/backend/ssh/sftp.ts +967 -0
  75. package/backend/ssh/socks5.test.ts +167 -0
  76. package/backend/ssh/socks5.ts +164 -0
  77. package/backend/ssh/tunnel.ts +87 -0
  78. package/backend/ws/chat/stream.ts +24 -0
  79. package/backend/ws/db-client/connections.ts +1 -0
  80. package/backend/ws/engine/codex/accounts.ts +0 -12
  81. package/backend/ws/engine/copilot/accounts.ts +0 -10
  82. package/backend/ws/engine/cursor/accounts.ts +0 -10
  83. package/backend/ws/engine/index.ts +17 -2
  84. package/backend/ws/engine/opencode/providers.ts +0 -52
  85. package/backend/ws/files/read.ts +1 -1
  86. package/backend/ws/files/watch.ts +5 -1
  87. package/backend/ws/git/conflict.ts +1 -1
  88. package/backend/ws/git/diff.ts +1 -1
  89. package/backend/ws/git/staging.ts +1 -1
  90. package/backend/ws/git/status.ts +1 -1
  91. package/backend/ws/index.ts +4 -0
  92. package/backend/ws/ssh/access.ts +31 -0
  93. package/backend/ws/ssh/connections.ts +224 -0
  94. package/backend/ws/ssh/forwards.ts +109 -0
  95. package/backend/ws/ssh/index.ts +18 -0
  96. package/backend/ws/ssh/sftp.ts +259 -0
  97. package/backend/ws/ssh/tunnel.ts +93 -0
  98. package/dist/assets/{index-DYwQ5bP8.js → index-BF4buYmI.js} +1 -1
  99. package/dist/assets/{index-DUc5T21e.js → index-BW0DA8NV.js} +1 -1
  100. package/dist/assets/main-BbwWLJRN.js +1057 -0
  101. package/dist/assets/main-CCvRMXlP.css +1 -0
  102. package/dist/index.html +2 -2
  103. package/package.json +1 -1
  104. package/shared/types/database/schema.ts +49 -0
  105. package/shared/types/db-client/connection.ts +6 -0
  106. package/shared/types/ssh/connection.ts +80 -0
  107. package/shared/types/ssh/forward.ts +46 -0
  108. package/shared/types/ssh/index.ts +8 -0
  109. package/shared/types/ssh/known-host.ts +19 -0
  110. package/shared/types/ssh/sftp.ts +141 -0
  111. package/shared/utils/logger.ts +1 -0
  112. package/backend/ws/engine/restart.ts +0 -54
  113. package/dist/assets/main-VgdjTBLR.css +0 -1
  114. package/dist/assets/main-r0iv2PDz.js +0 -1044
@@ -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,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,7 @@ export type LogLabel =
46
46
  | 'tunnel'
47
47
  | 'remote-access'
48
48
  | 'db-client'
49
+ | 'ssh'
49
50
 
50
51
  // User
51
52
  | 'user'
@@ -1,54 +0,0 @@
1
- /**
2
- * Restart-all-engines handler.
3
- *
4
- * Disposes every cached engine instance (global + per-project) and the shared
5
- * OpenCode server/client so the next chat turn re-initialises from scratch.
6
- * Needed after changing MCP servers (install/uninstall/enable/disable/config)
7
- * or other global engine config — the engines read that config when they
8
- * (re)initialise, not mid-session.
9
- */
10
-
11
- import { t } from 'elysia';
12
- import { createRouter } from '$shared/utils/ws-server';
13
- import { debug } from '$shared/utils/logger';
14
- import { disposeAllEngines } from '../../engine';
15
- import { disposeOpenCodeClient } from '../../engine/adapters/opencode/server';
16
- import { streamManager } from '../../chat';
17
-
18
- export const engineRestartRouter = createRouter()
19
- .http('engine:restart-all', {
20
- data: t.Object({
21
- force: t.Optional(t.Boolean()),
22
- }),
23
- response: t.Object({
24
- success: t.Boolean(),
25
- activeChats: t.Optional(t.Number()),
26
- needsConfirmation: t.Optional(t.Boolean()),
27
- })
28
- }, async ({ data }) => {
29
- const activeStreams = streamManager.getActiveStreams();
30
-
31
- // Restarting kills in-flight chats — ask first unless forced.
32
- if (activeStreams.length > 0 && !data.force) {
33
- return { success: false, activeChats: activeStreams.length, needsConfirmation: true };
34
- }
35
-
36
- if (activeStreams.length > 0) {
37
- debug.log('engine', `Force-aborting ${activeStreams.length} active stream(s) before restart-all`);
38
- for (const stream of activeStreams) {
39
- try {
40
- await streamManager.cancelStream(stream.streamId);
41
- } catch (error) {
42
- debug.warn('engine', `Failed to abort stream ${stream.streamId}:`, error);
43
- }
44
- }
45
- }
46
-
47
- await disposeAllEngines();
48
- // OpenCode keeps a separate persistent server/client beyond the engine
49
- // instance — purge it too so it respawns with fresh MCP config.
50
- await disposeOpenCodeClient(true);
51
-
52
- debug.log('engine', 'All engines disposed (restart-all). Will re-initialize on next use.');
53
- return { success: true };
54
- });