@treeport/treeport 0.5.0 → 0.6.1

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.
@@ -6,397 +6,6 @@ import crypto from "node:crypto";
6
6
  import fsSync, { constants } from "node:fs";
7
7
  import os from "node:os";
8
8
  import { fileURLToPath, pathToFileURL } from "node:url";
9
- //#region ../../packages/shared/dist/terminal-protocol.js
10
- const SOCKET_IO_PATH = "/api/socket.io/";
11
- const TERMINAL_CONTROLLER_GRACE_MS = 1e4;
12
- const TERMINAL_OUTPUT_HIGH_WATERMARK = 256 * 1024;
13
- const TERMINAL_OUTPUT_LOW_WATERMARK = 64 * 1024;
14
- const TERMINAL_OUTPUT_STALL_TIMEOUT_MS = 3e4;
15
- const TERMINAL_MAX_CLIENT_MESSAGE_BYTES = 128 * 1024;
16
- const TERMINAL_MAX_INPUT_BYTES = 64 * 1024;
17
- const TERMINAL_SCROLL_EXIT_SEQUENCE = "\x1B[9000~";
18
- const TERMINAL_SELECTION_START_SEQUENCE = "\x1B[9001~";
19
- const TERMINAL_SELECTION_STOP_SEQUENCE = "\x1B[9002~";
20
- const TERMINAL_SELECTION_CLEAR_SEQUENCE = "\x1B[9003~";
21
- const TERMINAL_SELECTION_RESTORE_SEQUENCE = "\x1B[9004~";
22
- z.unknown();
23
- const terminalId = z.string().min(1).max(128);
24
- const clientId = z.string().min(1).max(128);
25
- const streamId = z.string().min(1).max(128);
26
- const generation = z.number().int().nonnegative();
27
- const dimensions = {
28
- cols: z.number().int().min(2).max(1e3),
29
- rows: z.number().int().min(2).max(500)
30
- };
31
- const terminalSizeSchema = z.strictObject(dimensions);
32
- const terminalProgressSchema = z.strictObject({
33
- state: z.enum([
34
- "normal",
35
- "error",
36
- "indeterminate",
37
- "paused"
38
- ]),
39
- value: z.number().int().min(0).max(100).nullable()
40
- });
41
- const terminalProgramSchema = z.enum([
42
- "pi",
43
- "claude",
44
- "codex"
45
- ]);
46
- const terminalRuntimeMetadataSchema = z.strictObject({
47
- terminalId: z.string().min(1),
48
- title: z.string().max(256).nullable(),
49
- program: terminalProgramSchema.nullable().default(null),
50
- hasForegroundProcess: z.boolean().nullable().optional(),
51
- progress: terminalProgressSchema.nullable(),
52
- progressStartedAt: z.string().datetime().nullable().default(null),
53
- progressClearedAt: z.string().datetime().nullable().default(null),
54
- bell: z.strictObject({
55
- sequence: z.number().int().positive(),
56
- at: z.string().datetime(),
57
- unread: z.boolean()
58
- }).nullable().default(null)
59
- });
60
- const terminalBellAcknowledgementSchema = z.strictObject({ sequence: z.number().int().positive() });
61
- function parseTerminalProgress(data) {
62
- const [command, rawState, rawValue, ...extra] = data.split(";");
63
- if (command !== "4" || extra.length > 0 || !/^[0-4]$/.test(rawState ?? "")) return;
64
- const state = Number(rawState);
65
- if (state === 0) return null;
66
- if (rawValue !== void 0 && rawValue !== "" && !/^\d{1,3}$/.test(rawValue)) return;
67
- const value = rawValue === void 0 || rawValue === "" ? null : Number(rawValue);
68
- if (value !== null && value > 100) return;
69
- return {
70
- state: [
71
- void 0,
72
- "normal",
73
- "error",
74
- "indeterminate",
75
- "paused"
76
- ][state],
77
- value
78
- };
79
- }
80
- const terminalAuthSchema = z.strictObject({
81
- terminalId,
82
- clientId,
83
- ...dimensions
84
- });
85
- const terminalInputSchema = z.strictObject({
86
- generation,
87
- data: z.string().max(TERMINAL_MAX_INPUT_BYTES)
88
- });
89
- const terminalBinarySchema = z.strictObject({
90
- generation,
91
- data: z.string().max(TERMINAL_MAX_INPUT_BYTES)
92
- });
93
- const terminalResizeSchema = z.strictObject({
94
- generation,
95
- ...dimensions
96
- });
97
- const terminalTakeControlSchema = z.strictObject({
98
- generation,
99
- ...dimensions
100
- });
101
- const terminalLegacyTakeControlSchema = z.strictObject({ generation });
102
- const terminalOutputAckSchema = z.strictObject({
103
- streamId,
104
- sequence: z.number().int().nonnegative()
105
- });
106
- const terminalReadyBase = {
107
- connectionId: z.string().min(1).max(128),
108
- streamId,
109
- generation,
110
- controller: z.boolean(),
111
- reset: z.literal("full")
112
- };
113
- const terminalLegacyReadySchema = z.strictObject(terminalReadyBase);
114
- const terminalReadyV2Schema = z.strictObject({
115
- ...terminalReadyBase,
116
- ...dimensions,
117
- revision: z.number().int().positive()
118
- });
119
- z.union([terminalLegacyReadySchema, terminalReadyV2Schema]);
120
- z.strictObject({
121
- ...dimensions,
122
- revision: z.number().int().positive()
123
- });
124
- z.strictObject({
125
- streamId,
126
- sequence: z.number().int().positive(),
127
- data: z.string()
128
- });
129
- z.strictObject({ title: z.string().max(256) });
130
- z.strictObject({ progress: terminalProgressSchema.nullable() });
131
- z.strictObject({ viewing: z.boolean() });
132
- z.strictObject({
133
- generation,
134
- controller: z.boolean()
135
- });
136
- z.strictObject({ exitCode: z.number().int().nullable() });
137
- z.strictObject({
138
- code: z.string().min(1).max(80),
139
- message: z.string().min(1).max(1e3),
140
- retryable: z.boolean()
141
- });
142
- function parseTerminalAuth(value) {
143
- const parsed = terminalAuthSchema.safeParse(value);
144
- return parsed.success ? parsed.data : null;
145
- }
146
- //#endregion
147
- //#region ../../packages/shared/dist/socket-protocol.js
148
- const identifierSchema = z.string().min(1).max(128);
149
- const eventEnvelope = (type, data) => z.strictObject({
150
- id: identifierSchema,
151
- type: z.literal(type),
152
- at: z.string().datetime(),
153
- data
154
- });
155
- const projectEventDataSchema = z.strictObject({
156
- projectId: identifierSchema,
157
- worktreeId: z.null()
158
- });
159
- const worktreeEventDataSchema = z.strictObject({ worktreeId: identifierSchema });
160
- const projectWorktreeEventDataSchema = z.strictObject({
161
- projectId: identifierSchema,
162
- worktreeId: identifierSchema
163
- });
164
- const operationEventDataSchema = z.strictObject({
165
- operationId: identifierSchema,
166
- worktreeId: identifierSchema
167
- });
168
- const productEventSchema = z.discriminatedUnion("type", [
169
- eventEnvelope("project.created", projectEventDataSchema),
170
- eventEnvelope("project.updated", projectEventDataSchema),
171
- eventEnvelope("project.removed", projectEventDataSchema),
172
- eventEnvelope("worktree.created", projectWorktreeEventDataSchema),
173
- eventEnvelope("worktree.updated", worktreeEventDataSchema),
174
- eventEnvelope("worktree.removed", projectWorktreeEventDataSchema),
175
- eventEnvelope("create.started", z.strictObject({
176
- projectId: identifierSchema,
177
- operationId: identifierSchema,
178
- worktreeId: z.null()
179
- })),
180
- eventEnvelope("create.completed", z.strictObject({
181
- projectId: identifierSchema,
182
- operationId: identifierSchema,
183
- worktreeId: identifierSchema
184
- })),
185
- eventEnvelope("create.failed", z.strictObject({
186
- projectId: identifierSchema,
187
- operationId: identifierSchema,
188
- worktreeId: z.null()
189
- })),
190
- eventEnvelope("terminal.created", z.strictObject({
191
- projectId: identifierSchema.optional(),
192
- worktreeId: identifierSchema,
193
- terminalId: identifierSchema
194
- })),
195
- eventEnvelope("terminal.updated", z.strictObject({
196
- worktreeId: identifierSchema,
197
- terminalId: identifierSchema
198
- })),
199
- eventEnvelope("terminal.removed", z.strictObject({
200
- worktreeId: identifierSchema,
201
- terminalId: identifierSchema
202
- })),
203
- eventEnvelope("terminal.metadata", terminalRuntimeMetadataSchema.extend({ worktreeId: z.null() })),
204
- eventEnvelope("terminal.controller_changed", z.strictObject({
205
- terminalId: identifierSchema,
206
- controlled: z.boolean(),
207
- worktreeId: z.null()
208
- })),
209
- eventEnvelope("panel.created", z.strictObject({
210
- worktreeId: identifierSchema,
211
- panelId: identifierSchema
212
- })),
213
- eventEnvelope("panel.updated", z.strictObject({
214
- worktreeId: identifierSchema,
215
- panelId: identifierSchema
216
- })),
217
- eventEnvelope("panel.open_requested", z.strictObject({
218
- worktreeId: identifierSchema,
219
- panelId: identifierSchema,
220
- sourceTerminalId: identifierSchema.nullable()
221
- })),
222
- eventEnvelope("panel.removed", z.strictObject({
223
- worktreeId: identifierSchema,
224
- panelId: identifierSchema
225
- })),
226
- eventEnvelope("workspace.open_requested", z.strictObject({
227
- worktreeId: identifierSchema,
228
- sourceTerminalId: identifierSchema
229
- })),
230
- eventEnvelope("remove.started", operationEventDataSchema.extend({ kind: z.literal("remove") })),
231
- eventEnvelope("remove.completed", operationEventDataSchema),
232
- eventEnvelope("remove.failed", operationEventDataSchema.extend({ error: z.string() }))
233
- ]);
234
- const webPanelSnapshotSchema = z.strictObject({
235
- id: z.string().min(1),
236
- kind: z.literal("web"),
237
- worktreeId: z.string().min(1),
238
- definitionId: z.string().min(1),
239
- title: z.string().min(1),
240
- launch: z.strictObject({
241
- input: z.record(z.string(), z.json()).nullable(),
242
- cwd: z.string().nullable()
243
- }),
244
- sandbox: z.strictObject({ allowSameOrigin: z.boolean() }),
245
- createdAt: z.string(),
246
- updatedAt: z.string()
247
- });
248
- const eventsSnapshotSchema = z.strictObject({
249
- at: z.string().datetime(),
250
- terminalMetadata: z.array(terminalRuntimeMetadataSchema),
251
- webPanels: z.array(webPanelSnapshotSchema)
252
- });
253
- z.unknown();
254
- function parseEventsSnapshot(value) {
255
- const parsed = eventsSnapshotSchema.safeParse(value);
256
- return parsed.success ? parsed.data : null;
257
- }
258
- function parseProductEvent(value) {
259
- const parsed = productEventSchema.safeParse(value);
260
- return parsed.success ? parsed.data : null;
261
- }
262
- //#endregion
263
- //#region ../../packages/shared/dist/index.js
264
- const TERMINAL_MAX_UPLOAD_BYTES = 50 * 1024 * 1024;
265
- const TERMINAL_EXECUTABLE_MAX_LENGTH = 4096;
266
- const TERMINAL_ARGUMENT_MAX_LENGTH = 4096;
267
- const TERMINAL_CAPTURE_MAX_LINES = 5e3;
268
- const WEB_PANEL_INPUT_MAX_BYTES = 64 * 1024;
269
- function formatCommandLine(argv) {
270
- return argv.map((value) => {
271
- if (value === "") return "\"\"";
272
- if (!/[\s"'\\]/.test(value)) return value;
273
- return `"${value.replace(/["\\]/g, "\\$&")}"`;
274
- }).join(" ");
275
- }
276
- const PROJECT_COLORS = [
277
- "rose",
278
- "orange",
279
- "amber",
280
- "emerald",
281
- "cyan",
282
- "blue",
283
- "violet",
284
- "pink"
285
- ];
286
- const browseDirectoryQuerySchema = z.object({
287
- input: z.string().trim().min(1).max(4096),
288
- hidden: z.enum(["true", "false"]).optional().default("false").transform((value) => value === "true")
289
- });
290
- const terminalCaptureQuerySchema = z.object({ lines: z.coerce.number().int().min(1).max(TERMINAL_CAPTURE_MAX_LINES).optional().default(200) });
291
- const registerProjectSchema = z.object({
292
- path: z.string().trim().min(1),
293
- name: z.string().trim().min(1).max(120).optional()
294
- });
295
- const updateProjectSchema = z.object({ color: z.enum(PROJECT_COLORS).nullable() });
296
- const terminalNameSchema = z.string().trim().min(1).max(120);
297
- const terminalArgvSchema = z.array(z.string()).min(1).max(128);
298
- const terminalPresetArgumentSchema = z.string().max(TERMINAL_ARGUMENT_MAX_LENGTH);
299
- const terminalPresetFields = {
300
- name: terminalNameSchema,
301
- executable: z.string().min(1).max(TERMINAL_EXECUTABLE_MAX_LENGTH).refine((value) => value.trim().length > 0, { message: "Executable cannot be blank" }),
302
- args: z.array(terminalPresetArgumentSchema).max(127),
303
- closeOnSuccess: z.boolean().default(false)
304
- };
305
- const repositoryTerminalPresetSchema = z.strictObject(terminalPresetFields);
306
- const repositoryTerminalPresetIdSchema = z.string().regex(/^[a-z0-9][a-z0-9._-]{0,119}$/, { message: "Preset IDs must contain only lowercase letters, numbers, dots, underscores, and hyphens" });
307
- const repositoryTerminalPresetsFileSchema = z.strictObject({
308
- version: z.literal(1),
309
- presets: z.record(repositoryTerminalPresetIdSchema, z.unknown())
310
- });
311
- const terminalPresetRevisionSchema = z.string().min(1).max(64);
312
- const initialTerminalSchema = z.object({
313
- name: terminalNameSchema,
314
- argv: terminalArgvSchema.optional(),
315
- returnToShell: z.boolean().optional(),
316
- initialSize: terminalSizeSchema.optional()
317
- });
318
- const createWorktreeSchema = z.object({
319
- name: z.string().trim().min(1).max(120),
320
- base: z.enum(["default", "current"]).default("default"),
321
- sourceWorktreeId: z.string().min(1).optional(),
322
- initialTerminal: initialTerminalSchema.optional()
323
- }).superRefine((value, context) => {
324
- if (value.base === "current" && !value.sourceWorktreeId) context.addIssue({
325
- code: "custom",
326
- path: ["sourceWorktreeId"],
327
- message: "A source tree is required when starting from current"
328
- });
329
- });
330
- const terminalCwdSchema = z.string().min(1).max(4096).refine((value) => value.trim().length > 0 && !value.includes("\0"), { message: "Working directory cannot be blank or contain NUL" });
331
- const terminalEnvironmentKeySchema = z.string().min(1).max(256).refine((value) => !value.includes("=") && !value.includes("\0"), { message: "Environment keys cannot contain equals or NUL" });
332
- const terminalShellCommandSchema = z.string().min(1).max(TERMINAL_ARGUMENT_MAX_LENGTH).refine((value) => value.trim().length > 0 && !value.includes("\0"), { message: "Shell command cannot be blank or contain NUL" });
333
- const terminalEnvironmentSchema = z.record(terminalEnvironmentKeySchema, z.string().max(TERMINAL_ARGUMENT_MAX_LENGTH).refine((value) => !value.includes("\0"), { message: "Environment values cannot contain NUL" })).refine((value) => Object.keys(value).length <= 128, { message: "Environment cannot contain more than 128 variables" });
334
- const createTerminalSchema = z.object({
335
- name: terminalNameSchema,
336
- argv: terminalArgvSchema.optional(),
337
- shellCommand: terminalShellCommandSchema.optional(),
338
- cwd: terminalCwdSchema.optional(),
339
- env: terminalEnvironmentSchema.optional(),
340
- returnToShell: z.boolean().optional(),
341
- closeOnSuccess: z.boolean().optional(),
342
- initialSize: terminalSizeSchema.optional()
343
- }).refine((value) => !(value.argv && value.shellCommand), { message: "A terminal cannot have both argv and a shell command" }).refine((value) => !(value.returnToShell && value.closeOnSuccess), { message: "A terminal cannot return to a shell and close on success" });
344
- const updateTerminalSchema = z.object({ name: terminalNameSchema });
345
- const webPanelInputSchema = z.record(z.string(), z.json());
346
- const createWebPanelSchema = z.object({
347
- definitionId: z.string().min(1).max(256),
348
- input: webPanelInputSchema.nullable().optional(),
349
- launchCwd: z.string().max(4096).nullable().optional()
350
- });
351
- const openWebPanelSchema = createWebPanelSchema.extend({
352
- newInstance: z.boolean().optional(),
353
- sourceTerminalId: z.string().min(1).max(128).nullable().optional()
354
- });
355
- const requestWorkspaceOpenSchema = z.object({ sourceTerminalId: z.string().min(1).max(128) });
356
- const webPanelStorageKeySchema = z.string().min(1).max(128);
357
- const getWebPanelStorageSchema = z.object({ key: webPanelStorageKeySchema });
358
- const setWebPanelStorageSchema = z.object({
359
- key: webPanelStorageKeySchema,
360
- value: z.json()
361
- });
362
- const deleteWebPanelStorageSchema = z.object({ key: webPanelStorageKeySchema });
363
- const createTerminalPresetSchema = z.object(terminalPresetFields);
364
- const updateTerminalPresetSchema = z.object({
365
- ...terminalPresetFields,
366
- closeOnSuccess: z.boolean().optional(),
367
- expectedUpdatedAt: terminalPresetRevisionSchema
368
- });
369
- const deleteTerminalPresetSchema = z.object({ expectedUpdatedAt: terminalPresetRevisionSchema });
370
- const packageProjectQuerySchema = z.object({ path: z.string().trim().min(1).max(4096) });
371
- const packageInstallSchema = z.object({
372
- source: z.string().trim().min(1).max(4096),
373
- projectId: z.string().min(1).optional()
374
- });
375
- const packageRemoveSchema = z.object({
376
- source: z.string().trim().min(1).max(4096),
377
- projectId: z.string().min(1).optional()
378
- });
379
- const packageUpdateSchema = z.object({ source: z.string().trim().min(1).max(4096).optional() });
380
- const packageReloadSchema = z.object({ projectId: z.string().min(1).optional() });
381
- const removeWorktreeSchema = z.object({
382
- confirmationToken: z.string().length(64),
383
- confirmDestructive: z.boolean()
384
- });
385
- z.object({
386
- project: z.string().min(1),
387
- worktreeName: z.string().trim().min(1).max(120),
388
- name: terminalNameSchema,
389
- argv: terminalArgvSchema.optional(),
390
- base: z.enum(["default", "current"]).default("default"),
391
- sourceWorktreeId: z.string().min(1).optional()
392
- }).superRefine((value, context) => {
393
- if (value.base === "current" && !value.sourceWorktreeId) context.addIssue({
394
- code: "custom",
395
- path: ["sourceWorktreeId"],
396
- message: "A source tree is required when starting from current"
397
- });
398
- });
399
- //#endregion
400
9
  //#region src/duration.ts
401
10
  const DURATION_UNITS = /* @__PURE__ */ new Map([
402
11
  ["ms", 1],
@@ -3104,4 +2713,4 @@ async function runLocalUpdate(options = {}) {
3104
2713
  }
3105
2714
  }
3106
2715
  //#endregion
3107
- export { repositoryTerminalPresetSchema as $, treeportVersion as A, terminalSizeSchema as At, createWorktreeSchema as B, disableTailscaleRemote as C, parseTerminalProgress as Ct, resolvePackagePath as D, terminalLegacyTakeControlSchema as Dt, resolveLocalApiUrl as E, terminalInputSchema as Et, WEB_PANEL_INPUT_MAX_BYTES as F, openWebPanelSchema as G, deleteWebPanelStorageSchema as H, browseDirectoryQuerySchema as I, packageReloadSchema as J, packageInstallSchema as K, createTerminalPresetSchema as L, parseDurationMs as M, TERMINAL_CAPTURE_MAX_LINES as N, runDoctor as O, terminalOutputAckSchema as Ot, TERMINAL_MAX_UPLOAD_BYTES as P, removeWorktreeSchema as Q, createTerminalSchema as R, daemonUp as S, parseTerminalAuth as St, readDaemonLogs as T, terminalBinarySchema as Tt, formatCommandLine as U, deleteTerminalPresetSchema as V, getWebPanelStorageSchema as W, packageUpdateSchema as X, packageRemoveSchema as Y, registerProjectSchema as Z, serviceStatus as _, TERMINAL_SCROLL_EXIT_SEQUENCE as _t, readLocalUpdateProgress as a, updateTerminalPresetSchema as at, daemonHealth as b, TERMINAL_SELECTION_START_SEQUENCE as bt, createUpdateStartupReporter as c, parseEventsSnapshot as ct, serviceDisable as d, TERMINAL_CONTROLLER_GRACE_MS as dt, repositoryTerminalPresetsFileSchema as et, serviceDoctorCheck as f, TERMINAL_MAX_CLIENT_MESSAGE_BYTES as ft, serviceStart as g, TERMINAL_OUTPUT_STALL_TIMEOUT_MS as gt, serviceRun as h, TERMINAL_OUTPUT_LOW_WATERMARK as ht, isCanonicalTreeportVersion as i, updateProjectSchema as it, assertLoopbackHost as j, terminalTakeControlSchema as jt, tailscaleRemoteStatus as k, terminalResizeSchema as kt, readServiceLogs as l, parseProductEvent as lt, serviceInstalled as m, TERMINAL_OUTPUT_HIGH_WATERMARK as mt, compareTreeportVersions as n, setWebPanelStorageSchema as nt, resolveLatestTreeportRelease as o, updateTerminalSchema as ot, serviceEnable as p, TERMINAL_MAX_INPUT_BYTES as pt, packageProjectQuerySchema as q, inspectLocalUpdateInstallation as r, terminalCaptureQuerySchema as rt, runLocalUpdate as s, webPanelInputSchema as st, LocalUpdateError as t, requestWorkspaceOpenSchema as tt, serviceApply as u, SOCKET_IO_PATH as ut, serviceStop as v, TERMINAL_SELECTION_CLEAR_SEQUENCE as vt, enableTailscaleRemote as w, terminalBellAcknowledgementSchema as wt, daemonStatus as x, TERMINAL_SELECTION_STOP_SEQUENCE as xt, daemonDown as y, TERMINAL_SELECTION_RESTORE_SEQUENCE as yt, createWebPanelSchema as z };
2716
+ export { treeportVersion as A, disableTailscaleRemote as C, resolvePackagePath as D, resolveLocalApiUrl as E, parseDurationMs as M, runDoctor as O, daemonUp as S, readDaemonLogs as T, serviceStatus as _, readLocalUpdateProgress as a, daemonHealth as b, createUpdateStartupReporter as c, serviceDisable as d, serviceDoctorCheck as f, serviceStart as g, serviceRun as h, isCanonicalTreeportVersion as i, assertLoopbackHost as j, tailscaleRemoteStatus as k, readServiceLogs as l, serviceInstalled as m, compareTreeportVersions as n, resolveLatestTreeportRelease as o, serviceEnable as p, inspectLocalUpdateInstallation as r, runLocalUpdate as s, LocalUpdateError as t, serviceApply as u, serviceStop as v, enableTailscaleRemote as w, daemonStatus as x, daemonDown as y };