@microvac/plugin-daytona 0.0.0-stage → 0.1.0-rc.14

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 (122) hide show
  1. package/README.md +98 -2
  2. package/dist/archive-stream-window.test.d.ts +2 -0
  3. package/dist/archive-stream-window.test.d.ts.map +1 -0
  4. package/dist/archive-stream-window.test.js +93 -0
  5. package/dist/archive-stream-window.test.js.map +1 -0
  6. package/dist/archive-stream.d.ts +10 -0
  7. package/dist/archive-stream.d.ts.map +1 -0
  8. package/dist/archive-stream.js +159 -0
  9. package/dist/archive-stream.js.map +1 -0
  10. package/dist/archive-stream.test.d.ts +2 -0
  11. package/dist/archive-stream.test.d.ts.map +1 -0
  12. package/dist/archive-stream.test.js +121 -0
  13. package/dist/archive-stream.test.js.map +1 -0
  14. package/dist/duplex-close-deadline.test.d.ts +2 -0
  15. package/dist/duplex-close-deadline.test.d.ts.map +1 -0
  16. package/dist/duplex-close-deadline.test.js +106 -0
  17. package/dist/duplex-close-deadline.test.js.map +1 -0
  18. package/dist/duplex-command-stream.d.ts +98 -0
  19. package/dist/duplex-command-stream.d.ts.map +1 -0
  20. package/dist/duplex-command-stream.js +218 -0
  21. package/dist/duplex-command-stream.js.map +1 -0
  22. package/dist/duplex-command-stream.live.test.d.ts +2 -0
  23. package/dist/duplex-command-stream.live.test.d.ts.map +1 -0
  24. package/dist/duplex-command-stream.live.test.js +324 -0
  25. package/dist/duplex-command-stream.live.test.js.map +1 -0
  26. package/dist/duplex-command-stream.test.d.ts +2 -0
  27. package/dist/duplex-command-stream.test.d.ts.map +1 -0
  28. package/dist/duplex-command-stream.test.js +519 -0
  29. package/dist/duplex-command-stream.test.js.map +1 -0
  30. package/dist/file-sync-capacity.live.test.d.ts +2 -0
  31. package/dist/file-sync-capacity.live.test.d.ts.map +1 -0
  32. package/dist/file-sync-capacity.live.test.js +122 -0
  33. package/dist/file-sync-capacity.live.test.js.map +1 -0
  34. package/dist/file-sync-capacity.test.d.ts +2 -0
  35. package/dist/file-sync-capacity.test.d.ts.map +1 -0
  36. package/dist/file-sync-capacity.test.js +337 -0
  37. package/dist/file-sync-capacity.test.js.map +1 -0
  38. package/dist/file-sync-diagnostics.test.d.ts +2 -0
  39. package/dist/file-sync-diagnostics.test.d.ts.map +1 -0
  40. package/dist/file-sync-diagnostics.test.js +165 -0
  41. package/dist/file-sync-diagnostics.test.js.map +1 -0
  42. package/dist/file-sync.d.ts +80 -0
  43. package/dist/file-sync.d.ts.map +1 -0
  44. package/dist/file-sync.js +1362 -0
  45. package/dist/file-sync.js.map +1 -0
  46. package/dist/file-sync.test.d.ts +2 -0
  47. package/dist/file-sync.test.d.ts.map +1 -0
  48. package/dist/file-sync.test.js +1214 -0
  49. package/dist/file-sync.test.js.map +1 -0
  50. package/dist/idle-activity.d.ts +40 -0
  51. package/dist/idle-activity.d.ts.map +1 -0
  52. package/dist/idle-activity.js +145 -0
  53. package/dist/idle-activity.js.map +1 -0
  54. package/dist/idle-activity.test.d.ts +2 -0
  55. package/dist/idle-activity.test.d.ts.map +1 -0
  56. package/dist/idle-activity.test.js +159 -0
  57. package/dist/idle-activity.test.js.map +1 -0
  58. package/dist/index.d.ts +3 -0
  59. package/dist/index.d.ts.map +1 -0
  60. package/dist/index.js +3 -0
  61. package/dist/index.js.map +1 -0
  62. package/dist/lease-tracing.d.ts +7 -0
  63. package/dist/lease-tracing.d.ts.map +1 -0
  64. package/dist/lease-tracing.js +31 -0
  65. package/dist/lease-tracing.js.map +1 -0
  66. package/dist/lease-tracing.test.d.ts +2 -0
  67. package/dist/lease-tracing.test.d.ts.map +1 -0
  68. package/dist/lease-tracing.test.js +298 -0
  69. package/dist/lease-tracing.test.js.map +1 -0
  70. package/dist/login-pty.d.ts +162 -0
  71. package/dist/login-pty.d.ts.map +1 -0
  72. package/dist/login-pty.js +258 -0
  73. package/dist/login-pty.js.map +1 -0
  74. package/dist/login-pty.test.d.ts +2 -0
  75. package/dist/login-pty.test.d.ts.map +1 -0
  76. package/dist/login-pty.test.js +319 -0
  77. package/dist/login-pty.test.js.map +1 -0
  78. package/dist/manifest.d.ts +5 -0
  79. package/dist/manifest.d.ts.map +1 -0
  80. package/dist/manifest.js +189 -0
  81. package/dist/manifest.js.map +1 -0
  82. package/dist/one-shot-exec-deadline.test.d.ts +2 -0
  83. package/dist/one-shot-exec-deadline.test.d.ts.map +1 -0
  84. package/dist/one-shot-exec-deadline.test.js +73 -0
  85. package/dist/one-shot-exec-deadline.test.js.map +1 -0
  86. package/dist/plugin.d.ts +103 -0
  87. package/dist/plugin.d.ts.map +1 -0
  88. package/dist/plugin.js +3572 -0
  89. package/dist/plugin.js.map +1 -0
  90. package/dist/plugin.test.d.ts +2 -0
  91. package/dist/plugin.test.d.ts.map +1 -0
  92. package/dist/plugin.test.js +7276 -0
  93. package/dist/plugin.test.js.map +1 -0
  94. package/dist/pty-chunked-input.d.ts +48 -0
  95. package/dist/pty-chunked-input.d.ts.map +1 -0
  96. package/dist/pty-chunked-input.js +74 -0
  97. package/dist/pty-chunked-input.js.map +1 -0
  98. package/dist/pty-chunked-input.test.d.ts +2 -0
  99. package/dist/pty-chunked-input.test.d.ts.map +1 -0
  100. package/dist/pty-chunked-input.test.js +115 -0
  101. package/dist/pty-chunked-input.test.js.map +1 -0
  102. package/dist/runner-ingress.sdk-integration.d.ts +2 -0
  103. package/dist/runner-ingress.sdk-integration.d.ts.map +1 -0
  104. package/dist/runner-ingress.sdk-integration.js +87 -0
  105. package/dist/runner-ingress.sdk-integration.js.map +1 -0
  106. package/dist/session-command-completion.test.d.ts +2 -0
  107. package/dist/session-command-completion.test.d.ts.map +1 -0
  108. package/dist/session-command-completion.test.js +251 -0
  109. package/dist/session-command-completion.test.js.map +1 -0
  110. package/dist/session-stream-exit.d.ts +13 -0
  111. package/dist/session-stream-exit.d.ts.map +1 -0
  112. package/dist/session-stream-exit.js +48 -0
  113. package/dist/session-stream-exit.js.map +1 -0
  114. package/dist/tar-listing.test.d.ts +2 -0
  115. package/dist/tar-listing.test.d.ts.map +1 -0
  116. package/dist/tar-listing.test.js +220 -0
  117. package/dist/tar-listing.test.js.map +1 -0
  118. package/dist/worker.d.ts +3 -0
  119. package/dist/worker.d.ts.map +1 -0
  120. package/dist/worker.js +5 -0
  121. package/dist/worker.js.map +1 -0
  122. package/package.json +42 -4
