@myrialabs/clopen 0.4.39 → 0.4.41

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 (173) hide show
  1. package/.env.example +1 -1
  2. package/backend/artifacts/detect.ts +15 -3
  3. package/backend/artifacts/generate.ts +2 -2
  4. package/backend/artifacts/index.ts +12 -4
  5. package/backend/artifacts/markers.ts +24 -1
  6. package/backend/artifacts/matrix.ts +47 -3
  7. package/backend/artifacts/sync.test.ts +3 -3
  8. package/backend/artifacts/sync.ts +8 -20
  9. package/backend/artifacts/types.ts +9 -3
  10. package/backend/auth/permissions.ts +29 -11
  11. package/backend/auth/session-cleanup.ts +10 -1
  12. package/backend/auth/tokens.ts +9 -1
  13. package/backend/chat/stream-manager.ts +42 -0
  14. package/backend/database/crypto/secret-columns.ts +5 -1
  15. package/backend/database/migrations/078_create_worktree_branch_tables.ts +158 -0
  16. package/backend/database/migrations/079_merge_commands_into_skills.ts +222 -0
  17. package/backend/database/migrations/080_create_file_shares.ts +111 -0
  18. package/backend/database/migrations/081_create_push_subscriptions.ts +32 -0
  19. package/backend/database/migrations/index.ts +28 -0
  20. package/backend/database/queries/file-share-queries.ts +163 -0
  21. package/backend/database/queries/index.ts +12 -4
  22. package/backend/database/queries/profile-queries.ts +5 -3
  23. package/backend/database/queries/push-subscription-queries.test.ts +90 -0
  24. package/backend/database/queries/push-subscription-queries.ts +99 -0
  25. package/backend/database/queries/skill-queries.ts +96 -18
  26. package/backend/database/queries/worktree-branch-queries.ts +331 -0
  27. package/backend/db-client/cloning.test.ts +161 -0
  28. package/backend/db-client/cloning.ts +672 -0
  29. package/backend/db-client/connection-url.test.ts +117 -0
  30. package/backend/db-client/connection-url.ts +126 -0
  31. package/backend/db-client/drivers/mongodb.ts +2 -14
  32. package/backend/db-client/drivers/mysql.ts +2 -8
  33. package/backend/db-client/drivers/postgres.ts +10 -13
  34. package/backend/db-client/drivers/redis.ts +2 -6
  35. package/backend/db-client/env/detect.ts +438 -0
  36. package/backend/db-client/env/diff.ts +94 -0
  37. package/backend/db-client/env/env.test.ts +574 -0
  38. package/backend/db-client/env/index.ts +15 -0
  39. package/backend/db-client/env/naming.ts +202 -0
  40. package/backend/db-client/env/service.ts +487 -0
  41. package/backend/db-client/integrations/index.ts +7 -0
  42. package/backend/db-client/integrations/links.ts +41 -10
  43. package/backend/db-client/providers/neon/adapter.ts +522 -0
  44. package/backend/db-client/providers/neon/api-types.ts +182 -0
  45. package/backend/db-client/providers/neon/client.ts +298 -0
  46. package/backend/db-client/providers/neon/endpoints.test.ts +201 -0
  47. package/backend/db-client/providers/neon/endpoints.ts +314 -0
  48. package/backend/db-client/providers/neon/list.test.ts +181 -0
  49. package/backend/db-client/providers/supabase/adapter.ts +25 -2
  50. package/backend/db-client/providers/types.ts +57 -0
  51. package/backend/engine/adapters/claude/stream.ts +2 -1
  52. package/backend/engine/adapters/cline/stream.ts +3 -3
  53. package/backend/engine/adapters/codex/stream.ts +3 -3
  54. package/backend/engine/adapters/copilot/stream.ts +3 -3
  55. package/backend/engine/adapters/cursor/stream.ts +25 -3
  56. package/backend/engine/adapters/opencode/stream.ts +4 -6
  57. package/backend/engine/adapters/pi/stream.ts +2 -2
  58. package/backend/engine/adapters/qwen/stream.ts +2 -2
  59. package/backend/engine/artifact-sync.ts +26 -20
  60. package/backend/engine/docs/artifacts.md +81 -22
  61. package/backend/engine/docs/quick-reference.md +2 -1
  62. package/backend/engine/resolve-model.test.ts +108 -0
  63. package/backend/engine/resolve-model.ts +53 -10
  64. package/backend/engine/structured-helpers.ts +22 -0
  65. package/backend/env-files/discovery.ts +48 -0
  66. package/backend/env-files/edit.ts +213 -0
  67. package/backend/env-files/env-files.test.ts +515 -0
  68. package/backend/env-files/git.ts +27 -0
  69. package/backend/env-files/index.ts +44 -0
  70. package/backend/env-files/keys.ts +69 -0
  71. package/backend/env-files/parse.ts +157 -0
  72. package/backend/env-files/write.ts +229 -0
  73. package/backend/files/file-shares.ts +369 -0
  74. package/backend/files/path-browsing.ts +27 -21
  75. package/backend/http/files-shared.test.ts +505 -0
  76. package/backend/http/files-shared.ts +351 -0
  77. package/backend/http/push.ts +150 -0
  78. package/backend/index.ts +8 -0
  79. package/backend/instructions/index.ts +1 -1
  80. package/backend/instructions/sync.ts +30 -6
  81. package/backend/integrations/health.ts +18 -4
  82. package/backend/integrations/projections/types.ts +9 -2
  83. package/backend/integrations/registry/index.ts +3 -0
  84. package/backend/integrations/registry/providers/context7.ts +1 -0
  85. package/backend/integrations/registry/providers/firecrawl.ts +1 -0
  86. package/backend/integrations/registry/providers/github.ts +1 -0
  87. package/backend/integrations/registry/providers/neon.ts +55 -0
  88. package/backend/integrations/registry/providers/supabase.ts +1 -0
  89. package/backend/integrations/registry/providers/vercel.ts +1 -0
  90. package/backend/integrations/registry/types.ts +2 -0
  91. package/backend/memory/compose.ts +2 -2
  92. package/backend/memory/consolidate.ts +2 -2
  93. package/backend/memory/extract/episodic.ts +2 -2
  94. package/backend/memory/judge.ts +2 -2
  95. package/backend/profiles/service.ts +7 -6
  96. package/backend/push/sender.ts +172 -0
  97. package/backend/push/tags.ts +25 -0
  98. package/backend/push/vapid-keys.ts +77 -0
  99. package/backend/push/webpush-crypto.test.ts +200 -0
  100. package/backend/push/webpush-crypto.ts +231 -0
  101. package/backend/skills/detect.ts +28 -0
  102. package/backend/skills/index.ts +22 -4
  103. package/backend/skills/invoke.test.ts +114 -0
  104. package/backend/skills/invoke.ts +222 -0
  105. package/backend/skills/service.ts +194 -44
  106. package/backend/skills/spec.ts +35 -0
  107. package/backend/skills/sync.ts +85 -55
  108. package/backend/subagents/detect.ts +2 -3
  109. package/backend/subagents/sync.ts +15 -8
  110. package/backend/work/pull-requests.ts +2 -2
  111. package/backend/work/start-work.ts +4 -0
  112. package/backend/worktrees/branching/engine.ts +557 -0
  113. package/backend/worktrees/branching/index.ts +56 -0
  114. package/backend/worktrees/branching/naming.test.ts +118 -0
  115. package/backend/worktrees/branching/naming.ts +97 -0
  116. package/backend/worktrees/branching/projector.test.ts +229 -0
  117. package/backend/worktrees/branching/projector.ts +139 -0
  118. package/backend/worktrees/branching/providers/neon.ts +220 -0
  119. package/backend/worktrees/branching/registry.ts +27 -0
  120. package/backend/worktrees/branching/service.ts +620 -0
  121. package/backend/worktrees/branching/suggest.test.ts +154 -0
  122. package/backend/worktrees/branching/suggest.ts +202 -0
  123. package/backend/worktrees/branching/types.ts +88 -0
  124. package/backend/worktrees/index.ts +7 -0
  125. package/backend/worktrees/service.ts +48 -1
  126. package/backend/ws/chat/stream.ts +100 -8
  127. package/backend/ws/db-client/env.ts +142 -0
  128. package/backend/ws/db-client/index.ts +2 -0
  129. package/backend/ws/files/index.ts +4 -0
  130. package/backend/ws/files/share.ts +95 -0
  131. package/backend/ws/git/branch-name.ts +2 -2
  132. package/backend/ws/git/commit-message.ts +2 -2
  133. package/backend/ws/index.ts +3 -4
  134. package/backend/ws/profiles/crud.ts +2 -3
  135. package/backend/ws/projects/index.ts +6 -1
  136. package/backend/ws/projects/info.ts +70 -6
  137. package/backend/ws/projects/overview.test.ts +108 -0
  138. package/backend/ws/projects/overview.ts +300 -0
  139. package/backend/ws/skills/catalog.ts +5 -1
  140. package/backend/ws/skills/crud.ts +128 -22
  141. package/backend/ws/skills/index.ts +4 -1
  142. package/backend/ws/system/device-info.ts +307 -76
  143. package/backend/ws/user/crud.ts +12 -3
  144. package/backend/ws/worktrees/branching.ts +212 -0
  145. package/backend/ws/worktrees/crud.ts +33 -7
  146. package/backend/ws/worktrees/index.ts +14 -0
  147. package/dist/assets/{index-C8Gi-b6U.js → index-CeNKKSDR.js} +1 -1
  148. package/dist/assets/{index-BrF6nqld.js → index-DW89566K.js} +1 -1
  149. package/dist/assets/main-Cy5DXWPT.js +1207 -0
  150. package/dist/assets/main-DJKj_4By.css +1 -0
  151. package/dist/index.html +7 -2
  152. package/dist/sw.js +112 -0
  153. package/package.json +1 -1
  154. package/shared/constants/engine-tools.ts +31 -6
  155. package/shared/constants/notification-messages.ts +142 -0
  156. package/shared/constants/tool-icons.ts +6 -2
  157. package/shared/types/db-client/env.ts +192 -0
  158. package/shared/types/db-client/index.ts +1 -0
  159. package/shared/types/db-client/integrations.ts +30 -0
  160. package/shared/types/integrations.ts +9 -0
  161. package/shared/types/unified/stream.ts +7 -0
  162. package/shared/types/worktree-branching.ts +315 -0
  163. package/shared/utils/logger.ts +1 -0
  164. package/backend/commands/detect.ts +0 -25
  165. package/backend/commands/index.ts +0 -9
  166. package/backend/commands/service.ts +0 -178
  167. package/backend/commands/store.ts +0 -45
  168. package/backend/commands/sync.ts +0 -94
  169. package/backend/database/queries/command-queries.ts +0 -82
  170. package/backend/ws/commands/crud.ts +0 -157
  171. package/backend/ws/commands/index.ts +0 -8
  172. package/dist/assets/main-Bd3gb79F.css +0 -1
  173. package/dist/assets/main-Bo1hD7mt.js +0 -1191
@@ -112,7 +112,10 @@ export const crudHandler = createRouter()
112
112
  unreadSessions: t.Union([t.Any(), t.Null()]),
113
113
  todoPanelState: t.Union([t.Any(), t.Null()]),
114
114
  projectOrder: t.Union([t.Array(t.String()), t.Null()]),
115
- commandUsage: t.Union([t.Any(), t.Null()])
115
+ pinnedProjectIds: t.Union([t.Array(t.String()), t.Null()]),
116
+ archivedProjectIds: t.Union([t.Array(t.String()), t.Null()]),
117
+ commandUsage: t.Union([t.Any(), t.Null()]),
118
+ fileShareDefaults: t.Union([t.Any(), t.Null()])
116
119
  })
117
120
  }, async ({ conn }) => {
118
121
  const userId = ws.getUserId(conn);
@@ -123,7 +126,10 @@ export const crudHandler = createRouter()
123
126
  const unreadSessions = getUserState(userId, 'unreadSessions');
124
127
  const todoPanelState = getUserState(userId, 'todoPanelState');
125
128
  const projectOrder = getUserState(userId, 'projectOrder');
129
+ const pinnedProjectIds = getUserState(userId, 'pinnedProjectIds');
130
+ const archivedProjectIds = getUserState(userId, 'archivedProjectIds');
126
131
  const commandUsage = getUserState(userId, 'commandUsage');
132
+ const fileShareDefaults = getUserState(userId, 'fileShareDefaults');
127
133
 
128
134
  debug.log('user', `Restored state for ${userId}:`, {
129
135
  currentProjectId,
@@ -140,7 +146,10 @@ export const crudHandler = createRouter()
140
146
  unreadSessions: unreadSessions ?? null,
141
147
  todoPanelState: todoPanelState ?? null,
142
148
  projectOrder: Array.isArray(projectOrder) ? projectOrder : null,
143
- commandUsage: commandUsage ?? null
149
+ pinnedProjectIds: Array.isArray(pinnedProjectIds) ? pinnedProjectIds : null,
150
+ archivedProjectIds: Array.isArray(archivedProjectIds) ? archivedProjectIds : null,
151
+ commandUsage: commandUsage ?? null,
152
+ fileShareDefaults: fileShareDefaults ?? null
144
153
  };
145
154
  })
146
155
 
@@ -157,7 +166,7 @@ export const crudHandler = createRouter()
157
166
  const userId = ws.getUserId(conn);
158
167
 
159
168
  // Validate allowed keys to prevent arbitrary data storage
160
- const allowedKeys = ['currentProjectId', 'lastView', 'settings', 'unreadSessions', 'todoPanelState', 'projectOrder', 'commandUsage'];
169
+ const allowedKeys = ['currentProjectId', 'lastView', 'settings', 'unreadSessions', 'todoPanelState', 'projectOrder', 'pinnedProjectIds', 'archivedProjectIds', 'commandUsage', 'fileShareDefaults'];
161
170
  if (!allowedKeys.includes(data.key)) {
162
171
  throw new Error(`Invalid state key: ${data.key}. Allowed: ${allowedKeys.join(', ')}`);
163
172
  }
@@ -0,0 +1,212 @@
1
+ /**
2
+ * Worktree database branching routes.
3
+ *
4
+ * worktrees:branching-state sources, binding, dotenv files, branches
5
+ * worktrees:branch-suggest the binding this project's own `.env` implies
6
+ * worktrees:branch-parents databases one source can copy from
7
+ * worktrees:branching-save point this project at a parent database
8
+ * worktrees:branching-clear stop branching — existing branches are left alone
9
+ * worktrees:branch-rewrite-env retry the dotenv write
10
+ * worktrees:branch-orphans branches with no live worktree, both kinds
11
+ * worktrees:branch-delete destroy an orphan at the provider
12
+ * worktrees:branch-forget drop the row, leave the remote branch alone
13
+ * worktrees:branch-delete-remote destroy a branch the sweep found untracked
14
+ *
15
+ * ACCESS IS SPLIT, deliberately, and enforced in two places. Every route here
16
+ * takes project access the way `worktrees:create` and `git:push` do — they act
17
+ * inside one project. The DESTROYING ones are additionally listed in
18
+ * `backend/auth/permissions.ts` as admin-only, the way `db-client:link` is:
19
+ * deleting one destroys a real database.
20
+ *
21
+ * Choosing a SOURCE is gated per source rather than per route, because the two
22
+ * kinds belong to different people. An integration account belongs to the
23
+ * install and spends its quota, so only an admin is shown one; a DB Client
24
+ * connection belongs to whoever saved it, and refusing a member their own would
25
+ * make the whole feature admin-only for no reason that survives being stated.
26
+ * `listBranchSources` decides, and `requireSource` enforces.
27
+ */
28
+
29
+ import { t } from 'elysia';
30
+ import { createRouter } from '$shared/utils/ws-server';
31
+ import { initializeDatabase } from '../../database';
32
+ import { worktreeBranching } from '../../worktrees';
33
+ import { ws } from '$backend/utils/ws';
34
+ import { requireCurrentProjectAccess } from '../access';
35
+
36
+ /**
37
+ * Who is asking.
38
+ *
39
+ * Passed into every source-facing call rather than checked here, because the
40
+ * rule is not "admin or not": an integration account belongs to the install and
41
+ * is admin-only, while a DB Client connection belongs to whoever saved it. One
42
+ * helper in the service answers both — see `requireSource`.
43
+ */
44
+ function principalOf(conn: Parameters<typeof ws.getUserId>[0]) {
45
+ return { userId: ws.getUserId(conn), isAdmin: ws.getRole(conn) === 'admin' };
46
+ }
47
+
48
+ /**
49
+ * Tell everyone in the project that its branches or binding moved.
50
+ *
51
+ * The broadcast state is built for an ADMIN. Every recipient re-reads the
52
+ * source list through their own request anyway, and building one payload per
53
+ * viewer here would make an announcement O(viewers) round trips into the
54
+ * database for a list that is about to be refetched.
55
+ */
56
+ async function announce(projectId: string): Promise<void> {
57
+ ws.emit.project(projectId, 'worktrees:branching-changed', {
58
+ projectId,
59
+ state: await worktreeBranching.state(projectId, { userId: '', isAdmin: true })
60
+ });
61
+ }
62
+
63
+ export const worktreeBranchingHandler = createRouter()
64
+ .http('worktrees:branching-state', {
65
+ data: t.Object({}),
66
+ response: t.Any()
67
+ }, async ({ conn }) => {
68
+ await initializeDatabase();
69
+ const { projectId } = requireCurrentProjectAccess(conn);
70
+ return worktreeBranching.state(projectId, principalOf(conn));
71
+ })
72
+
73
+ /**
74
+ * The binding this project would get if it asked for one.
75
+ *
76
+ * Its own route rather than a field on `branching-state`, because it reads
77
+ * the project's dotenv files from disk and the state route is on the path of
78
+ * every worktree dialog open.
79
+ */
80
+ .http('worktrees:branch-suggest', {
81
+ data: t.Object({}),
82
+ response: t.Nullable(t.Any())
83
+ }, async ({ conn }) => {
84
+ await initializeDatabase();
85
+ const { projectId } = requireCurrentProjectAccess(conn);
86
+ return worktreeBranching.suggest(projectId);
87
+ })
88
+
89
+ .http('worktrees:branch-parents', {
90
+ data: t.Object({
91
+ sourceKind: t.Union([t.Literal('account'), t.Literal('connection')]),
92
+ sourceId: t.String({ minLength: 1 })
93
+ }),
94
+ response: t.Array(t.Any())
95
+ }, async ({ data, conn }) => {
96
+ requireCurrentProjectAccess(conn);
97
+ return worktreeBranching.parents(data, principalOf(conn));
98
+ })
99
+
100
+ .http('worktrees:branching-save', {
101
+ data: t.Object({
102
+ sourceKind: t.Union([t.Literal('account'), t.Literal('connection')]),
103
+ sourceId: t.String({ minLength: 1 }),
104
+ parentRef: t.String({ minLength: 1 }),
105
+ parentName: t.String(),
106
+ config: t.Object({
107
+ envVar: t.Optional(t.String()),
108
+ envFile: t.Optional(t.String()),
109
+ autoCreate: t.Optional(t.Boolean()),
110
+ pooled: t.Optional(t.Boolean()),
111
+ dataMode: t.Optional(
112
+ t.Union([t.Literal('schema-data'), t.Literal('schema'), t.Literal('empty')])
113
+ )
114
+ })
115
+ }),
116
+ response: t.Any()
117
+ }, async ({ data, conn }) => {
118
+ await initializeDatabase();
119
+ const { projectId } = requireCurrentProjectAccess(conn);
120
+
121
+ const binding = worktreeBranching.saveBinding({ projectId, ...data }, principalOf(conn));
122
+ await announce(projectId);
123
+ return binding;
124
+ })
125
+
126
+ .http('worktrees:branching-clear', {
127
+ data: t.Object({}),
128
+ response: t.Object({ success: t.Boolean() })
129
+ }, async ({ conn }) => {
130
+ const { projectId } = requireCurrentProjectAccess(conn);
131
+
132
+ worktreeBranching.clearBinding(projectId);
133
+ await announce(projectId);
134
+ return { success: true };
135
+ })
136
+
137
+ .http('worktrees:branch-rewrite-env', {
138
+ data: t.Object({ branchId: t.String({ minLength: 1 }) }),
139
+ response: t.Nullable(t.Any())
140
+ }, async ({ data, conn }) => {
141
+ const { projectId } = requireCurrentProjectAccess(conn);
142
+ const branch = await worktreeBranching.rewriteEnv(data.branchId);
143
+ await announce(projectId);
144
+ return branch;
145
+ })
146
+
147
+ /**
148
+ * Both kinds of leak in one answer.
149
+ *
150
+ * Tracked orphans come from the database and always succeed. The remote sweep
151
+ * talks to the provider and can fail, so it is reported as `sweepError`
152
+ * rather than taking the whole route down with it: a list that says "no
153
+ * untracked branches" because it could not look is exactly the false
154
+ * reassurance this feature exists to avoid.
155
+ */
156
+ .http('worktrees:branch-orphans', {
157
+ data: t.Object({}),
158
+ response: t.Object({
159
+ tracked: t.Array(t.Any()),
160
+ untracked: t.Array(t.Any()),
161
+ sweepError: t.Nullable(t.String())
162
+ })
163
+ }, async ({ conn }) => {
164
+ const { projectId } = requireCurrentProjectAccess(conn);
165
+
166
+ let untracked: unknown[] = [];
167
+ let sweepError: string | null = null;
168
+ try {
169
+ untracked = await worktreeBranching.unknownBranches(projectId);
170
+ } catch (error) {
171
+ sweepError = error instanceof Error ? error.message : String(error);
172
+ }
173
+
174
+ return { tracked: worktreeBranching.orphans(), untracked, sweepError };
175
+ })
176
+
177
+ .http('worktrees:branch-delete', {
178
+ data: t.Object({ branchId: t.String({ minLength: 1 }) }),
179
+ response: t.Object({ success: t.Boolean() })
180
+ }, async ({ data, conn }) => {
181
+ const { projectId } = requireCurrentProjectAccess(conn);
182
+
183
+ await worktreeBranching.deleteOrphan(data.branchId);
184
+ await announce(projectId);
185
+ return { success: true };
186
+ })
187
+
188
+ .http('worktrees:branch-forget', {
189
+ data: t.Object({ branchId: t.String({ minLength: 1 }) }),
190
+ response: t.Object({ success: t.Boolean() })
191
+ }, async ({ data, conn }) => {
192
+ const { projectId } = requireCurrentProjectAccess(conn);
193
+
194
+ worktreeBranching.forgetOrphan(data.branchId);
195
+ await announce(projectId);
196
+ return { success: true };
197
+ })
198
+
199
+ .http('worktrees:branch-delete-remote', {
200
+ data: t.Object({
201
+ sourceKind: t.Union([t.Literal('account'), t.Literal('connection')]),
202
+ sourceId: t.String({ minLength: 1 }),
203
+ parentRef: t.String({ minLength: 1 }),
204
+ branchRef: t.String({ minLength: 1 })
205
+ }),
206
+ response: t.Object({ success: t.Boolean() })
207
+ }, async ({ data, conn }) => {
208
+ requireCurrentProjectAccess(conn);
209
+
210
+ await worktreeBranching.deleteUnknown(data);
211
+ return { success: true };
212
+ });
@@ -14,7 +14,8 @@ import {
14
14
  countPendingChanges,
15
15
  createWorktree,
16
16
  getWorktreeDiskUsage,
17
- removeWorktree
17
+ removeWorktree,
18
+ worktreeBranching
18
19
  } from '../../worktrees';
19
20
  import { ws } from '$backend/utils/ws';
20
21
  import { debug } from '$shared/utils/logger';
@@ -32,7 +33,9 @@ export const worktreeSchema = t.Object({
32
33
  created_at: t.String(),
33
34
  last_opened_at: t.Optional(t.String()),
34
35
  last_applied_at: t.Optional(t.String()),
35
- sessionCount: t.Number()
36
+ sessionCount: t.Number(),
37
+ /** The database branch this worktree owns, when the project is branching. */
38
+ branch: t.Optional(t.Any())
36
39
  });
37
40
 
38
41
  /**
@@ -52,7 +55,11 @@ export function serializeWorktree(worktree: Worktree) {
52
55
  created_at: worktree.created_at,
53
56
  last_opened_at: worktree.last_opened_at ?? undefined,
54
57
  last_applied_at: worktree.last_applied_at ?? undefined,
55
- sessionCount: worktreeQueries.countSessions(worktree.id)
58
+ sessionCount: worktreeQueries.countSessions(worktree.id),
59
+ // Carried on the row rather than fetched per worktree: the switcher shows
60
+ // it on every line, and a second round trip per worktree to render one
61
+ // badge would make opening the menu cost a request per tree.
62
+ branch: worktreeBranching.forWorktree(worktree.id) ?? undefined
56
63
  };
57
64
  }
58
65
 
@@ -75,12 +82,27 @@ export const worktreeCrudHandler = createRouter()
75
82
 
76
83
  .http('worktrees:create', {
77
84
  data: t.Object({
78
- name: t.String({ minLength: 1, maxLength: 80 })
85
+ name: t.String({ minLength: 1, maxLength: 80 }),
86
+ /** Skip this project's database branch for this one worktree. */
87
+ skipBranch: t.Optional(t.Boolean()),
88
+ dataMode: t.Optional(
89
+ t.Union([t.Literal('schema-data'), t.Literal('schema'), t.Literal('empty')])
90
+ )
79
91
  }),