@@ -0,0 +1,106 @@
1
+ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
2
+ const createSandbox = vi.hoisted(() => vi.fn());
3
+ vi.mock("@daytonaio/sdk", () => ({
4
+ Daytona: class {
5
+ create = createSandbox;
6
+ get = vi.fn();
7
+ },
8
+ DaytonaNotFoundError: class extends Error {
9
+ },
10
+ DaytonaTimeoutError: class extends Error {
11
+ },
12
+ }));
13
+ import { DUPLEX_CHANNEL_CLOSE_KILL_TIMEOUT_MS, openDaytonaDuplexChannelSession } from "./duplex-command-stream.js";
14
+ import plugin, { __resetDaytonaSandboxHandleCacheForTest } from "./plugin.js";
15
+ const HOST_DUPLEX_CLOSE_TIMEOUT_MS = 10_000;
16
+ function fakePty() {
17
+ return {
18
+ waitForConnection: vi.fn(async () => { }),
19
+ sendInput: vi.fn(async () => { }),
20
+ wait: vi.fn(() => new Promise(() => { })),
21
+ kill: vi.fn(async () => { }),
22
+ disconnect: vi.fn(async () => { }),
23
+ };
24
+ }
25
+ async function fixture() {
26
+ const pty = fakePty();
27
+ const sandbox = {
28
+ id: "fixture-sandbox", name: "paperclip-sandbox", state: "started", recoverable: false, target: "us",
29
+ errorReason: null, autoDeleteInterval: -1, autoStopInterval: 15,
30
+ setAutostopInterval: vi.fn(async () => { }), setAutoDeleteInterval: vi.fn(async () => { }),
31
+ setTtl: vi.fn(async () => { }), refreshData: vi.fn(async () => { }),
32
+ getWorkDir: vi.fn(async () => "/home/daytona"), getUserHomeDir: vi.fn(async () => "/home/daytona"),
33
+ start: vi.fn(async () => { }), stop: vi.fn(async () => { }), delete: vi.fn(async () => { }),
34
+ fs: { createFolder: vi.fn(async () => { }), uploadFile: vi.fn(async () => { }), deleteFile: vi.fn(async () => { }) },
35
+ process: {
36
+ executeCommand: vi.fn(async () => ({ exitCode: 0, result: "bash", artifacts: { stdout: "bash" } })),
37
+ createPty: vi.fn(async () => pty),
38
+ },
39
+ };
40
+ createSandbox.mockResolvedValue(sandbox);
41
+ await plugin.definition.onEnvironmentAcquireLease({
42
+ driverKey: "daytona", companyId: "fixture-company", environmentId: "fixture-environment", runId: "fixture-run",
43
+ config: { apiKey: "fixture-not-a-key", image: "fixture-image", timeoutMs: 3_000, livenessTimeoutMs: 1_000, reuseLease: true },
44
+ });
45
+ const opened = await plugin.definition.onDuplexChannelOpen({
46
+ driverKey: "daytona", companyId: "fixture-company", environmentId: "fixture-environment",
47
+ providerLeaseId: sandbox.id, command: ["fixture-bridge"], hostRouteId: "fixture-route",
48
+ });
49
+ return { pty, opened };
50
+ }
51
+ describe("Daytona duplex channel close deadline", () => {
52
+ beforeEach(() => { __resetDaytonaSandboxHandleCacheForTest(); createSandbox.mockReset(); });
53
+ afterEach(() => { vi.useRealTimers(); __resetDaytonaSandboxHandleCacheForTest(); });
54
+ it("keeps the close kill deadline well inside the host close deadline", () => {
55
+ expect(DUPLEX_CHANNEL_CLOSE_KILL_TIMEOUT_MS).toBeLessThanOrEqual(HOST_DUPLEX_CLOSE_TIMEOUT_MS / 2);
56
+ });
57
+ it("releases the session socket at the kill deadline when the remote kill never settles", async () => {
58
+ const pty = fakePty();
59
+ const session = await openDaytonaDuplexChannelSession({ createPty: async () => pty }, ["fixture-bridge"]);
60
+ pty.kill.mockImplementation(() => new Promise(() => { }));
61
+ vi.useFakeTimers();
62
+ let closed = false;
63
+ const closing = session.close().then(() => { closed = true; });
64
+ await vi.advanceTimersByTimeAsync(DUPLEX_CHANNEL_CLOSE_KILL_TIMEOUT_MS - 1);
65
+ expect(closed).toBe(false);
66
+ expect(pty.disconnect).not.toHaveBeenCalled();
67
+ await vi.advanceTimersByTimeAsync(1);
68
+ await closing;
69
+ expect(pty.disconnect).toHaveBeenCalledTimes(1);
70
+ });
71
+ it("acknowledges a bound close inside the host deadline when the remote kill never settles", async () => {
72
+ const { pty, opened } = await fixture();
73
+ pty.kill.mockImplementation(() => new Promise(() => { }));
74
+ vi.useFakeTimers();
75
+ let ack;
76
+ const closing = plugin.definition.onDuplexChannelClose({ hostRouteId: opened.hostRouteId })
77
+ .then((value) => { ack = value; });
78
+ await vi.advanceTimersByTimeAsync(HOST_DUPLEX_CLOSE_TIMEOUT_MS - 1_000);
79
+ expect(ack).toEqual(opened);
80
+ await closing;
81
+ expect(pty.kill).toHaveBeenCalledTimes(1);
82
+ expect(pty.disconnect).toHaveBeenCalledTimes(1);
83
+ await expect(plugin.definition.onDuplexChannelClose({ hostRouteId: opened.hostRouteId })).resolves.toEqual(opened);
84
+ await expect(plugin.definition.onDuplexChannelOpen({
85
+ driverKey: "daytona", companyId: "fixture-company", environmentId: "fixture-environment",
86
+ providerLeaseId: "fixture-sandbox", command: ["fixture-bridge"], hostRouteId: opened.hostRouteId,
87
+ })).rejects.toThrow("already been used");
88
+ });
89
+ it("still waits for a kill that answers inside the deadline before it releases the socket", async () => {
90
+ const { pty, opened } = await fixture();
91
+ let finishKill;
92
+ pty.kill.mockImplementation(() => new Promise((resolve) => { finishKill = resolve; }));
93
+ vi.useFakeTimers();
94
+ let ack;
95
+ const closing = plugin.definition.onDuplexChannelClose({ hostRouteId: opened.hostRouteId })
96
+ .then((value) => { ack = value; });
97
+ await vi.advanceTimersByTimeAsync(1_000);
98
+ expect(ack).toBeUndefined();
99
+ expect(pty.disconnect).not.toHaveBeenCalled();
100
+ finishKill();
101
+ await closing;
102
+ expect(ack).toEqual(opened);
103
+ expect(pty.disconnect).toHaveBeenCalledTimes(1);
104
+ });
105
+ });
106
+ //# sourceMappingURL=duplex-close-deadline.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"duplex-close-deadline.test.js","sourceRoot":"","sources":["../src/duplex-close-deadline.test.ts"],"names":[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AC,CAAC;IAEH,EAAE,CAAC,uFAAuF,EAAE,KAAK,IAAI,EAAE;QACrG,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,MAAM,OAAO,EAAE,CAAC;QACxC,IAAI,UAAuB,CAAC;QAC5B,GAAG,CAAC,IAAI,CAAC,kBAAkB,CAAC,GAAG,EAAE,CAAC,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,EAAE,GAAG,UAAU,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAC7F,EAAE,CAAC,aAAa,EAAE,CAAC;QAEnB,IAAI,GAAY,CAAC;QACjB,MAAM,OAAO,GAAG,MAAM,CAAC,UAAU,CAAC,oBAAqB,CAAC,EAAE,WAAW,EAAE,MAAM,CAAC,WAAW,EAAE,CAAC;aACzF,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,GAAG,GAAG,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;QACrC,MAAM,EAAE,CAAC,wBAAwB,CAAC,KAAK,CAAC,CAAC;QACzC,MAAM,CAAC,GAAG,CAAC,CAAC,aAAa,EAAE,CAAC;QAC5B,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,GAAG,CAAC,gBAAgB,EAAE,CAAC;QAE9C,UAAU,EAAE,CAAC;QACb,MAAM,OAAO,CAAC;QACd,MAAM,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QAC5B,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC;IAClD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -0,0 +1,98 @@
1
+ import type { DaytonaPtyProcess } from "./login-pty.js";
2
+ export type { DaytonaPtyCreateOptions, DaytonaPtyHandle, DaytonaPtyProcess, } from "./login-pty.js";
3
+ /**
4
+ * A live duplex channel session for one command. The session allocates a real
5
+ * pseudo-terminal in raw mode, streams the raw output, accepts host input, and
6
+ * stops the child. The shape matches the worker duplex channel session, so the
7
+ * worker forwards the data and the exit with no adapter.
8
+ */
9
+ export interface DuplexChannelSession {
10
+ /** Registers the one data listener. The session streams each raw byte chunk in order. */
11
+ onData(listener: (chunk: Uint8Array) => void): void;
12
+ /** Writes raw input bytes to the pseudo-terminal. */
13
+ write(data: Uint8Array): void;
14
+ /**
15
+ * Resolves when the command ends or the transport closes. A numeric `exitCode`
16
+ * is a real process exit. `transportClosed` is true when the pseudo-terminal
17
+ * socket closed with no exit data, so the caller can tell a real process exit
18
+ * from a reason-less transport close.
19
+ */
20
+ wait(): Promise<{
21
+ exitCode: number | null;
22
+ transportClosed: boolean;
23
+ }>;
24
+ /** Stops the child process. Safe to call more than one time. */
25
+ kill(): void;
26
+ /** Releases the session resources. Safe to call more than one time. */
27
+ close(): Promise<void>;
28
+ }
29
+ /**
30
+ * Opens a {@link DuplexChannelSession} for `command`. The transport calls it one
31
+ * time. `command` is an argument vector: element 0 is the program and the rest
32
+ * are its arguments. The session quotes each element, so a shell metacharacter in
33
+ * an element cannot inject a shell command.
34
+ */
35
+ export type DuplexChannelSessionOpener = (command: readonly string[]) => Promise<DuplexChannelSession>;
36
+ /**
37
+ * The typed, closed reason for a duplex channel write failure. The seam reports
38
+ * only this constant, never the raw provider error text. It maps to the host
39
+ * telemetry `write_error` loss reason.
40
+ */
41
+ export declare const DAYTONA_DUPLEX_WRITE_ERROR_REASON: "write_error";
42
+ /** The typed reason a rejected host-to-sandbox write reports. */
43
+ export type DaytonaDuplexWriteErrorReason = typeof DAYTONA_DUPLEX_WRITE_ERROR_REASON;
44
+ /** The options for the Daytona duplex channel session. */
45
+ export interface DaytonaDuplexChannelOptions {
46
+ /** The working directory for the duplex channel PTY. Defaults to the sandbox default. */
47
+ cwd?: string;
48
+ /**
49
+ * The absolute sandbox path for the gateway diagnostics. The wrapper redirects
50
+ * the terminal's stderr to this path, so a diagnostic line never reaches the
51
+ * stdout frame stream. Defaults to a per-channel path under `/tmp`.
52
+ */
53
+ diagnosticsPath?: string;
54
+ /**
55
+ * The write-error seam. The session calls it one time when a host-to-sandbox
56
+ * `sendInput` rejects. The session then ends the channel at once. The seam
57
+ * carries only the typed {@link DaytonaDuplexWriteErrorReason}; the raw provider
58
+ * error never reaches it.
59
+ */
60
+ onWriteError?: (reason: DaytonaDuplexWriteErrorReason) => void;
61
+ }
62
+ export declare const DUPLEX_CHANNEL_CLOSE_KILL_TIMEOUT_MS = 5000;
63
+ /**
64
+ * Builds the launch wrapper input line for the duplex channel. `command` is an
65
+ * argument vector: element 0 is the program and the rest are its arguments.
66
+ *
67
+ * The wrapper does three steps in order:
68
+ * 1. `exec 2>'<diagnosticsPath>'` redirects the shell's stderr to the file. The
69
+ * later `exec` inherits it, so the gateway diagnostics land in the file and
70
+ * never on the stdout frame stream.
71
+ * 2. `stty raw -echo` sets the terminal to raw mode with echo off, so the
72
+ * terminal neither echoes host input as data nor translates newlines.
73
+ * 3. `exec '<program>' '<arg>'...` replaces the shell with the gateway, so the
74
+ * PTY runs the gateway directly and the gateway exit code becomes the PTY
75
+ * exit code.
76
+ *
77
+ * The wrapper quotes the diagnostics path and every command argument as a
78
+ * single-quoted shell word. So a shell metacharacter in a path or an argument
79
+ * stays literal text and cannot inject a shell command.
80
+ */
81
+ export declare function buildDuplexChannelLaunchWrapper(command: readonly string[], diagnosticsPath: string): string;
82
+ /**
83
+ * Opens a Daytona duplex channel PTY session for `command` and returns it as a
84
+ * {@link DuplexChannelSession}. The session allocates a real pseudo-terminal in
85
+ * raw mode, streams the raw output, accepts host input, and stops the child.
86
+ *
87
+ * The function forwards the terminal bytes unchanged. It buffers the output
88
+ * until the transport registers the listener, so no early chunk is lost.
89
+ */
90
+ export declare function openDaytonaDuplexChannelSession(process: DaytonaPtyProcess, command: readonly string[], options?: DaytonaDuplexChannelOptions): Promise<DuplexChannelSession>;
91
+ /**
92
+ * Creates a {@link DuplexChannelSessionOpener} bound to a Daytona `process`. Pass
93
+ * `sandbox.process` from the Daytona SDK. The opener runs the gateway command on a
94
+ * raw pseudo-terminal, streams the output, accepts host input, and stops the child
95
+ * for a terminal state.
96
+ */
97
+ export declare function createDaytonaDuplexChannelSessionOpener(process: DaytonaPtyProcess, options?: DaytonaDuplexChannelOptions): DuplexChannelSessionOpener;
98
+ //# sourceMappingURL=duplex-command-stream.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"duplex-command-stream.d.ts","sourceRoot":"","sources":["../src/duplex-command-stream.ts"],"names":[],"mappings":"AAmCA,OAAO,KAAK,EAGV,iBAAiB,EAClB,MAAM,gBAAgB,CAAC;AAExB,YAAY,EACV,uBAAuB,EACvB,gBAAgB,EAChB,iBAAiB,GAClB,MAAM,gBAAgB,CAAC;AAIxB;;;;;GAKG;AACH,MAAM,WAAW,oBAAoB;IACnC,yFAAyF;IACzF,MAAM,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,UAAU,KAAK,IAAI,GAAG,IAAI,CAAC;IACpD,qDAAqD;IACrD,KAAK,CAAC,IAAI,EAAE,UAAU,GAAG,IAAI,CAAC;IAC9B;;;;;OAKG;IACH,IAAI,IAAI,OAAO,CAAC;QAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;QAAC,eAAe,EAAE,OAAO,CAAA;KAAE,CAAC,CAAC;IACvE,gEAAgE;IAChE,IAAI,IAAI,IAAI,CAAC;IACb,uEAAuE;IACvE,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB;AAED;;;;;GAKG;AACH,MAAM,MAAM,0BAA0B,GAAG,CACvC,OAAO,EAAE,SAAS,MAAM,EAAE,KACvB,OAAO,CAAC,oBAAoB,CAAC,CAAC;AAEnC;;;;GAIG;AACH,eAAO,MAAM,iCAAiC,EAAG,aAAsB,CAAC;AAExE,iEAAiE;AACjE,MAAM,MAAM,6BAA6B,GAAG,OAAO,iCAAiC,CAAC;AAErF,0DAA0D;AAC1D,MAAM,WAAW,2BAA2B;IAC1C,yFAAyF;IACzF,GAAG,CAAC,EAAE,MAAM,CAAC;IACb;;;;OAIG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB;;;;;OAKG;IACH,YAAY,CAAC,EAAE,CAAC,MAAM,EAAE,6BAA6B,KAAK,IAAI,CAAC;CAChE;AAED,eAAO,MAAM,oCAAoC,OAAQ,CAAC;AAoC1D;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,+BAA+B,CAC7C,OAAO,EAAE,SAAS,MAAM,EAAE,EAC1B,eAAe,EAAE,MAAM,GACtB,MAAM,CASR;AAED;;;;;;;GAOG;AACH,wBAAsB,+BAA+B,CACnD,OAAO,EAAE,iBAAiB,EAC1B,OAAO,EAAE,SAAS,MAAM,EAAE,EAC1B,OAAO,CAAC,EAAE,2BAA2B,GACpC,OAAO,CAAC,oBAAoB,CAAC,CA2G/B;AAED;;;;;GAKG;AACH,wBAAgB,uCAAuC,CACrD,OAAO,EAAE,iBAAiB,EAC1B,OAAO,CAAC,EAAE,2BAA2B,GACpC,0BAA0B,CAG5B"}
@@ -0,0 +1,218 @@
1
+ // The Daytona duplex command stream for the sandbox callback bridge. The bridge
2
+ // needs one live bidirectional byte stream: the host writes request frames to the
3
+ // process, and the process writes response frames back, on one connection while
4
+ // the command runs. This module binds a Daytona pseudo-terminal (PTY) to a small
5
+ // session that the duplex transport consumes, so the gateway runs on a real
6
+ // terminal, streams its output, and receives host input.
7
+ //
8
+ // Primitive choice (the first acceptance criterion of the phase): the Daytona SDK
9
+ // proves two primitives. The ordinary session primitive (`createSession` plus
10
+ // `executeSessionCommand` plus `getSessionCommandLogs`) dispatches a command and
11
+ // tails its output, split into separate stdout and stderr streams. It exposes no
12
+ // call that writes bytes to a running command's stdin. The PTY primitive
13
+ // (`createPty`) exposes `sendInput` for host-to-process bytes and one `onData`
14
+ // callback for process-to-host bytes, on one live socket. Only the PTY carries a
15
+ // bidirectional stream on one connection, so this module uses the PTY. The
16
+ // characterization test in `duplex-command-stream.test.ts` records the evidence.
17
+ //
18
+ // Clean stream: a PTY echoes its input and translates newlines by default
19
+ // (`ICRNL` on input, `ONLCR` on output). The frames are newline-delimited JSON, so
20
+ // echo and newline translation corrupt the stream. The launch wrapper runs
21
+ // `stty raw -echo` before it starts the gateway, so the terminal becomes an 8-bit
22
+ // transparent path with no echo and no newline translation. The wrapper also
23
+ // redirects the gateway diagnostics to a file, so a diagnostic line never reaches
24
+ // the stdout frame stream. The wrapper starts the gateway with `exec`, so the PTY
25
+ // runs the gateway directly and the gateway exit code becomes the PTY exit code.
26
+ //
27
+ // Dependency boundary: this provider plugin ships standalone (the workspace
28
+ // excludes `packages/plugins/sandbox-providers/**`). So the module imports no
29
+ // workspace package. It reuses the narrow Daytona PTY surface that
30
+ // `login-pty.ts` declares (`DaytonaPtyProcess`, `DaytonaPtyHandle`,
31
+ // `DaytonaPtyCreateOptions`), so a caller passes `sandbox.process` with no
32
+ // adapter. The narrow surface keeps the module unit-testable with a fake PTY.
33
+ import { randomUUID } from "node:crypto";
34
+ import { sendPtyInputInChunks } from "./pty-chunked-input.js";
35
+ /**
36
+ * The typed, closed reason for a duplex channel write failure. The seam reports
37
+ * only this constant, never the raw provider error text. It maps to the host
38
+ * telemetry `write_error` loss reason.
39
+ */
40
+ export const DAYTONA_DUPLEX_WRITE_ERROR_REASON = "write_error";
41
+ export const DUPLEX_CHANNEL_CLOSE_KILL_TIMEOUT_MS = 5_000;
42
+ async function settleWithin(action, timeoutMs) {
43
+ let timer;
44
+ try {
45
+ await Promise.race([
46
+ action.catch(() => undefined),
47
+ new Promise((resolve) => { timer = setTimeout(resolve, timeoutMs); }),
48
+ ]);
49
+ }
50
+ finally {
51
+ clearTimeout(timer);
52
+ }
53
+ }
54
+ // The terminal size for the duplex channel PTY. The channel carries bytes, not a
55
+ // visible UI, so a fixed standard size is enough. A fixed size keeps the launch
56
+ // deterministic.
57
+ const DUPLEX_CHANNEL_PTY_COLS = 120;
58
+ const DUPLEX_CHANNEL_PTY_ROWS = 30;
59
+ /**
60
+ * The input terminator that submits the launch wrapper line. The terminal reads
61
+ * the carriage return as the Enter key, so the shell runs the wrapper line.
62
+ */
63
+ const PTY_COMMAND_TERMINATOR = "\r";
64
+ /**
65
+ * Quotes one value for a POSIX shell. The result is one single-quoted word, so
66
+ * the shell reads it as literal text and never expands or splits it. The function
67
+ * closes the quote, adds an escaped single quote, and reopens the quote for each
68
+ * single quote in the value.
69
+ */
70
+ function shellQuote(value) {
71
+ return `'${value.replace(/'/g, `'"'"'`)}'`;
72
+ }
73
+ /**
74
+ * Builds the launch wrapper input line for the duplex channel. `command` is an
75
+ * argument vector: element 0 is the program and the rest are its arguments.
76
+ *
77
+ * The wrapper does three steps in order:
78
+ * 1. `exec 2>'<diagnosticsPath>'` redirects the shell's stderr to the file. The
79
+ * later `exec` inherits it, so the gateway diagnostics land in the file and
80
+ * never on the stdout frame stream.
81
+ * 2. `stty raw -echo` sets the terminal to raw mode with echo off, so the
82
+ * terminal neither echoes host input as data nor translates newlines.
83
+ * 3. `exec '<program>' '<arg>'...` replaces the shell with the gateway, so the
84
+ * PTY runs the gateway directly and the gateway exit code becomes the PTY
85
+ * exit code.
86
+ *
87
+ * The wrapper quotes the diagnostics path and every command argument as a
88
+ * single-quoted shell word. So a shell metacharacter in a path or an argument
89
+ * stays literal text and cannot inject a shell command.
90
+ */
91
+ export function buildDuplexChannelLaunchWrapper(command, diagnosticsPath) {
92
+ if (command.length === 0) {
93
+ throw new Error("The duplex channel launch command needs at least one argument.");
94
+ }
95
+ const quotedCommand = command.map(shellQuote).join(" ");
96
+ return (`exec 2>${shellQuote(diagnosticsPath)}; stty raw -echo; ` +
97
+ `exec ${quotedCommand}${PTY_COMMAND_TERMINATOR}`);
98
+ }
99
+ /**
100
+ * Opens a Daytona duplex channel PTY session for `command` and returns it as a
101
+ * {@link DuplexChannelSession}. The session allocates a real pseudo-terminal in
102
+ * raw mode, streams the raw output, accepts host input, and stops the child.
103
+ *
104
+ * The function forwards the terminal bytes unchanged. It buffers the output
105
+ * until the transport registers the listener, so no early chunk is lost.
106
+ */
107
+ export async function openDaytonaDuplexChannelSession(process, command, options) {
108
+ let listener = null;
109
+ let buffered = Buffer.alloc(0);
110
+ const diagnosticsPath = options?.diagnosticsPath ?? `/tmp/paperclip-duplex-${randomUUID()}.log`;
111
+ const handle = await process.createPty({
112
+ id: `paperclip-duplex-${randomUUID()}`,
113
+ ...(options?.cwd ? { cwd: options.cwd } : {}),
114
+ cols: DUPLEX_CHANNEL_PTY_COLS,
115
+ rows: DUPLEX_CHANNEL_PTY_ROWS,
116
+ onData: (data) => {
117
+ // Forward the raw bytes unchanged; the frame codec owns the
118
+ // newline-delimited JSON parsing and any multi-byte character
119
+ // reassembly on the read side.
120
+ if (data.byteLength === 0)
121
+ return;
122
+ if (listener)
123
+ listener(data);
124
+ else
125
+ buffered = buffered.length === 0 ? Buffer.from(data) : Buffer.concat([buffered, data]);
126
+ },
127
+ });
128
+ await handle.waitForConnection();
129
+ // Start the gateway through the raw-mode wrapper. Raw mode with echo off stops
130
+ // the terminal from echoing host input back as data and from translating the
131
+ // frame newlines. The diagnostics redirect keeps the stdout frame stream clean.
132
+ await handle.sendInput(buildDuplexChannelLaunchWrapper(command, diagnosticsPath));
133
+ // Report a host-to-sandbox write failure one time and end the channel at once.
134
+ // The seam carries only the typed reason; the raw provider error never leaves
135
+ // this scope. The channel end propagates the loss up through the exit.
136
+ //
137
+ // `channelTerminated` turns true on the first rejected chunk, before the early
138
+ // return, so a later queued write reads it and sends no chunk. Without the flag
139
+ // a queued write runs after the terminal kill and calls `sendInput` on the
140
+ // closed transport.
141
+ let channelTerminated = false;
142
+ let writeErrorReported = false;
143
+ const endOnWriteError = () => {
144
+ channelTerminated = true;
145
+ if (writeErrorReported)
146
+ return;
147
+ writeErrorReported = true;
148
+ options?.onWriteError?.(DAYTONA_DUPLEX_WRITE_ERROR_REASON);
149
+ void handle.kill().catch(() => undefined);
150
+ };
151
+ // The tail of the write chain. The chunker awaits each chunk, so one write can
152
+ // suspend between its chunks. The chain runs each write after the previous
153
+ // write ends, so the chunks of two writes never interleave on the wire. The
154
+ // chain never rejects, because the chunker maps a rejected send to
155
+ // `endOnWriteError` and returns.
156
+ let writeChain = Promise.resolve();
157
+ return {
158
+ onData(next) {
159
+ listener = next;
160
+ if (buffered.length > 0) {
161
+ const pending = buffered;
162
+ buffered = Buffer.alloc(0);
163
+ next(pending);
164
+ }
165
+ },
166
+ write(data) {
167
+ // Send the input as byte-bounded chunks under the provider message cap. A
168
+ // whole payload in one message can cross the cap and take the channel down,
169
+ // so the chunker slices the payload and sends each chunk in order. The chain
170
+ // runs this write after the previous write ends, so two writes keep their
171
+ // order and never interleave their chunks. A write error must not throw into
172
+ // the transport, so the transport's stream stays the single result path. On
173
+ // a rejected chunk, the chunker ends the channel one time through
174
+ // `endOnWriteError` and sends no later chunk. The raw provider error never
175
+ // reaches a sink.
176
+ //
177
+ // A rejected chunk terminalizes the channel and kills the transport. So this
178
+ // write skips the send when `channelTerminated` is true, and a queued write
179
+ // never calls `sendInput` on the closed transport.
180
+ writeChain = writeChain.then(() => {
181
+ if (channelTerminated)
182
+ return;
183
+ return sendPtyInputInChunks((chunk) => handle.sendInput(chunk), data, endOnWriteError);
184
+ });
185
+ },
186
+ async wait() {
187
+ const result = await handle.wait();
188
+ if (typeof result.exitCode === "number") {
189
+ // A numeric exit code is a real process exit. The SDK parses it from the
190
+ // pseudo-terminal WebSocket close reason (for example `{"exitCode":0}`).
191
+ return { exitCode: result.exitCode, transportClosed: false };
192
+ }
193
+ // A non-numeric exit code marks a reason-less transport close: the socket
194
+ // closed with no exit data. It is a transport close, not a process exit.
195
+ return { exitCode: null, transportClosed: true };
196
+ },
197
+ kill() {
198
+ void handle.kill().catch(() => undefined);
199
+ },
200
+ async close() {
201
+ // Stop the child and release the socket. `kill` ends the gateway and `wait`
202
+ // resolves with the exit; `disconnect` releases the PTY socket. Both are
203
+ // safe to call more than one time, so close stays idempotent.
204
+ await settleWithin(handle.kill(), DUPLEX_CHANNEL_CLOSE_KILL_TIMEOUT_MS);
205
+ await handle.disconnect().catch(() => undefined);
206
+ },
207
+ };
208
+ }
209
+ /**
210
+ * Creates a {@link DuplexChannelSessionOpener} bound to a Daytona `process`. Pass
211
+ * `sandbox.process` from the Daytona SDK. The opener runs the gateway command on a
212
+ * raw pseudo-terminal, streams the output, accepts host input, and stops the child
213
+ * for a terminal state.
214
+ */
215
+ export function createDaytonaDuplexChannelSessionOpener(process, options) {
216
+ return (command) => openDaytonaDuplexChannelSession(process, command, options);
217
+ }
218
+ //# sourceMappingURL=duplex-command-stream.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"duplex-command-stream.js","sourceRoot":"","sources":["../src/duplex-command-stream.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAChF,kFAAkF;AAClF,gFAAgF;AAChF,iFAAiF;AACjF,4EAA4E;AAC5E,yDAAyD;AACzD,EAAE;AACF,kFAAkF;AAClF,8EAA8E;AAC9E,iFAAiF;AACjF,iFAAiF;AACjF,yEAAyE;AACzE,+EAA+E;AAC/E,iFAAiF;AACjF,2EAA2E;AAC3E,iFAAiF;AACjF,EAAE;AACF,0EAA0E;AAC1E,mFAAmF;AACnF,2EAA2E;AAC3E,kFAAkF;AAClF,6EAA6E;AAC7E,kFAAkF;AAClF,kFAAkF;AAClF,iFAAiF;AACjF,EAAE;AACF,4EAA4E;AAC5E,8EAA8E;AAC9E,mEAAmE;AACnE,oEAAoE;AACpE,2EAA2E;AAC3E,8EAA8E;AAE9E,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAczC,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAoC9D;;;;GAIG;AACH,MAAM,CAAC,MAAM,iCAAiC,GAAG,aAAsB,CAAC;AAwBxE,MAAM,CAAC,MAAM,oCAAoC,GAAG,KAAK,CAAC;AAE1D,KAAK,UAAU,YAAY,CAAC,MAAwB,EAAE,SAAiB;IACrE,IAAI,KAAgD,CAAC;IACrD,IAAI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,CAAC;YACnC,IAAI,OAAO,MAAM,CAAC,QAAQ,KAAK,QAAQ,EAAE,CAAC;gBACxC,yEAAyE;gBACzE,yEAAyE;gBACzE,OAAO,EAAE,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAE,eAAe,EAAE,KAAK,EAAE,CAAC;YAC/D,CAAC;YACD,0EAA0E;YAC1E,yEAAyE;YACzE,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,eAAe,EAAE,IAAI,EAAE,CAAC;QACnD,CAAC;QACD,IAAI;YACF,KAAK,MAAM,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;QAC5C,CAAC;QACD,KAAK,CAAC,KAAK;YACT,4EAA4E;YAC5E,yEAAyE;YACzE,8DAA8D;YAC9D,MAAM,YAAY,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,oCAAoC,CAAC,CAAC;YACxE,MAAM,MAAM,CAAC,UAAU,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;QACnD,CAAC;KACF,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,uCAAuC,CACrD,OAA0B,EAC1B,OAAqC;IAErC,OAAO,CAAC,OAA0B,EAAE,EAAE,CACpC,+BAA+B,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;AAC/D,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=duplex-command-stream.live.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"duplex-command-stream.live.test.d.ts","sourceRoot":"","sources":["../src/duplex-command-stream.live.test.ts"],"names":[],"mappings":""}