80
92
  response: t.Object({
81
93
  worktree: worktreeSchema,
82
94
  fileCount: t.Number(),
83
- carriedIgnoredFiles: t.Boolean()
95
+ carriedIgnoredFiles: t.Boolean(),
96
+ branch: t.Nullable(t.Any()),
97
+ /**
98
+ * Why no branch was cut, when one was expected.
99
+ *
100
+ * Part of a SUCCESSFUL response on purpose. The worktree is what the
101
+ * user asked for and it exists; a provider outage or a branch limit is
102
+ * something they need to know rather than a reason to report the whole
103
+ * action as failed.
104
+ */
105
+ branchError: t.Nullable(t.String())
84
106
  })
85
107
  }, async ({ data, conn }) => {
86
108
  const { projectId, userId } = requireCurrentProjectAccess(conn);
@@ -88,7 +110,9 @@ export const worktreeCrudHandler = createRouter()
88
110
  const result = await createWorktree({
89
111
  projectId,
90
112
  name: data.name,
91
- createdBy: userId
113
+ createdBy: userId,
114
+ skipBranch: data.skipBranch,
115
+ dataMode: data.dataMode
92
116
  });
93
117
 
94
118
  broadcastWorktrees(projectId);
@@ -96,7 +120,9 @@ export const worktreeCrudHandler = createRouter()
96
120
  return {
97
121
  worktree: serializeWorktree(result.worktree),
98
122
  fileCount: result.fileCount,
99
- carriedIgnoredFiles: result.carriedIgnoredFiles
123
+ carriedIgnoredFiles: result.carriedIgnoredFiles,
124
+ branch: result.branch,
125
+ branchError: result.branchError
100
126
  };
101
127
  })
102
128
 
@@ -4,16 +4,19 @@
4
4
  * Structure:
5
5
  * - crud.ts: list/create/rename/delete/status and session binding
6
6
  * - transfer.ts: two-phase apply (worktree → main) and sync (main → worktree)
7
+ * - branching.ts: the database branch a worktree gets, and the ones it leaked
7
8
  */
8
9
 
9
10
  import { t } from 'elysia';
10
11
  import { createRouter } from '$shared/utils/ws-server';
11
12
  import { worktreeCrudHandler } from './crud';
12
13
  import { worktreeTransferHandler } from './transfer';
14
+ import { worktreeBranchingHandler } from './branching';
13
15
 
14
16
  export const worktreesRouter = createRouter()
15
17
  .merge(worktreeCrudHandler)
16
18
  .merge(worktreeTransferHandler)
19
+ .merge(worktreeBranchingHandler)
17
20
  // Collaborative broadcast events (Server → Client)
18
21
  .emit('worktrees:changed', t.Object({
19
22
  projectId: t.String(),
@@ -23,6 +26,17 @@ export const worktreesRouter = createRouter()
23
26
  sessionId: t.String(),
24
27
  worktreeId: t.Union([t.String(), t.Null()])
25
28
  }))
29
+ /**
30
+ * The branching binding or the branch list moved.
31
+ *
32
+ * Carries the whole state rather than a delta: the dialog renders providers,
33
+ * accounts, the binding, the dotenv file list and every branch together, and
34
+ * five separate events would have five orders they could arrive in.
35
+ */
36
+ .emit('worktrees:branching-changed', t.Object({
37
+ projectId: t.String(),
38
+ state: t.Any()
39
+ }))
26
40
  .emit('worktrees:transferred', t.Object({
27
41
  worktreeId: t.String(),
28
42
  projectId: t.String(),
@@ -1 +1 @@
1
- import{_ as ce}from"./main-Bo1hD7mt.js";async function ot(s={}){var t,e=s,r=!!globalThis.window,i=!!globalThis.WorkerGlobalScope,o=globalThis.process?.versions?.node&&globalThis.process?.type!="renderer";if(o){const{createRequire:n}=await ce(()=>import("./__vite-browser-external-BIHI7g3E.js"),[]);var l=n(import.meta.url)}var p=(n,c)=>{throw c},m=import.meta.url,z="";function _(n){return e.locateFile?e.locateFile(n,z):z+n}var x,A;if(o){var a=l("node:fs");m.startsWith("file:")&&(z=l("node:path").dirname(l("node:url").fileURLToPath(m))+"/"),A=n=>{n=u(n)?new URL(n):n;var c=a.readFileSync(n);return c},x=async(n,c=!0)=>{n=u(n)?new URL(n):n;var f=a.readFileSync(n,c?void 0:"utf8");return f},process.argv.length>1&&process.argv[1].replace(/\\/g,"/"),process.argv.slice(2),p=(n,c)=>{throw process.exitCode=n,c}}else if(r||i){try{z=new URL(".",m).href}catch{}x=async n=>{var c=await fetch(n,{credentials:"same-origin"});if(c.ok)return c.arrayBuffer();throw new Error(c.status+" : "+c.url)}}var R=console.log.bind(console),C=console.error.bind(console),U,M=!1,T,u=n=>n.startsWith("file://"),d,D,B=!1;function E(){var n=ae.buffer;e.HEAPU8=V=new Uint8Array(n),P=new Uint32Array(n),Q=new BigInt64Array(n),new BigUint64Array(n)}function te(){if(e.preRun)for(typeof e.preRun=="function"&&(e.preRun=[e.preRun]);e.preRun.length;)Me(e.preRun.shift());ze(ye)}function fe(){B=!0,L.m()}function Y(){if(e.postRun)for(typeof e.postRun=="function"&&(e.postRun=[e.postRun]);e.postRun.length;)Be(e.postRun.shift());ze(ge)}function X(n){e.onAbort?.(n),n=`Aborted(${n})`,C(n),M=!0,n+=". Build with -sASSERTIONS for more info.";var c=new WebAssembly.RuntimeError(n);throw D?.(c),c}var J;function ne(){return e.locateFile?_("zipkit-engine.wasm"):new URL("/assets/zipkit-engine-CaR0t_Uy.wasm",import.meta.url).href}function re(n){if(n==J&&U)return new Uint8Array(U);if(A)return A(n);throw"both async and sync fetching of the wasm failed"}async function K(n){if(!U)try{var c=await x(n);return new Uint8Array(c)}catch{}return re(n)}async function F(n,c){try{var f=await K(n),h=await WebAssembly.instantiate(f,c);return h}catch(b){C(`failed to asynchronously prepare wasm: ${b}`),X(b)}}async function _e(n,c,f){if(!n&&!o)try{var h=fetch(c,{credentials:"same-origin"}),b=await WebAssembly.instantiateStreaming(h,f);return b}catch(v){C(`wasm streaming compile failed: ${v}`),C("falling back to ArrayBuffer instantiation")}return F(c,f)}function se(){var n={a:rt};return n}async function ie(){function n(v,k){return L=v.exports,L=st(L),nt(L),E(),L}function c(v){return n(v.instance)}var f=se();if(e.instantiateWasm)return new Promise((v,k)=>{e.instantiateWasm(f,(I,N)=>{v(n(I))})});J??=ne();var h=await _e(U,J,f),b=c(h);return b}class oe{name="ExitStatus";constructor(c){this.message=`Program terminated with exit(${c})`,this.status=c}}var Q,P,V,ze=n=>{for(;n.length>0;)n.shift()(e)},ge=[],Be=n=>ge.push(n),ye=[],Me=n=>ye.push(n),me=!0,be=globalThis.TextDecoder&&new TextDecoder,Ie=(n,c,f,h)=>{for(var b=c+f;n[c]&&!(c>=b);)++c;return c},we=(n,c=0,f,h)=>{c>>>=0;var b=Ie(n,c,f);if(b-c>16&&n.buffer&&be)return be.decode(n.subarray(c,b));for(var v="";c<b;){var k=n[c++];if(!(k&128)){v+=String.fromCharCode(k);continue}var I=n[c++]&63;if((k&224)==192){v+=String.fromCharCode((k&31)<<6|I);continue}var N=n[c++]&63;if((k&240)==224?k=(k&15)<<12|I<<6|N:k=(k&7)<<18|I<<12|N<<6|n[c++]&63,k<65536)v+=String.fromCharCode(k);else{var Te=k-65536;v+=String.fromCharCode(55296|Te>>10,56320|Te&1023)}}return v},he=(n,c,f)=>(n>>>=0,n?we(V,n,c):"");function We(n,c,f,h){return n>>>=0,c>>>=0,h>>>=0,X(`Assertion failed: ${he(n)}, at: `+[c?he(c):"unknown filename",f,h?he(h):"unknown function"])}var Le=()=>X(""),ve=0,Ne=()=>{me=!1,ve=0},O={},ke=n=>{if(n instanceof oe||n=="unwind")return T;p(1,n)},xe=()=>me||ve>0,Ae=n=>{T=n,xe()||(e.onExit?.(n),M=!0),p(n,new oe(n))},He=(n,c)=>{T=n,Ae(n)},Se=He,Ke=()=>{if(!xe())try{Se(T)}catch(n){ke(n)}},Fe=n=>{if(!M)try{return n()}catch(c){ke(c)}finally{Ke()}},Re=()=>performance.now(),Ve=(n,c)=>{if(O[n]&&(clearTimeout(O[n].id),delete O[n]),!c)return 0;var f=setTimeout(()=>{delete O[n],Fe(()=>Ce(n,Re()))},c);return O[n]={id:f,timeout_ms:c},0},qe=()=>Date.now(),$e=n=>n>=0&&n<=3;function je(n,c,f){if(f>>>=0,!$e(n))return 28;var h;n===0?h=qe():h=Re();var b=Math.round(h*1e3*1e3);return Q[f>>>3>>>0]=BigInt(b),0}var Ze=()=>4294901760,Ge=(n,c)=>Math.ceil(n/c)*c,Ye=n=>{var c=ae.buffer.byteLength,f=(n-c+65535)/65536|0;try{return ae.grow(f),E(),1}catch{}};function Xe(n){n>>>=0;var c=V.length,f=Ze();if(n>f)return!1;for(var h=1;h<=4;h*=2){var b=c*(1+.2/h);b=Math.min(b,n+100663296);var v=Math.min(f,Ge(Math.max(n,b),65536)),k=Ye(v);if(k)return!0}return!1}var Je=n=>52;function Qe(n,c,f,h){return 70}var Oe=[null,[],[]],et=(n,c)=>{var f=Oe[n];c===0||c===10?((n===1?R:C)(we(f)),f.length=0):f.push(c)};function tt(n,c,f,h){c>>>=0,f>>>=0,h>>>=0;for(var b=0,v=0;v<f;v++){var k=P[c>>>2>>>0],I=P[c+4>>>2>>>0];c+=8;for(var N=0;N<I;N++)et(n,V[k+N>>>0]);b+=I}return P[h>>>2>>>0]=b,0}if(e.noExitRuntime&&(me=e.noExitRuntime),e.print&&(R=e.print),e.printErr&&(C=e.printErr),e.wasmBinary&&(U=e.wasmBinary),e.arguments&&e.arguments,e.thisProgram&&e.thisProgram,e.preInit)for(typeof e.preInit=="function"&&(e.preInit=[e.preInit]);e.preInit.length>0;)e.preInit.shift()();var Ce,ae;function nt(n){e._zk_input_ptr=n.n,e._zk_result_ptr=n.o,e._zk_result_len=n.p,e._zk_gzip_compress=n.q,e._zk_gzip_decompress=n.r,e._zk_deflate_compress=n.s,e._zk_deflate_decompress=n.t,e._zk_zlib_compress=n.u,e._zk_zlib_decompress=n.v,e._zk_crc32=n.w,e._zk_lz4_compress=n.x,e._zk_lz4_decompress=n.y,e._zk_zstd_compress=n.z,e._zk_zstd_decompress=n.A,e._zk_brotli_compress=n.B,e._zk_brotli_decompress=n.C,e._zk_snappy_compress=n.D,e._zk_snappy_decompress=n.E,e._zk_zstd_max_compress=n.F,e._zk_set_aux=n.G,e._zk_zstd_train_dict=n.H,e._zk_zstd_compress_dict=n.I,e._zk_zstd_decompress_dict=n.J,e._zk_lzma_compress=n.K,e._zk_lzma_decompress=n.L,e._zk_xz_ok=n.M,e._zk_xz_compress=n.N,e._zk_xz_decompress=n.O,e._zk_lzma2_decompress=n.P,e._zk_bzip2_compress=n.Q,e._zk_bzip2_decompress=n.R,e._zk_qoi_encode=n.S,e._zk_qoi_decode=n.T,e._zk_frame_delta_encode=n.U,e._zk_frame_delta_decode=n.V,Ce=n.W,ae=n.l,n.__indirect_function_table}var rt={a:We,f:Le,e:Ne,k:Ve,h:je,c:Xe,b:Se,j:Je,g:Qe,i:tt,d:Ae};function st(n){n=Object.assign({},n);var c=h=>b=>h(b)>>>0,f=h=>()=>h()>>>0;return n._emscripten_stack_alloc=c(n._emscripten_stack_alloc),n.emscripten_stack_get_current=f(n.emscripten_stack_get_current),n}function it(){te();function n(){e.calledRun=!0,!M&&(fe(),d?.(e),e.onRuntimeInitialized?.(),Y())}e.setStatus?(e.setStatus("Running..."),setTimeout(()=>{setTimeout(()=>e.setStatus(""),1),n()},1)):n()}var L;return L=await ie(),it(),B?t=e:t=new Promise((n,c)=>{d=n,D=c}),t}class ue{m;constructor(t){this.m=t}static async load(){const t=await ot();return new ue(t)}call(t,e){const r=this.m,i=r._zk_input_ptr(e.length);r.HEAPU8.set(e,i),t(e.length);const o=r._zk_result_ptr(),l=r._zk_result_len()>>>0;return r.HEAPU8.slice(o,o+l)}gzipCompress(t,e=9){return this.call(r=>this.m._zk_gzip_compress(r,e),t)}gzipDecompress(t){return this.call(e=>this.m._zk_gzip_decompress(e),t)}deflateCompress(t,e=9){return this.call(r=>this.m._zk_deflate_compress(r,e),t)}deflateDecompress(t){return this.call(e=>this.m._zk_deflate_decompress(e,0),t)}zlibCompress(t,e=9){return this.call(r=>this.m._zk_zlib_compress(r,e),t)}zlibDecompress(t){return this.call(e=>this.m._zk_zlib_decompress(e,0),t)}crc32(t,e=0){const r=this.m,i=r._zk_input_ptr(t.length);return r.HEAPU8.set(t,i),r._zk_crc32(t.length,e>>>0)>>>0}lz4Compress(t){return this.call(e=>this.m._zk_lz4_compress(e),t)}lz4Decompress(t){return this.call(e=>this.m._zk_lz4_decompress(e),t)}zstdCompress(t,e=19){return this.call(r=>this.m._zk_zstd_compress(r,e),t)}zstdDecompress(t){return this.call(e=>this.m._zk_zstd_decompress(e),t)}brotliCompress(t,e=11){return this.call(r=>this.m._zk_brotli_compress(r,e),t)}brotliDecompress(t){return this.call(e=>this.m._zk_brotli_decompress(e),t)}snappyCompress(t){return this.call(e=>this.m._zk_snappy_compress(e),t)}snappyDecompress(t){return this.call(e=>this.m._zk_snappy_decompress(e),t)}zstdMaxCompress(t,e=22){return this.call(r=>this.m._zk_zstd_max_compress(r,e),t)}lzmaCompress(t,e=9){return this.call(r=>this.m._zk_lzma_compress(r,e),t)}lzmaDecompress(t){return this.call(e=>this.m._zk_lzma_decompress(e),t)}lzma2Decompress(t,e,r){return this.call(i=>this.m._zk_lzma2_decompress(i,e,r),t)}xzCompress(t,e=6){const r=this.call(i=>this.m._zk_xz_compress(i,e),t);if(!this.m._zk_xz_ok())throw new Error("xz compression failed");return r}xzDecompress(t){const e=this.call(r=>this.m._zk_xz_decompress(r),t);if(!this.m._zk_xz_ok())throw new Error("xz decompression failed (corrupt stream or unsupported filter)");return e}setAux(t){const e=this.m,r=e._zk_input_ptr(t.length);e.HEAPU8.set(t,r),e._zk_set_aux(t.length)}zstdTrainDict(t,e,r){const i=this.m,o=i._zk_input_ptr(t.length);i.HEAPU8.set(t,o),i._zk_zstd_train_dict(t.length,e,r);const l=i._zk_result_ptr(),p=i._zk_result_len()>>>0;return i.HEAPU8.slice(l,l+p)}zstdCompressDict(t,e=19){return this.call(r=>this.m._zk_zstd_compress_dict(r,e),t)}zstdDecompressDict(t){return this.call(e=>this.m._zk_zstd_decompress_dict(e),t)}bzip2Compress(t,e=9){return this.call(r=>this.m._zk_bzip2_compress(r,e),t)}bzip2Decompress(t){return this.call(e=>this.m._zk_bzip2_decompress(e),t)}qoiEncode(t,e,r,i){return this.call(o=>this.m._zk_qoi_encode(o,e,r,i),t)}qoiDecode(t){return this.call(e=>this.m._zk_qoi_decode(e),t)}frameDeltaEncode(t,e){return this.call(r=>this.m._zk_frame_delta_encode(r,e),t)}frameDeltaDecode(t,e){return this.call(r=>this.m._zk_frame_delta_decode(r,e),t)}}let at;function w(){return at??=ue.load()}const ct=Object.freeze(Object.defineProperty({__proto__:null,ZipKitEngine:ue,getEngine:w},Symbol.toStringTag,{value:"Module"}));class pe extends Error{constructor(t="The operation was aborted"){super(t),this.name="AbortError"}}class ee extends Error{constructor(t){super(t),this.name="ZipKitError"}}function lt(s,t,e,r){return s===void 0||!Number.isFinite(s)?r:Math.max(t,Math.min(e,Math.round(s)))}function de(s){return s?.mode??"balanced"}function H(s,t,e,r){return lt(s?.level,t,e,r[de(s)])}function W(){return globalThis.Bun}function ut(s){if(s?.aborted)throw new pe}async function y(s,t,e){ut(t?.signal),t?.onProgress?.(0,0);const r=s();return t?.onProgress?.(1,e),r}function ft(s){return de(s)!=="ratio"&&!!W()?.gzipSync}async function _t(s,t){const e=H(t,0,9,{speed:1,balanced:6,ratio:9}),r=W();if(ft(t))return y(()=>r.gzipSync(s,{level:e}),t,s.length);const i=await w();return y(()=>i.gzipCompress(s,e),t,s.length)}async function mt(s,t){const e=W();if(e?.gunzipSync)return y(()=>e.gunzipSync(s),t,s.length);const r=await w();return y(()=>r.gzipDecompress(s),t,s.length)}function ht(s){return de(s)!=="ratio"&&!!W()?.deflateSync}async function pt(s,t){const e=H(t,0,9,{speed:1,balanced:6,ratio:9}),r=W();if(ht(t))return y(()=>r.deflateSync(s,{level:e}),t,s.length);const i=await w();return y(()=>i.deflateCompress(s,e),t,s.length)}async function dt(s,t){const e=W();if(e?.inflateSync)return y(()=>e.inflateSync(s),t,s.length);const r=await w();return y(()=>r.deflateDecompress(s),t,s.length)}async function zt(s,t){const e=await w(),r=H(t,0,9,{speed:1,balanced:6,ratio:9});return y(()=>e.zlibCompress(s,r),t,s.length)}async function gt(s,t){const e=await w();return y(()=>e.zlibDecompress(s),t,s.length)}async function yt(s,t){const e=H(t,1,22,{speed:1,balanced:3,ratio:19}),r=W();if(r?.zstdCompressSync)return y(()=>r.zstdCompressSync(s,{level:e}),t,s.length);const i=await w(),o=e>19?()=>i.zstdMaxCompress(s,e):()=>i.zstdCompress(s,e);return y(o,t,s.length)}async function bt(s,t){const e=W();if(e?.zstdDecompressSync)return y(()=>e.zstdDecompressSync(s),t,s.length);const r=await w();return y(()=>r.zstdDecompress(s),t,s.length)}async function wt(s,t){const e=await w();return y(()=>e.lz4Compress(s),t,s.length)}async function vt(s,t){const e=await w();return y(()=>e.lz4Decompress(s),t,s.length)}async function kt(s,t){const e=await w();return y(()=>e.snappyCompress(s),t,s.length)}async function xt(s,t){const e=await w();return y(()=>e.snappyDecompress(s),t,s.length)}async function At(s,t){const e=await w(),r=H(t,0,11,{speed:4,balanced:6,ratio:11});return y(()=>e.brotliCompress(s,r),t,s.length)}async function St(s,t){const e=await w();return y(()=>e.brotliDecompress(s),t,s.length)}async function Rt(s,t){const e=await w(),r=H(t,0,9,{speed:3,balanced:6,ratio:9});return y(()=>e.lzmaCompress(s,r),t,s.length)}async function Ct(s,t){const e=await w();return y(()=>e.lzmaDecompress(s),t,s.length)}async function Tt(s,t){const e=await w(),r=H(t,1,9,{speed:1,balanced:6,ratio:9});return y(()=>e.bzip2Compress(s,r),t,s.length)}async function Dt(s,t){const e=await w();return y(()=>e.bzip2Decompress(s),t,s.length)}const Pt={gzip:_t,deflate:pt,zlib:zt,zstd:yt,lz4:wt,snappy:kt,brotli:At,lzma:Rt,bzip2:Tt},Ut={gzip:mt,deflate:dt,zlib:gt,zstd:bt,lz4:vt,snappy:xt,brotli:St,lzma:Ct,bzip2:Dt};function Et(s,t,e){const r=Pt[t];if(!r)throw new ee(`Unknown codec: ${t}`);return r(s,e)}function Bt(s,t,e){const r=Ut[t];if(!r)throw new ee(`Unknown codec: ${t}`);return r(s,e)}const Mt=Object.freeze(Object.defineProperty({__proto__:null,compress:Et,decompressWith:Bt},Symbol.toStringTag,{value:"Module"})),It=new URL(import.meta.url.endsWith(".ts")?"./worker.ts":"./worker.js",import.meta.url);function Wt(){const s=globalThis.navigator?.hardwareConcurrency??4;return Math.max(1,Math.min(s,8))}async function Lt(){try{return await ce(()=>import("./__vite-browser-external-BIHI7g3E.js"),[])}catch{return}}class Nt{size;workers=[];pending=new Map;next=0;seq=0;ready;usable=!0;refWhileBusy(){const t=this.pending.size>0;for(const e of this.workers)(t?e.ref:e.unref).call(e)}constructor(t={}){this.size=t.size??Wt()}async ensure(){return this.ready?this.ready:(this.ready=(async()=>{const t=await Lt();if(!t){this.usable=!1;return}for(let e=0;e<this.size;e++){const r=new t.Worker(It);r.on("message",i=>this.settle(i)),r.on("error",i=>this.failAll(i)),r.unref(),this.workers.push(r)}})(),this.ready)}settle(t){const e=this.pending.get(t.id);e&&(this.pending.delete(t.id),this.refWhileBusy(),e.signal&&e.onAbort&&e.signal.removeEventListener("abort",e.onAbort),t.ok&&t.result?e.resolve(t.result):e.reject(new Error(t.error??"Worker operation failed")))}failAll(t){for(const[,e]of this.pending)e.reject(t);this.pending.clear(),this.refWhileBusy()}async run(t,e,r,i,o,l,p){if(l?.aborted)throw new pe;if(await this.ensure(),!this.usable){if(t==="zipCompress"){const{getEngine:A}=await ce(async()=>{const{getEngine:R}=await Promise.resolve().then(()=>ct);return{getEngine:R}},void 0),a=await A();return p==="zstd"?a.zstdCompress(e,i??19):a.deflateCompress(e,i??6)}const{compress:_,decompressWith:x}=await ce(async()=>{const{compress:A,decompressWith:a}=await Promise.resolve().then(()=>Mt);return{compress:A,decompressWith:a}},void 0);return t==="compress"?_(e,r,{level:i,mode:o}):x(e,r)}const m=this.seq++,z=this.workers[this.next++%this.workers.length];return new Promise((_,x)=>{const A={resolve:_,reject:x,signal:l};l&&(A.onAbort=()=>{this.pending.delete(m),this.refWhileBusy(),x(new pe)},l.addEventListener("abort",A.onAbort,{once:!0})),this.pending.set(m,A),this.refWhileBusy();const a=e.slice(),R={id:m,kind:t,codec:r,level:i,mode:o,method:p,data:a};z.postMessage(R,[a.buffer])})}compress(t,e,r){return this.run("compress",t,e,r?.level,r?.mode,r?.signal)}decompress(t,e,r){return this.run("decompress",t,e,void 0,void 0,r?.signal)}zipCompress(t,e,r){return this.run("zipCompress",t,e,r,void 0,void 0,e)}async destroy(){this.failAll(new Error("Worker pool destroyed")),await Promise.all(this.workers.map(t=>t.terminate())),this.workers=[],this.ready=void 0}}let Ht;function Kt(){return Ht??=new Nt}function Ft(s){const e=(Math.max(1980,s.getFullYear())-1980&127)<<9|s.getMonth()+1<<5|s.getDate(),r=s.getHours()<<11|s.getMinutes()<<5|s.getSeconds()>>1;return{date:e,time:r}}let g,$,j,Z,G;const Vt=new Uint32Array([16777216,33554432,67108864,134217728,268435456,536870912,1073741824,2147483648,452984832,905969664]);function qt(){g=new Uint8Array(256);const s=new Uint8Array(256);let t=1,e=1;do t=t^t<<1^(t&128?283:0),t&=255,e^=e<<1,e^=e<<2,e^=e<<4,e&=255,e&128&&(e^=9),e&=255,s[t]=e;while(t!==1);g[0]=99;for(let r=0;r<256;r++){let i=s[r],o=i;for(let l=0;l<4;l++)o=(o<<1|o>>>7)&255,i^=o;i^=99,g[r]=r===0?99:i}$=new Uint32Array(256),j=new Uint32Array(256),Z=new Uint32Array(256),G=new Uint32Array(256);for(let r=0;r<256;r++){const i=g[r],o=$t(i),l=o^i;$[r]=(o<<24|i<<16|i<<8|l)>>>0,j[r]=(l<<24|o<<16|i<<8|i)>>>0,Z[r]=(i<<24|l<<16|o<<8|i)>>>0,G[r]=(i<<24|i<<16|l<<8|o)>>>0}}function $t(s){return(s<<1^(s&128?283:0))&255}class jt{rk;rounds;constructor(t){if(g||qt(),t.length!==16&&t.length!==24&&t.length!==32)throw new Error(`AES key must be 16/24/32 bytes, got ${t.length}`);const e=t.length/4;this.rounds=e+6;const r=4*(this.rounds+1),i=new Uint32Array(r);for(let o=0;o<e;o++)i[o]=(t[4*o]<<24|t[4*o+1]<<16|t[4*o+2]<<8|t[4*o+3])>>>0;for(let o=e;o<r;o++){let l=i[o-1];o%e===0?l=(De(l<<8|l>>>24)^Vt[o/e-1])>>>0:e>6&&o%e===4&&(l=De(l)),i[o]=(i[o-e]^l)>>>0}this.rk=i}encryptBlock(t,e,r,i){const o=this.rk;let l=(t[e]<<24|t[e+1]<<16|t[e+2]<<8|t[e+3])^o[0],p=(t[e+4]<<24|t[e+5]<<16|t[e+6]<<8|t[e+7])^o[1],m=(t[e+8]<<24|t[e+9]<<16|t[e+10]<<8|t[e+11])^o[2],z=(t[e+12]<<24|t[e+13]<<16|t[e+14]<<8|t[e+15])^o[3],_=4;for(let x=1;x<this.rounds;x++){const A=($[l>>>24&255]^j[p>>>16&255]^Z[m>>>8&255]^G[z&255]^o[_])>>>0,a=($[p>>>24&255]^j[m>>>16&255]^Z[z>>>8&255]^G[l&255]^o[_+1])>>>0,R=($[m>>>24&255]^j[z>>>16&255]^Z[l>>>8&255]^G[p&255]^o[_+2])>>>0,C=($[z>>>24&255]^j[l>>>16&255]^Z[p>>>8&255]^G[m&255]^o[_+3])>>>0;l=A,p=a,m=R,z=C,_+=4}r[i]=(g[l>>>24&255]^o[_]>>>24)&255,r[i+1]=(g[p>>>16&255]^o[_]>>>16)&255,r[i+2]=(g[m>>>8&255]^o[_]>>>8)&255,r[i+3]=(g[z&255]^o[_])&255,r[i+4]=(g[p>>>24&255]^o[_+1]>>>24)&255,r[i+5]=(g[m>>>16&255]^o[_+1]>>>16)&255,r[i+6]=(g[z>>>8&255]^o[_+1]>>>8)&255,r[i+7]=(g[l&255]^o[_+1])&255,r[i+8]=(g[m>>>24&255]^o[_+2]>>>24)&255,r[i+9]=(g[z>>>16&255]^o[_+2]>>>16)&255,r[i+10]=(g[l>>>8&255]^o[_+2]>>>8)&255,r[i+11]=(g[p&255]^o[_+2])&255,r[i+12]=(g[z>>>24&255]^o[_+3]>>>24)&255,r[i+13]=(g[l>>>16&255]^o[_+3]>>>16)&255,r[i+14]=(g[p>>>8&255]^o[_+3]>>>8)&255,r[i+15]=(g[m&255]^o[_+3])&255}}function De(s){return(g[s>>>24&255]<<24|g[s>>>16&255]<<16|g[s>>>8&255]<<8|g[s&255])>>>0}function Zt(s,t){const e=new Uint8Array(t.length),r=new Uint8Array(16),i=new Uint8Array(16);let o=1;for(let l=0;l<t.length;l+=16){r[0]=o&255,r[1]=o>>>8&255,r[2]=o>>>16&255,r[3]=o>>>24&255,s.encryptBlock(r,0,i,0);const p=Math.min(16,t.length-l);for(let m=0;m<p;m++)e[l+m]=t[l+m]^i[m];o++}return e}const Gt={1:16,2:24,3:32},Yt={1:8,2:12,3:16},Ee=10,Xt=1e3;function le(){const s=globalThis.crypto;if(!s?.subtle)throw new ee("WebCrypto (crypto.subtle) is required for ZIP AES encryption");return s.subtle}function Jt(s){const t=globalThis.crypto;if(!t?.getRandomValues)throw new ee("crypto.getRandomValues is required to create encrypted ZIPs");return t.getRandomValues(new Uint8Array(s))}async function Qt(s,t,e){const r=Gt[e],i=await le().importKey("raw",new TextEncoder().encode(s),"PBKDF2",!1,["deriveBits"]),o=await le().deriveBits({name:"PBKDF2",salt:t,iterations:Xt,hash:"SHA-1"},i,(r*2+2)*8),l=new Uint8Array(o);return{aesKey:l.subarray(0,r),macKey:l.subarray(r,r*2),verifier:l.subarray(r*2,r*2+2)}}async function Ot(s,t){const e=await le().importKey("raw",s,{name:"HMAC",hash:"SHA-1"},!1,["sign"]),r=await le().sign("HMAC",e,t);return new Uint8Array(r).subarray(0,Ee)}async function en(s,t,e=3){const r=Jt(Yt[e]),{aesKey:i,macKey:o,verifier:l}=await Qt(t,r,e),p=Zt(new jt(i),s),m=await Ot(o,p),z=new Uint8Array(r.length+2+p.length+Ee);return z.set(r,0),z.set(l,r.length),z.set(p,r.length+2),z.set(m,r.length+2+p.length),{payload:z,strength:e}}const tn=256*1024,nn=67324752,rn=33639248,sn=101010256,on=101075792,an=117853008,S=4294967295,q=65535,cn={store:0,deflate:8,zstd:93};class ln{buf=new Uint8Array(1024);view=new DataView(this.buf.buffer);len=0;grow(t){if(this.len+t<=this.buf.length)return;let e=this.buf.length*2;for(;e<this.len+t;)e*=2;const r=new Uint8Array(e);r.set(this.buf.subarray(0,this.len)),this.buf=r,this.view=new DataView(this.buf.buffer)}u16(t){this.grow(2),this.view.setUint16(this.len,t,!0),this.len+=2}u32(t){this.grow(4),this.view.setUint32(this.len,t>>>0,!0),this.len+=4}u64(t){this.grow(8),this.view.setBigUint64(this.len,BigInt(t),!0),this.len+=8}bytes(t){this.grow(t.length),this.buf.set(t,this.len),this.len+=t.length}done(){return this.buf.slice(0,this.len)}}function Pe(s,t,e){s.u16(39169),s.u16(7),s.u16(2),s.u16(17729),s.bytes(new Uint8Array([t])),s.u16(e)}async function un(s,t,e){if(t==="store")return s;const r=await w();if(t==="deflate")return r.deflateCompress(s,e??6);if(t==="zstd")return r.zstdCompress(s,e??19);throw new ee(`Unsupported ZIP method: ${t}`)}const Ue=new TextEncoder;async function _n(s,t={}){const e=await w(),r=s.reduce((u,d)=>u+d.data.length,0),o=t.parallel??(s.length>=2&&r>=tn)?Kt():void 0,l=s.map(u=>e.crc32(u.data));let p=0;const m=t.onProgress,z=await Promise.all(s.map(u=>{const d=u.method??"deflate",D=d==="store"?Promise.resolve(u.data):o?o.zipCompress(u.data,d,u.level??(d==="zstd"?19:6)):un(u.data,d,u.level);return m?D.then(B=>(m(++p,s.length),B)):D})),_=3,x=t.password?await Promise.all(z.map(u=>en(u,t.password,_))):void 0,A=x?x.map(u=>u.payload):z,a=new ln,R=[];let C=s.length>q;for(let u=0;u<s.length;u++){const d=s[u],D=d.method??"deflate",B=cn[D],E=x!==void 0,te=E?99:B,fe=2048|(E?1:0),Y=Ue.encode(d.name),X=d.comment?Ue.encode(d.comment):new Uint8Array(0),J=l[u],ne=E?0:J,re=A[u],K=d.data.length,F=re.length,_e=d.mtime===void 0?new Date:new Date(d.mtime),{date:se,time:ie}=Ft(_e),oe=d.unixPermissions!==void 0?(d.unixPermissions&65535)<<16:0,Q=a.len,P=C||K>S||F>S||Q>S;P&&(C=!0);const V=(P?20:0)+(E?11:0);a.u32(nn),a.u16(P?45:20),a.u16(fe),a.u16(te),a.u16(ie),a.u16(se),a.u32(ne),a.u32(P?S:F),a.u32(P?S:K),a.u16(Y.length),a.u16(V),a.bytes(Y),P&&(a.u16(1),a.u16(16),a.u64(K),a.u64(F)),E&&Pe(a,_,B),a.bytes(re),R.push({nameBytes:Y,commentBytes:X,method:te,actualMethod:B,encrypted:E,crc:ne,compSize:F,size:K,dosDate:se,dosTime:ie,offset:Q,externalAttrs:oe,zip64:P})}const U=a.len;for(const u of R){a.u32(rn),a.u16(u.zip64?45:20),a.u16(u.zip64?45:20),a.u16(2048|(u.encrypted?1:0)),a.u16(u.method),a.u16(u.dosTime),a.u16(u.dosDate),a.u32(u.crc);const d=u.zip64;a.u32(d?S:u.compSize),a.u32(d?S:u.size),a.u16(u.nameBytes.length);const D=[];d&&D.push(u.size,u.compSize,u.offset);const B=(d?4+D.length*8:0)+(u.encrypted?11:0);if(a.u16(B),a.u16(u.commentBytes.length),a.u16(0),a.u16(0),a.u32(u.externalAttrs),a.u32(d?S:u.offset),a.bytes(u.nameBytes),d){a.u16(1),a.u16(D.length*8);for(const E of D)a.u64(E)}u.encrypted&&Pe(a,3,u.actualMethod),a.bytes(u.commentBytes)}const M=a.len-U,T=R.length;if(C||T>q||M>S||U>S){const u=a.len;a.u32(on),a.u64(44),a.u16(45),a.u16(45),a.u32(0),a.u32(0),a.u64(T),a.u64(T),a.u64(M),a.u64(U),a.u32(an),a.u32(0),a.u64(u),a.u32(1)}return a.u32(sn),a.u16(0),a.u16(0),a.u16(T>q?q:T),a.u16(T>q?q:T),a.u32(M>S?S:M),a.u32(U>S?S:U),a.u16(0),a.done()}new TextDecoder("utf-8");export{pe as AbortError,Nt as WorkerPool,ue as ZipKitEngine,ee as ZipKitError,At as brotli,Tt as bzip2,Et as compress,Bt as decompressWith,pt as deflate,w as getEngine,mt as gunzip,_t as gzip,dt as inflate,wt as lz4,Rt as lzma,Kt as sharedPool,kt as snappy,St as unbrotli,Dt as unbzip2,vt as unlz4,Ct as unlzma,xt as unsnappy,gt as unzlib,bt as unzstd,_n as zip,zt as zlib,yt as zstd};
1
+ import{_ as ce}from"./main-Cy5DXWPT.js";async function ot(s={}){var t,e=s,r=!!globalThis.window,i=!!globalThis.WorkerGlobalScope,o=globalThis.process?.versions?.node&&globalThis.process?.type!="renderer";if(o){const{createRequire:n}=await ce(()=>import("./__vite-browser-external-BIHI7g3E.js"),[]);var l=n(import.meta.url)}var p=(n,c)=>{throw c},m=import.meta.url,z="";function _(n){return e.locateFile?e.locateFile(n,z):z+n}var x,A;if(o){var a=l("node:fs");m.startsWith("file:")&&(z=l("node:path").dirname(l("node:url").fileURLToPath(m))+"/"),A=n=>{n=u(n)?new URL(n):n;var c=a.readFileSync(n);return c},x=async(n,c=!0)=>{n=u(n)?new URL(n):n;var f=a.readFileSync(n,c?void 0:"utf8");return f},process.argv.length>1&&process.argv[1].replace(/\\/g,"/"),process.argv.slice(2),p=(n,c)=>{throw process.exitCode=n,c}}else if(r||i){try{z=new URL(".",m).href}catch{}x=async n=>{var c=await fetch(n,{credentials:"same-origin"});if(c.ok)return c.arrayBuffer();throw new Error(c.status+" : "+c.url)}}var R=console.log.bind(console),C=console.error.bind(console),U,M=!1,T,u=n=>n.startsWith("file://"),d,D,B=!1;function E(){var n=ae.buffer;e.HEAPU8=V=new Uint8Array(n),P=new Uint32Array(n),Q=new BigInt64Array(n),new BigUint64Array(n)}function te(){if(e.preRun)for(typeof e.preRun=="function"&&(e.preRun=[e.preRun]);e.preRun.length;)Me(e.preRun.shift());ze(ye)}function fe(){B=!0,L.m()}function Y(){if(e.postRun)for(typeof e.postRun=="function"&&(e.postRun=[e.postRun]);e.postRun.length;)Be(e.postRun.shift());ze(ge)}function X(n){e.onAbort?.(n),n=`Aborted(${n})`,C(n),M=!0,n+=". Build with -sASSERTIONS for more info.";var c=new WebAssembly.RuntimeError(n);throw D?.(c),c}var J;function ne(){return e.locateFile?_("zipkit-engine.wasm"):new URL("/assets/zipkit-engine-CaR0t_Uy.wasm",import.meta.url).href}function re(n){if(n==J&&U)return new Uint8Array(U);if(A)return A(n);throw"both async and sync fetching of the wasm failed"}async function K(n){if(!U)try{var c=await x(n);return new Uint8Array(c)}catch{}return re(n)}async function F(n,c){try{var f=await K(n),h=await WebAssembly.instantiate(f,c);return h}catch(b){C(`failed to asynchronously prepare wasm: ${b}`),X(b)}}async function _e(n,c,f){if(!n&&!o)try{var h=fetch(c,{credentials:"same-origin"}),b=await WebAssembly.instantiateStreaming(h,f);return b}catch(v){C(`wasm streaming compile failed: ${v}`),C("falling back to ArrayBuffer instantiation")}return F(c,f)}function se(){var n={a:rt};return n}async function ie(){function n(v,k){return L=v.exports,L=st(L),nt(L),E(),L}function c(v){return n(v.instance)}var f=se();if(e.instantiateWasm)return new Promise((v,k)=>{e.instantiateWasm(f,(I,N)=>{v(n(I))})});J??=ne();var h=await _e(U,J,f),b=c(h);return b}class oe{name="ExitStatus";constructor(c){this.message=`Program terminated with exit(${c})`,this.status=c}}var Q,P,V,ze=n=>{for(;n.length>0;)n.shift()(e)},ge=[],Be=n=>ge.push(n),ye=[],Me=n=>ye.push(n),me=!0,be=globalThis.TextDecoder&&new TextDecoder,Ie=(n,c,f,h)=>{for(var b=c+f;n[c]&&!(c>=b);)++c;return c},we=(n,c=0,f,h)=>{c>>>=0;var b=Ie(n,c,f);if(b-c>16&&n.buffer&&be)return be.decode(n.subarray(c,b));for(var v="";c<b;){var k=n[c++];if(!(k&128)){v+=String.fromCharCode(k);continue}var I=n[c++]&63;if((k&224)==192){v+=String.fromCharCode((k&31)<<6|I);continue}var N=n[c++]&63;if((k&240)==224?k=(k&15)<<12|I<<6|N:k=(k&7)<<18|I<<12|N<<6|n[c++]&63,k<65536)v+=String.fromCharCode(k);else{var Te=k-65536;v+=String.fromCharCode(55296|Te>>10,56320|Te&1023)}}return v},he=(n,c,f)=>(n>>>=0,n?we(V,n,c):"");function We(n,c,f,h){return n>>>=0,c>>>=0,h>>>=0,X(`Assertion failed: ${he(n)}, at: `+[c?he(c):"unknown filename",f,h?he(h):"unknown function"])}var Le=()=>X(""),ve=0,Ne=()=>{me=!1,ve=0},O={},ke=n=>{if(n instanceof oe||n=="unwind")return T;p(1,n)},xe=()=>me||ve>0,Ae=n=>{T=n,xe()||(e.onExit?.(n),M=!0),p(n,new oe(n))},He=(n,c)=>{T=n,Ae(n)},Se=He,Ke=()=>{if(!xe())try{Se(T)}catch(n){ke(n)}},Fe=n=>{if(!M)try{return n()}catch(c){ke(c)}finally{Ke()}},Re=()=>performance.now(),Ve=(n,c)=>{if(O[n]&&(clearTimeout(O[n].id),delete O[n]),!c)return 0;var f=setTimeout(()=>{delete O[n],Fe(()=>Ce(n,Re()))},c);return O[n]={id:f,timeout_ms:c},0},qe=()=>Date.now(),$e=n=>n>=0&&n<=3;function je(n,c,f){if(f>>>=0,!$e(n))return 28;var h;n===0?h=qe():h=Re();var b=Math.round(h*1e3*1e3);return Q[f>>>3>>>0]=BigInt(b),0}var Ze=()=>4294901760,Ge=(n,c)=>Math.ceil(n/c)*c,Ye=n=>{var c=ae.buffer.byteLength,f=(n-c+65535)/65536|0;try{return ae.grow(f),E(),1}catch{}};function Xe(n){n>>>=0;var c=V.length,f=Ze();if(n>f)return!1;for(var h=1;h<=4;h*=2){var b=c*(1+.2/h);b=Math.min(b,n+100663296);var v=Math.min(f,Ge(Math.max(n,b),65536)),k=Ye(v);if(k)return!0}return!1}var Je=n=>52;function Qe(n,c,f,h){return 70}var Oe=[null,[],[]],et=(n,c)=>{var f=Oe[n];c===0||c===10?((n===1?R:C)(we(f)),f.length=0):f.push(c)};function tt(n,c,f,h){c>>>=0,f>>>=0,h>>>=0;for(var b=0,v=0;v<f;v++){var k=P[c>>>2>>>0],I=P[c+4>>>2>>>0];c+=8;for(var N=0;N<I;N++)et(n,V[k+N>>>0]);b+=I}return P[h>>>2>>>0]=b,0}if(e.noExitRuntime&&(me=e.noExitRuntime),e.print&&(R=e.print),e.printErr&&(C=e.printErr),e.wasmBinary&&(U=e.wasmBinary),e.arguments&&e.arguments,e.thisProgram&&e.thisProgram,e.preInit)for(typeof e.preInit=="function"&&(e.preInit=[e.preInit]);e.preInit.length>0;)e.preInit.shift()();var Ce,ae;function nt(n){e._zk_input_ptr=n.n,e._zk_result_ptr=n.o,e._zk_result_len=n.p,e._zk_gzip_compress=n.q,e._zk_gzip_decompress=n.r,e._zk_deflate_compress=n.s,e._zk_deflate_decompress=n.t,e._zk_zlib_compress=n.u,e._zk_zlib_decompress=n.v,e._zk_crc32=n.w,e._zk_lz4_compress=n.x,e._zk_lz4_decompress=n.y,e._zk_zstd_compress=n.z,e._zk_zstd_decompress=n.A,e._zk_brotli_compress=n.B,e._zk_brotli_decompress=n.C,e._zk_snappy_compress=n.D,e._zk_snappy_decompress=n.E,e._zk_zstd_max_compress=n.F,e._zk_set_aux=n.G,e._zk_zstd_train_dict=n.H,e._zk_zstd_compress_dict=n.I,e._zk_zstd_decompress_dict=n.J,e._zk_lzma_compress=n.K,e._zk_lzma_decompress=n.L,e._zk_xz_ok=n.M,e._zk_xz_compress=n.N,e._zk_xz_decompress=n.O,e._zk_lzma2_decompress=n.P,e._zk_bzip2_compress=n.Q,e._zk_bzip2_decompress=n.R,e._zk_qoi_encode=n.S,e._zk_qoi_decode=n.T,e._zk_frame_delta_encode=n.U,e._zk_frame_delta_decode=n.V,Ce=n.W,ae=n.l,n.__indirect_function_table}var rt={a:We,f:Le,e:Ne,k:Ve,h:je,c:Xe,b:Se,j:Je,g:Qe,i:tt,d:Ae};function st(n){n=Object.assign({},n);var c=h=>b=>h(b)>>>0,f=h=>()=>h()>>>0;return n._emscripten_stack_alloc=c(n._emscripten_stack_alloc),n.emscripten_stack_get_current=f(n.emscripten_stack_get_current),n}function it(){te();function n(){e.calledRun=!0,!M&&(fe(),d?.(e),e.onRuntimeInitialized?.(),Y())}e.setStatus?(e.setStatus("Running..."),setTimeout(()=>{setTimeout(()=>e.setStatus(""),1),n()},1)):n()}var L;return L=await ie(),it(),B?t=e:t=new Promise((n,c)=>{d=n,D=c}),t}class ue{m;constructor(t){this.m=t}static async load(){const t=await ot();return new ue(t)}call(t,e){const r=this.m,i=r._zk_input_ptr(e.length);r.HEAPU8.set(e,i),t(e.length);const o=r._zk_result_ptr(),l=r._zk_result_len()>>>0;return r.HEAPU8.slice(o,o+l)}gzipCompress(t,e=9){return this.call(r=>this.m._zk_gzip_compress(r,e),t)}gzipDecompress(t){return this.call(e=>this.m._zk_gzip_decompress(e),t)}deflateCompress(t,e=9){return this.call(r=>this.m._zk_deflate_compress(r,e),t)}deflateDecompress(t){return this.call(e=>this.m._zk_deflate_decompress(e,0),t)}zlibCompress(t,e=9){return this.call(r=>this.m._zk_zlib_compress(r,e),t)}zlibDecompress(t){return this.call(e=>this.m._zk_zlib_decompress(e,0),t)}crc32(t,e=0){const r=this.m,i=r._zk_input_ptr(t.length);return r.HEAPU8.set(t,i),r._zk_crc32(t.length,e>>>0)>>>0}lz4Compress(t){return this.call(e=>this.m._zk_lz4_compress(e),t)}lz4Decompress(t){return this.call(e=>this.m._zk_lz4_decompress(e),t)}zstdCompress(t,e=19){return this.call(r=>this.m._zk_zstd_compress(r,e),t)}zstdDecompress(t){return this.call(e=>this.m._zk_zstd_decompress(e),t)}brotliCompress(t,e=11){return this.call(r=>this.m._zk_brotli_compress(r,e),t)}brotliDecompress(t){return this.call(e=>this.m._zk_brotli_decompress(e),t)}snappyCompress(t){return this.call(e=>this.m._zk_snappy_compress(e),t)}snappyDecompress(t){return this.call(e=>this.m._zk_snappy_decompress(e),t)}zstdMaxCompress(t,e=22){return this.call(r=>this.m._zk_zstd_max_compress(r,e),t)}lzmaCompress(t,e=9){return this.call(r=>this.m._zk_lzma_compress(r,e),t)}lzmaDecompress(t){return this.call(e=>this.m._zk_lzma_decompress(e),t)}lzma2Decompress(t,e,r){return this.call(i=>this.m._zk_lzma2_decompress(i,e,r),t)}xzCompress(t,e=6){const r=this.call(i=>this.m._zk_xz_compress(i,e),t);if(!this.m._zk_xz_ok())throw new Error("xz compression failed");return r}xzDecompress(t){const e=this.call(r=>this.m._zk_xz_decompress(r),t);if(!this.m._zk_xz_ok())throw new Error("xz decompression failed (corrupt stream or unsupported filter)");return e}setAux(t){const e=this.m,r=e._zk_input_ptr(t.length);e.HEAPU8.set(t,r),e._zk_set_aux(t.length)}zstdTrainDict(t,e,r){const i=this.m,o=i._zk_input_ptr(t.length);i.HEAPU8.set(t,o),i._zk_zstd_train_dict(t.length,e,r);const l=i._zk_result_ptr(),p=i._zk_result_len()>>>0;return i.HEAPU8.slice(l,l+p)}zstdCompressDict(t,e=19){return this.call(r=>this.m._zk_zstd_compress_dict(r,e),t)}zstdDecompressDict(t){return this.call(e=>this.m._zk_zstd_decompress_dict(e),t)}bzip2Compress(t,e=9){return this.call(r=>this.m._zk_bzip2_compress(r,e),t)}bzip2Decompress(t){return this.call(e=>this.m._zk_bzip2_decompress(e),t)}qoiEncode(t,e,r,i){return this.call(o=>this.m._zk_qoi_encode(o,e,r,i),t)}qoiDecode(t){return this.call(e=>this.m._zk_qoi_decode(e),t)}frameDeltaEncode(t,e){return this.call(r=>this.m._zk_frame_delta_encode(r,e),t)}frameDeltaDecode(t,e){return this.call(r=>this.m._zk_frame_delta_decode(r,e),t)}}let at;function w(){return at??=ue.load()}const ct=Object.freeze(Object.defineProperty({__proto__:null,ZipKitEngine:ue,getEngine:w},Symbol.toStringTag,{value:"Module"}));class pe extends Error{constructor(t="The operation was aborted"){super(t),this.name="AbortError"}}class ee extends Error{constructor(t){super(t),this.name="ZipKitError"}}function lt(s,t,e,r){return s===void 0||!Number.isFinite(s)?r:Math.max(t,Math.min(e,Math.round(s)))}function de(s){return s?.mode??"balanced"}function H(s,t,e,r){return lt(s?.level,t,e,r[de(s)])}function W(){return globalThis.Bun}function ut(s){if(s?.aborted)throw new pe}async function y(s,t,e){ut(t?.signal),t?.onProgress?.(0,0);const r=s();return t?.onProgress?.(1,e),r}function ft(s){return de(s)!=="ratio"&&!!W()?.gzipSync}async function _t(s,t){const e=H(t,0,9,{speed:1,balanced:6,ratio:9}),r=W();if(ft(t))return y(()=>r.gzipSync(s,{level:e}),t,s.length);const i=await w();return y(()=>i.gzipCompress(s,e),t,s.length)}async function mt(s,t){const e=W();if(e?.gunzipSync)return y(()=>e.gunzipSync(s),t,s.length);const r=await w();return y(()=>r.gzipDecompress(s),t,s.length)}function ht(s){return de(s)!=="ratio"&&!!W()?.deflateSync}async function pt(s,t){const e=H(t,0,9,{speed:1,balanced:6,ratio:9}),r=W();if(ht(t))return y(()=>r.deflateSync(s,{level:e}),t,s.length);const i=await w();return y(()=>i.deflateCompress(s,e),t,s.length)}async function dt(s,t){const e=W();if(e?.inflateSync)return y(()=>e.inflateSync(s),t,s.length);const r=await w();return y(()=>r.deflateDecompress(s),t,s.length)}async function zt(s,t){const e=await w(),r=H(t,0,9,{speed:1,balanced:6,ratio:9});return y(()=>e.zlibCompress(s,r),t,s.length)}async function gt(s,t){const e=await w();return y(()=>e.zlibDecompress(s),t,s.length)}async function yt(s,t){const e=H(t,1,22,{speed:1,balanced:3,ratio:19}),r=W();if(r?.zstdCompressSync)return y(()=>r.zstdCompressSync(s,{level:e}),t,s.length);const i=await w(),o=e>19?()=>i.zstdMaxCompress(s,e):()=>i.zstdCompress(s,e);return y(o,t,s.length)}async function bt(s,t){const e=W();if(e?.zstdDecompressSync)return y(()=>e.zstdDecompressSync(s),t,s.length);const r=await w();return y(()=>r.zstdDecompress(s),t,s.length)}async function wt(s,t){const e=await w();return y(()=>e.lz4Compress(s),t,s.length)}async function vt(s,t){const e=await w();return y(()=>e.lz4Decompress(s),t,s.length)}async function kt(s,t){const e=await w();return y(()=>e.snappyCompress(s),t,s.length)}async function xt(s,t){const e=await w();return y(()=>e.snappyDecompress(s),t,s.length)}async function At(s,t){const e=await w(),r=H(t,0,11,{speed:4,balanced:6,ratio:11});return y(()=>e.brotliCompress(s,r),t,s.length)}async function St(s,t){const e=await w();return y(()=>e.brotliDecompress(s),t,s.length)}async function Rt(s,t){const e=await w(),r=H(t,0,9,{speed:3,balanced:6,ratio:9});return y(()=>e.lzmaCompress(s,r),t,s.length)}async function Ct(s,t){const e=await w();return y(()=>e.lzmaDecompress(s),t,s.length)}async function Tt(s,t){const e=await w(),r=H(t,1,9,{speed:1,balanced:6,ratio:9});return y(()=>e.bzip2Compress(s,r),t,s.length)}async function Dt(s,t){const e=await w();return y(()=>e.bzip2Decompress(s),t,s.length)}const Pt={gzip:_t,deflate:pt,zlib:zt,zstd:yt,lz4:wt,snappy:kt,brotli:At,lzma:Rt,bzip2:Tt},Ut={gzip:mt,deflate:dt,zlib:gt,zstd:bt,lz4:vt,snappy:xt,brotli:St,lzma:Ct,bzip2:Dt};function Et(s,t,e){const r=Pt[t];if(!r)throw new ee(`Unknown codec: ${t}`);return r(s,e)}function Bt(s,t,e){const r=Ut[t];if(!r)throw new ee(`Unknown codec: ${t}`);return r(s,e)}const Mt=Object.freeze(Object.defineProperty({__proto__:null,compress:Et,decompressWith:Bt},Symbol.toStringTag,{value:"Module"})),It=new URL(import.meta.url.endsWith(".ts")?"./worker.ts":"./worker.js",import.meta.url);function Wt(){const s=globalThis.navigator?.hardwareConcurrency??4;return Math.max(1,Math.min(s,8))}async function Lt(){try{return await ce(()=>import("./__vite-browser-external-BIHI7g3E.js"),[])}catch{return}}class Nt{size;workers=[];pending=new Map;next=0;seq=0;ready;usable=!0;refWhileBusy(){const t=this.pending.size>0;for(const e of this.workers)(t?e.ref:e.unref).call(e)}constructor(t={}){this.size=t.size??Wt()}async ensure(){return this.ready?this.ready:(this.ready=(async()=>{const t=await Lt();if(!t){this.usable=!1;return}for(let e=0;e<this.size;e++){const r=new t.Worker(It);r.on("message",i=>this.settle(i)),r.on("error",i=>this.failAll(i)),r.unref(),this.workers.push(r)}})(),this.ready)}settle(t){const e=this.pending.get(t.id);e&&(this.pending.delete(t.id),this.refWhileBusy(),e.signal&&e.onAbort&&e.signal.removeEventListener("abort",e.onAbort),t.ok&&t.result?e.resolve(t.result):e.reject(new Error(t.error??"Worker operation failed")))}failAll(t){for(const[,e]of this.pending)e.reject(t);this.pending.clear(),this.refWhileBusy()}async run(t,e,r,i,o,l,p){if(l?.aborted)throw new pe;if(await this.ensure(),!this.usable){if(t==="zipCompress"){const{getEngine:A}=await ce(async()=>{const{getEngine:R}=await Promise.resolve().then(()=>ct);return{getEngine:R}},void 0),a=await A();return p==="zstd"?a.zstdCompress(e,i??19):a.deflateCompress(e,i??6)}const{compress:_,decompressWith:x}=await ce(async()=>{const{compress:A,decompressWith:a}=await Promise.resolve().then(()=>Mt);return{compress:A,decompressWith:a}},void 0);return t==="compress"?_(e,r,{level:i,mode:o}):x(e,r)}const m=this.seq++,z=this.workers[this.next++%this.workers.length];return new Promise((_,x)=>{const A={resolve:_,reject:x,signal:l};l&&(A.onAbort=()=>{this.pending.delete(m),this.refWhileBusy(),x(new pe)},l.addEventListener("abort",A.onAbort,{once:!0})),this.pending.set(m,A),this.refWhileBusy();const a=e.slice(),R={id:m,kind:t,codec:r,level:i,mode:o,method:p,data:a};z.postMessage(R,[a.buffer])})}compress(t,e,r){return this.run("compress",t,e,r?.level,r?.mode,r?.signal)}decompress(t,e,r){return this.run("decompress",t,e,void 0,void 0,r?.signal)}zipCompress(t,e,r){return this.run("zipCompress",t,e,r,void 0,void 0,e)}async destroy(){this.failAll(new Error("Worker pool destroyed")),await Promise.all(this.workers.map(t=>t.terminate())),this.workers=[],this.ready=void 0}}let Ht;function Kt(){return Ht??=new Nt}function Ft(s){const e=(Math.max(1980,s.getFullYear())-1980&127)<<9|s.getMonth()+1<<5|s.getDate(),r=s.getHours()<<11|s.getMinutes()<<5|s.getSeconds()>>1;return{date:e,time:r}}let g,$,j,Z,G;const Vt=new Uint32Array([16777216,33554432,67108864,134217728,268435456,536870912,1073741824,2147483648,452984832,905969664]);function qt(){g=new Uint8Array(256);const s=new Uint8Array(256);let t=1,e=1;do t=t^t<<1^(t&128?283:0),t&=255,e^=e<<1,e^=e<<2,e^=e<<4,e&=255,e&128&&(e^=9),e&=255,s[t]=e;while(t!==1);g[0]=99;for(let r=0;r<256;r++){let i=s[r],o=i;for(let l=0;l<4;l++)o=(o<<1|o>>>7)&255,i^=o;i^=99,g[r]=r===0?99:i}$=new Uint32Array(256),j=new Uint32Array(256),Z=new Uint32Array(256),G=new Uint32Array(256);for(let r=0;r<256;r++){const i=g[r],o=$t(i),l=o^i;$[r]=(o<<24|i<<16|i<<8|l)>>>0,j[r]=(l<<24|o<<16|i<<8|i)>>>0,Z[r]=(i<<24|l<<16|o<<8|i)>>>0,G[r]=(i<<24|i<<16|l<<8|o)>>>0}}function $t(s){return(s<<1^(s&128?283:0))&255}class jt{rk;rounds;constructor(t){if(g||qt(),t.length!==16&&t.length!==24&&t.length!==32)throw new Error(`AES key must be 16/24/32 bytes, got ${t.length}`);const e=t.length/4;this.rounds=e+6;const r=4*(this.rounds+1),i=new Uint32Array(r);for(let o=0;o<e;o++)i[o]=(t[4*o]<<24|t[4*o+1]<<16|t[4*o+2]<<8|t[4*o+3])>>>0;for(let o=e;o<r;o++){let l=i[o-1];o%e===0?l=(De(l<<8|l>>>24)^Vt[o/e-1])>>>0:e>6&&o%e===4&&(l=De(l)),i[o]=(i[o-e]^l)>>>0}this.rk=i}encryptBlock(t,e,r,i){const o=this.rk;let l=(t[e]<<24|t[e+1]<<16|t[e+2]<<8|t[e+3])^o[0],p=(t[e+4]<<24|t[e+5]<<16|t[e+6]<<8|t[e+7])^o[1],m=(t[e+8]<<24|t[e+9]<<16|t[e+10]<<8|t[e+11])^o[2],z=(t[e+12]<<24|t[e+13]<<16|t[e+14]<<8|t[e+15])^o[3],_=4;for(let x=1;x<this.rounds;x++){const A=($[l>>>24&255]^j[p>>>16&255]^Z[m>>>8&255]^G[z&255]^o[_])>>>0,a=($[p>>>24&255]^j[m>>>16&255]^Z[z>>>8&255]^G[l&255]^o[_+1])>>>0,R=($[m>>>24&255]^j[z>>>16&255]^Z[l>>>8&255]^G[p&255]^o[_+2])>>>0,C=($[z>>>24&255]^j[l>>>16&255]^Z[p>>>8&255]^G[m&255]^o[_+3])>>>0;l=A,p=a,m=R,z=C,_+=4}r[i]=(g[l>>>24&255]^o[_]>>>24)&255,r[i+1]=(g[p>>>16&255]^o[_]>>>16)&255,r[i+2]=(g[m>>>8&255]^o[_]>>>8)&255,r[i+3]=(g[z&255]^o[_])&255,r[i+4]=(g[p>>>24&255]^o[_+1]>>>24)&255,r[i+5]=(g[m>>>16&255]^o[_+1]>>>16)&255,r[i+6]=(g[z>>>8&255]^o[_+1]>>>8)&255,r[i+7]=(g[l&255]^o[_+1])&255,r[i+8]=(g[m>>>24&255]^o[_+2]>>>24)&255,r[i+9]=(g[z>>>16&255]^o[_+2]>>>16)&255,r[i+10]=(g[l>>>8&255]^o[_+2]>>>8)&255,r[i+11]=(g[p&255]^o[_+2])&255,r[i+12]=(g[z>>>24&255]^o[_+3]>>>24)&255,r[i+13]=(g[l>>>16&255]^o[_+3]>>>16)&255,r[i+14]=(g[p>>>8&255]^o[_+3]>>>8)&255,r[i+15]=(g[m&255]^o[_+3])&255}}function De(s){return(g[s>>>24&255]<<24|g[s>>>16&255]<<16|g[s>>>8&255]<<8|g[s&255])>>>0}function Zt(s,t){const e=new Uint8Array(t.length),r=new Uint8Array(16),i=new Uint8Array(16);let o=1;for(let l=0;l<t.length;l+=16){r[0]=o&255,r[1]=o>>>8&255,r[2]=o>>>16&255,r[3]=o>>>24&255,s.encryptBlock(r,0,i,0);const p=Math.min(16,t.length-l);for(let m=0;m<p;m++)e[l+m]=t[l+m]^i[m];o++}return e}const Gt={1:16,2:24,3:32},Yt={1:8,2:12,3:16},Ee=10,Xt=1e3;function le(){const s=globalThis.crypto;if(!s?.subtle)throw new ee("WebCrypto (crypto.subtle) is required for ZIP AES encryption");return s.subtle}function Jt(s){const t=globalThis.crypto;if(!t?.getRandomValues)throw new ee("crypto.getRandomValues is required to create encrypted ZIPs");return t.getRandomValues(new Uint8Array(s))}async function Qt(s,t,e){const r=Gt[e],i=await le().importKey("raw",new TextEncoder().encode(s),"PBKDF2",!1,["deriveBits"]),o=await le().deriveBits({name:"PBKDF2",salt:t,iterations:Xt,hash:"SHA-1"},i,(r*2+2)*8),l=new Uint8Array(o);return{aesKey:l.subarray(0,r),macKey:l.subarray(r,r*2),verifier:l.subarray(r*2,r*2+2)}}async function Ot(s,t){const e=await le().importKey("raw",s,{name:"HMAC",hash:"SHA-1"},!1,["sign"]),r=await le().sign("HMAC",e,t);return new Uint8Array(r).subarray(0,Ee)}async function en(s,t,e=3){const r=Jt(Yt[e]),{aesKey:i,macKey:o,verifier:l}=await Qt(t,r,e),p=Zt(new jt(i),s),m=await Ot(o,p),z=new Uint8Array(r.length+2+p.length+Ee);return z.set(r,0),z.set(l,r.length),z.set(p,r.length+2),z.set(m,r.length+2+p.length),{payload:z,strength:e}}const tn=256*1024,nn=67324752,rn=33639248,sn=101010256,on=101075792,an=117853008,S=4294967295,q=65535,cn={store:0,deflate:8,zstd:93};class ln{buf=new Uint8Array(1024);view=new DataView(this.buf.buffer);len=0;grow(t){if(this.len+t<=this.buf.length)return;let e=this.buf.length*2;for(;e<this.len+t;)e*=2;const r=new Uint8Array(e);r.set(this.buf.subarray(0,this.len)),this.buf=r,this.view=new DataView(this.buf.buffer)}u16(t){this.grow(2),this.view.setUint16(this.len,t,!0),this.len+=2}u32(t){this.grow(4),this.view.setUint32(this.len,t>>>0,!0),this.len+=4}u64(t){this.grow(8),this.view.setBigUint64(this.len,BigInt(t),!0),this.len+=8}bytes(t){this.grow(t.length),this.buf.set(t,this.len),this.len+=t.length}done(){return this.buf.slice(0,this.len)}}function Pe(s,t,e){s.u16(39169),s.u16(7),s.u16(2),s.u16(17729),s.bytes(new Uint8Array([t])),s.u16(e)}async function un(s,t,e){if(t==="store")return s;const r=await w();if(t==="deflate")return r.deflateCompress(s,e??6);if(t==="zstd")return r.zstdCompress(s,e??19);throw new ee(`Unsupported ZIP method: ${t}`)}const Ue=new TextEncoder;async function _n(s,t={}){const e=await w(),r=s.reduce((u,d)=>u+d.data.length,0),o=t.parallel??(s.length>=2&&r>=tn)?Kt():void 0,l=s.map(u=>e.crc32(u.data));let p=0;const m=t.onProgress,z=await Promise.all(s.map(u=>{const d=u.method??"deflate",D=d==="store"?Promise.resolve(u.data):o?o.zipCompress(u.data,d,u.level??(d==="zstd"?19:6)):un(u.data,d,u.level);return m?D.then(B=>(m(++p,s.length),B)):D})),_=3,x=t.password?await Promise.all(z.map(u=>en(u,t.password,_))):void 0,A=x?x.map(u=>u.payload):z,a=new ln,R=[];let C=s.length>q;for(let u=0;u<s.length;u++){const d=s[u],D=d.method??"deflate",B=cn[D],E=x!==void 0,te=E?99:B,fe=2048|(E?1:0),Y=Ue.encode(d.name),X=d.comment?Ue.encode(d.comment):new Uint8Array(0),J=l[u],ne=E?0:J,re=A[u],K=d.data.length,F=re.length,_e=d.mtime===void 0?new Date:new Date(d.mtime),{date:se,time:ie}=Ft(_e),oe=d.unixPermissions!==void 0?(d.unixPermissions&65535)<<16:0,Q=a.len,P=C||K>S||F>S||Q>S;P&&(C=!0);const V=(P?20:0)+(E?11:0);a.u32(nn),a.u16(P?45:20),a.u16(fe),a.u16(te),a.u16(ie),a.u16(se),a.u32(ne),a.u32(P?S:F),a.u32(P?S:K),a.u16(Y.length),a.u16(V),a.bytes(Y),P&&(a.u16(1),a.u16(16),a.u64(K),a.u64(F)),E&&Pe(a,_,B),a.bytes(re),R.push({nameBytes:Y,commentBytes:X,method:te,actualMethod:B,encrypted:E,crc:ne,compSize:F,size:K,dosDate:se,dosTime:ie,offset:Q,externalAttrs:oe,zip64:P})}const U=a.len;for(const u of R){a.u32(rn),a.u16(u.zip64?45:20),a.u16(u.zip64?45:20),a.u16(2048|(u.encrypted?1:0)),a.u16(u.method),a.u16(u.dosTime),a.u16(u.dosDate),a.u32(u.crc);const d=u.zip64;a.u32(d?S:u.compSize),a.u32(d?S:u.size),a.u16(u.nameBytes.length);const D=[];d&&D.push(u.size,u.compSize,u.offset);const B=(d?4+D.length*8:0)+(u.encrypted?11:0);if(a.u16(B),a.u16(u.commentBytes.length),a.u16(0),a.u16(0),a.u32(u.externalAttrs),a.u32(d?S:u.offset),a.bytes(u.nameBytes),d){a.u16(1),a.u16(D.length*8);for(const E of D)a.u64(E)}u.encrypted&&Pe(a,3,u.actualMethod),a.bytes(u.commentBytes)}const M=a.len-U,T=R.length;if(C||T>q||M>S||U>S){const u=a.len;a.u32(on),a.u64(44),a.u16(45),a.u16(45),a.u32(0),a.u32(0),a.u64(T),a.u64(T),a.u64(M),a.u64(U),a.u32(an),a.u32(0),a.u64(u),a.u32(1)}return a.u32(sn),a.u16(0),a.u16(0),a.u16(T>q?q:T),a.u16(T>q?q:T),a.u32(M>S?S:M),a.u32(U>S?S:U),a.u16(0),a.done()}new TextDecoder("utf-8");export{pe as AbortError,Nt as WorkerPool,ue as ZipKitEngine,ee as ZipKitError,At as brotli,Tt as bzip2,Et as compress,Bt as decompressWith,pt as deflate,w as getEngine,mt as gunzip,_t as gzip,dt as inflate,wt as lz4,Rt as lzma,Kt as sharedPool,kt as snappy,St as unbrotli,Dt as unbzip2,vt as unlz4,Ct as unlzma,xt as unsnappy,gt as unzlib,bt as unzstd,_n as zip,zt as zlib,yt as zstd};
@@ -1 +1 @@
1
- import{s as _,_ as d,r as s,a as u}from"./main-Bo1hD7mt.js";import{C as T,P as y,W as E,d as L,b as g,c as v,h as P,l as b,m as k,e as D,n as O,f as R,g as S,t as V}from"./main-Bo1hD7mt.js";async function h(o,e={}){const i=e.loading===!1?void 0:_(o,e.loadingText??"Loading…"),[{Terminal:l},{FitAddon:c}]=await Promise.all([d(()=>import("./xterm-B-qIQCd3.js"),[]),d(()=>import("./addon-fit-DX4qG4td.js"),[])]).catch(r=>{throw i?.(),r}),a=new l({scrollback:e.scrollback??5e3,fontSize:e.fontSize??13,fontFamily:e.fontFamily??"ui-monospace, SFMono-Regular, Menlo, monospace",lineHeight:e.lineHeight??1,cursorBlink:e.cursorBlink??!1,cursorStyle:e.cursorStyle??"block",disableStdin:e.stdin!==!0,allowProposedApi:!0,convertEol:!0,theme:s(e.theme),...e.cols?{cols:e.cols}:{},...e.rows?{rows:e.rows}:{},...e.terminalOptions??{}}),t=e.fit===!1?void 0:new c;if(t&&a.loadAddon(t),e.clipboard)try{const{ClipboardAddon:r}=await d(()=>import("./addon-clipboard-wHJhZAA4.js"),[]);a.loadAddon(new r)}catch{}if(e.webLinks)try{const{WebLinksAddon:r}=await d(()=>import("./addon-web-links-DIbG5aQx.js"),[]);a.loadAddon(new r)}catch{}if(e.unicode11)try{const{Unicode11Addon:r}=await d(()=>import("./addon-unicode11-Bt8F3D7-.js"),[]);a.loadAddon(new r),a.unicode.activeVersion="11"}catch{}for(const r of e.addons??[])a.loadAddon(r);if(a.open(o),e.ligatures)try{const{LigaturesAddon:r}=await d(()=>import("./addon-ligatures-DpDY8N_X.js"),[]);a.loadAddon(new r)}catch{}const m=t?u({resize:async()=>{}},a,t,{debounceMs:e.fitDebounceMs??100}):void 0;e.onReady?.(a),i?.();let n=!1;return{terminal:a,fitAddon:t,write:r=>a.write(r),clear:()=>{a.clear(),a.reset()},fit:()=>t?.fit(),setTheme:r=>{a.options.theme=s(r)},dispose(){n||(n=!0,m?.(),a.dispose())}}}export{T as ClientSession,y as PtyKitClient,E as WsCore,u as attachFit,L as darkTheme,g as defaultPersistence,v as draculaTheme,P as hostSocket,b as lightTheme,k as matrixTheme,D as mountTerminal,h as mountViewer,O as nordTheme,s as resolveTheme,_ as showLoadingOverlay,R as solarizedDarkTheme,S as solarizedLightTheme,V as themes};
1
+ import{s as _,_ as d,r as s,a as u}from"./main-Cy5DXWPT.js";import{C as T,P as y,W as E,d as L,b as g,c as v,h as P,l as b,m as k,e as D,n as O,f as R,g as S,t as V}from"./main-Cy5DXWPT.js";async function h(o,e={}){const i=e.loading===!1?void 0:_(o,e.loadingText??"Loading…"),[{Terminal:l},{FitAddon:c}]=await Promise.all([d(()=>import("./xterm-B-qIQCd3.js"),[]),d(()=>import("./addon-fit-DX4qG4td.js"),[])]).catch(r=>{throw i?.(),r}),a=new l({scrollback:e.scrollback??5e3,fontSize:e.fontSize??13,fontFamily:e.fontFamily??"ui-monospace, SFMono-Regular, Menlo, monospace",lineHeight:e.lineHeight??1,cursorBlink:e.cursorBlink??!1,cursorStyle:e.cursorStyle??"block",disableStdin:e.stdin!==!0,allowProposedApi:!0,convertEol:!0,theme:s(e.theme),...e.cols?{cols:e.cols}:{},...e.rows?{rows:e.rows}:{},...e.terminalOptions??{}}),t=e.fit===!1?void 0:new c;if(t&&a.loadAddon(t),e.clipboard)try{const{ClipboardAddon:r}=await d(()=>import("./addon-clipboard-wHJhZAA4.js"),[]);a.loadAddon(new r)}catch{}if(e.webLinks)try{const{WebLinksAddon:r}=await d(()=>import("./addon-web-links-DIbG5aQx.js"),[]);a.loadAddon(new r)}catch{}if(e.unicode11)try{const{Unicode11Addon:r}=await d(()=>import("./addon-unicode11-Bt8F3D7-.js"),[]);a.loadAddon(new r),a.unicode.activeVersion="11"}catch{}for(const r of e.addons??[])a.loadAddon(r);if(a.open(o),e.ligatures)try{const{LigaturesAddon:r}=await d(()=>import("./addon-ligatures-DpDY8N_X.js"),[]);a.loadAddon(new r)}catch{}const m=t?u({resize:async()=>{}},a,t,{debounceMs:e.fitDebounceMs??100}):void 0;e.onReady?.(a),i?.();let n=!1;return{terminal:a,fitAddon:t,write:r=>a.write(r),clear:()=>{a.clear(),a.reset()},fit:()=>t?.fit(),setTheme:r=>{a.options.theme=s(r)},dispose(){n||(n=!0,m?.(),a.dispose())}}}export{T as ClientSession,y as PtyKitClient,E as WsCore,u as attachFit,L as darkTheme,g as defaultPersistence,v as draculaTheme,P as hostSocket,b as lightTheme,k as matrixTheme,D as mountTerminal,h as mountViewer,O as nordTheme,s as resolveTheme,_ as showLoadingOverlay,R as solarizedDarkTheme,S as solarizedLightTheme,V as themes};