@wavexzore/sandbox 0.1.0

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 (149) hide show
  1. package/Dockerfile +14 -0
  2. package/LICENSE +661 -0
  3. package/NOTICE +3 -0
  4. package/README.md +153 -0
  5. package/dist/index.d.ts +9 -0
  6. package/dist/index.js +9 -0
  7. package/dist/sandbox/cli/install.d.ts +5 -0
  8. package/dist/sandbox/cli/install.js +335 -0
  9. package/dist/sandbox/cli/local-store.d.ts +87 -0
  10. package/dist/sandbox/cli/local-store.js +604 -0
  11. package/dist/sandbox/cli/opencode-config.d.ts +25 -0
  12. package/dist/sandbox/cli/opencode-config.js +240 -0
  13. package/dist/sandbox/cli/path.d.ts +64 -0
  14. package/dist/sandbox/cli/path.js +127 -0
  15. package/dist/sandbox/cli/types.d.ts +145 -0
  16. package/dist/sandbox/cli/types.js +6 -0
  17. package/dist/sandbox/cli/wavexzore-sandbox.d.ts +65 -0
  18. package/dist/sandbox/cli/wavexzore-sandbox.js +577 -0
  19. package/dist/sandbox/core/cli-helper.d.ts +19 -0
  20. package/dist/sandbox/core/cli-helper.js +64 -0
  21. package/dist/sandbox/core/docker-archive-utils.d.ts +3 -0
  22. package/dist/sandbox/core/docker-archive-utils.js +50 -0
  23. package/dist/sandbox/core/docker-sandbox.d.ts +51 -0
  24. package/dist/sandbox/core/docker-sandbox.js +675 -0
  25. package/dist/sandbox/core/edit/filediff.d.ts +16 -0
  26. package/dist/sandbox/core/edit/filediff.js +21 -0
  27. package/dist/sandbox/core/edit/index.d.ts +5 -0
  28. package/dist/sandbox/core/edit/index.js +5 -0
  29. package/dist/sandbox/core/edit/line-endings.d.ts +4 -0
  30. package/dist/sandbox/core/edit/line-endings.js +10 -0
  31. package/dist/sandbox/core/edit/lock.d.ts +1 -0
  32. package/dist/sandbox/core/edit/lock.js +18 -0
  33. package/dist/sandbox/core/edit/replace.d.ts +10 -0
  34. package/dist/sandbox/core/edit/replace.js +14 -0
  35. package/dist/sandbox/core/edit/replacers.d.ts +15 -0
  36. package/dist/sandbox/core/edit/replacers.js +241 -0
  37. package/dist/sandbox/core/logger.d.ts +15 -0
  38. package/dist/sandbox/core/logger.js +59 -0
  39. package/dist/sandbox/core/lsp/client.d.ts +63 -0
  40. package/dist/sandbox/core/lsp/client.js +533 -0
  41. package/dist/sandbox/core/lsp/config.d.ts +13 -0
  42. package/dist/sandbox/core/lsp/config.js +36 -0
  43. package/dist/sandbox/core/lsp/diagnostics.d.ts +12 -0
  44. package/dist/sandbox/core/lsp/diagnostics.js +65 -0
  45. package/dist/sandbox/core/lsp/index.d.ts +4 -0
  46. package/dist/sandbox/core/lsp/index.js +4 -0
  47. package/dist/sandbox/core/lsp/language.d.ts +24 -0
  48. package/dist/sandbox/core/lsp/language.js +249 -0
  49. package/dist/sandbox/core/lsp/manager.d.ts +77 -0
  50. package/dist/sandbox/core/lsp/manager.js +237 -0
  51. package/dist/sandbox/core/lsp/tooling.d.ts +14 -0
  52. package/dist/sandbox/core/lsp/tooling.js +78 -0
  53. package/dist/sandbox/core/patch-parser.d.ts +23 -0
  54. package/dist/sandbox/core/patch-parser.js +248 -0
  55. package/dist/sandbox/core/path-map.d.ts +9 -0
  56. package/dist/sandbox/core/path-map.js +73 -0
  57. package/dist/sandbox/core/project-data-storage.d.ts +42 -0
  58. package/dist/sandbox/core/project-data-storage.js +167 -0
  59. package/dist/sandbox/core/read/binary.d.ts +4 -0
  60. package/dist/sandbox/core/read/binary.js +80 -0
  61. package/dist/sandbox/core/read/format.d.ts +38 -0
  62. package/dist/sandbox/core/read/format.js +85 -0
  63. package/dist/sandbox/core/read/index.d.ts +3 -0
  64. package/dist/sandbox/core/read/index.js +3 -0
  65. package/dist/sandbox/core/read/permissions.d.ts +7 -0
  66. package/dist/sandbox/core/read/permissions.js +13 -0
  67. package/dist/sandbox/core/session-manager.d.ts +29 -0
  68. package/dist/sandbox/core/session-manager.js +338 -0
  69. package/dist/sandbox/core/shell/config.d.ts +7 -0
  70. package/dist/sandbox/core/shell/config.js +82 -0
  71. package/dist/sandbox/core/shell/output.d.ts +35 -0
  72. package/dist/sandbox/core/shell/output.js +80 -0
  73. package/dist/sandbox/core/shell/parser.d.ts +7 -0
  74. package/dist/sandbox/core/shell/parser.js +122 -0
  75. package/dist/sandbox/core/shell/permissions.d.ts +13 -0
  76. package/dist/sandbox/core/shell/permissions.js +33 -0
  77. package/dist/sandbox/core/shell/workdir.d.ts +4 -0
  78. package/dist/sandbox/core/shell/workdir.js +19 -0
  79. package/dist/sandbox/core/stream-utils.d.ts +23 -0
  80. package/dist/sandbox/core/stream-utils.js +97 -0
  81. package/dist/sandbox/core/toast.d.ts +47 -0
  82. package/dist/sandbox/core/toast.js +73 -0
  83. package/dist/sandbox/core/types.d.ts +159 -0
  84. package/dist/sandbox/core/types.js +11 -0
  85. package/dist/sandbox/core/write/bom.d.ts +8 -0
  86. package/dist/sandbox/core/write/bom.js +15 -0
  87. package/dist/sandbox/core/write/config.d.ts +14 -0
  88. package/dist/sandbox/core/write/config.js +188 -0
  89. package/dist/sandbox/core/write/diagnostics.d.ts +19 -0
  90. package/dist/sandbox/core/write/diagnostics.js +120 -0
  91. package/dist/sandbox/core/write/diff.d.ts +7 -0
  92. package/dist/sandbox/core/write/diff.js +21 -0
  93. package/dist/sandbox/core/write/formatter.d.ts +16 -0
  94. package/dist/sandbox/core/write/formatter.js +51 -0
  95. package/dist/sandbox/core/write/index.d.ts +6 -0
  96. package/dist/sandbox/core/write/index.js +5 -0
  97. package/dist/sandbox/core/write/permissions.d.ts +13 -0
  98. package/dist/sandbox/core/write/permissions.js +19 -0
  99. package/dist/sandbox/core/write/pipeline.d.ts +48 -0
  100. package/dist/sandbox/core/write/pipeline.js +229 -0
  101. package/dist/sandbox/core/write/read-tracker.d.ts +13 -0
  102. package/dist/sandbox/core/write/read-tracker.js +30 -0
  103. package/dist/sandbox/git/host-git-manager.d.ts +40 -0
  104. package/dist/sandbox/git/host-git-manager.js +278 -0
  105. package/dist/sandbox/git/index.d.ts +5 -0
  106. package/dist/sandbox/git/index.js +5 -0
  107. package/dist/sandbox/git/sandbox-git-manager.d.ts +14 -0
  108. package/dist/sandbox/git/sandbox-git-manager.js +54 -0
  109. package/dist/sandbox/git/session-git-manager.d.ts +18 -0
  110. package/dist/sandbox/git/session-git-manager.js +85 -0
  111. package/dist/sandbox/index.d.ts +205 -0
  112. package/dist/sandbox/index.js +70 -0
  113. package/dist/sandbox/plugins/custom-tools.d.ts +203 -0
  114. package/dist/sandbox/plugins/custom-tools.js +15 -0
  115. package/dist/sandbox/plugins/session-events.d.ts +10 -0
  116. package/dist/sandbox/plugins/session-events.js +56 -0
  117. package/dist/sandbox/plugins/system-transform.d.ts +10 -0
  118. package/dist/sandbox/plugins/system-transform.js +23 -0
  119. package/dist/sandbox/tools/bash-output.d.ts +17 -0
  120. package/dist/sandbox/tools/bash-output.js +35 -0
  121. package/dist/sandbox/tools/bash-status.d.ts +13 -0
  122. package/dist/sandbox/tools/bash-status.js +29 -0
  123. package/dist/sandbox/tools/bash-stop.d.ts +13 -0
  124. package/dist/sandbox/tools/bash-stop.js +28 -0
  125. package/dist/sandbox/tools/bash.d.ts +26 -0
  126. package/dist/sandbox/tools/bash.js +120 -0
  127. package/dist/sandbox/tools/edit.d.ts +20 -0
  128. package/dist/sandbox/tools/edit.js +87 -0
  129. package/dist/sandbox/tools/get-preview-url.d.ts +17 -0
  130. package/dist/sandbox/tools/get-preview-url.js +16 -0
  131. package/dist/sandbox/tools/glob.d.ts +17 -0
  132. package/dist/sandbox/tools/glob.js +23 -0
  133. package/dist/sandbox/tools/grep.d.ts +17 -0
  134. package/dist/sandbox/tools/grep.js +23 -0
  135. package/dist/sandbox/tools/ls.d.ts +17 -0
  136. package/dist/sandbox/tools/ls.js +21 -0
  137. package/dist/sandbox/tools/lsp.d.ts +41 -0
  138. package/dist/sandbox/tools/lsp.js +198 -0
  139. package/dist/sandbox/tools/multiedit.d.ts +24 -0
  140. package/dist/sandbox/tools/multiedit.js +83 -0
  141. package/dist/sandbox/tools/patch.d.ts +14 -0
  142. package/dist/sandbox/tools/patch.js +260 -0
  143. package/dist/sandbox/tools/read.d.ts +22 -0
  144. package/dist/sandbox/tools/read.js +105 -0
  145. package/dist/sandbox/tools/write.d.ts +16 -0
  146. package/dist/sandbox/tools/write.js +27 -0
  147. package/dist/sandbox/tools.d.ts +200 -0
  148. package/dist/sandbox/tools.js +43 -0
  149. package/package.json +55 -0
@@ -0,0 +1,50 @@
1
+ import tar from 'tar-stream';
2
+ export async function getFileFromContainer(container, filePath) {
3
+ let archiveStream;
4
+ try {
5
+ archiveStream = await container.getArchive({ path: filePath });
6
+ }
7
+ catch (err) {
8
+ if (err?.statusCode === 404 || err?.reason?.includes?.('No such container')) {
9
+ throw new Error(`File not found in container: ${filePath}`);
10
+ }
11
+ throw new Error(`Failed to read file from container: ${filePath} — ${err?.message || err}`);
12
+ }
13
+ const chunks = [];
14
+ return new Promise((resolve, reject) => {
15
+ const extract = tar.extract();
16
+ extract.on('entry', (_header, stream, next) => {
17
+ stream.on('data', (chunk) => chunks.push(chunk));
18
+ stream.on('end', next);
19
+ stream.resume();
20
+ });
21
+ extract.on('finish', () => resolve(Buffer.concat(chunks)));
22
+ extract.on('error', reject);
23
+ archiveStream.on('error', (err) => {
24
+ reject(new Error(`Failed to read file from container: ${filePath} — ${err.message}`));
25
+ });
26
+ archiveStream.pipe(extract);
27
+ });
28
+ }
29
+ function archivePath(filePath) {
30
+ return filePath.replace(/^\/+/, '');
31
+ }
32
+ function parentDirectories(filePath) {
33
+ const parts = archivePath(filePath).split('/').slice(0, -1);
34
+ const dirs = [];
35
+ for (let i = 1; i <= parts.length; i++) {
36
+ dirs.push(parts.slice(0, i).join('/'));
37
+ }
38
+ return dirs;
39
+ }
40
+ export async function putFileToContainer(container, filePath, content) {
41
+ const pack = tar.pack();
42
+ for (const dir of parentDirectories(filePath)) {
43
+ pack.entry({ name: dir, type: 'directory', mode: 0o755 }, Buffer.alloc(0));
44
+ }
45
+ pack.entry({ name: archivePath(filePath) }, content);
46
+ pack.finalize();
47
+ // Delegate placement to Docker Engine archive extraction instead of doing
48
+ // host-side temp-file rename/copy operations across bind mounts.
49
+ await container.putArchive(pack, { path: '/', noOverwriteDirNonDir: '1' });
50
+ }
@@ -0,0 +1,51 @@
1
+ import Dockerode from 'dockerode';
2
+ import type { Sandbox, SandboxBackgroundCommandOptions, SandboxBackgroundOutput, SandboxBackgroundStartResult, SandboxBackgroundStatus, SandboxCommandOptions, SandboxProcessResult, SandboxSessionResult, SandboxFileInfo, SandboxFileSearchResult, SandboxMatch, SandboxPreviewLink } from './types.js';
3
+ export declare class DockerSandbox implements Sandbox {
4
+ private docker;
5
+ private container;
6
+ private _state;
7
+ private _workDir;
8
+ private _id;
9
+ private backgroundCommands;
10
+ constructor(docker: Dockerode, container: Dockerode.Container, workDir: string);
11
+ get id(): string;
12
+ get state(): string;
13
+ refreshData(): Promise<void>;
14
+ start(): Promise<void>;
15
+ delete(): Promise<void>;
16
+ deleteSync(): void;
17
+ get process(): {
18
+ executeCommand: (command: string, cwd?: string | SandboxCommandOptions) => Promise<SandboxProcessResult>;
19
+ startBackgroundCommand: (command: string, opts?: SandboxBackgroundCommandOptions) => Promise<SandboxBackgroundStartResult>;
20
+ getBackgroundCommand: (cmdId: string) => Promise<SandboxBackgroundStatus>;
21
+ readBackgroundCommand: (cmdId: string, opts?: {
22
+ maxOutputBytes?: number;
23
+ maxOutputLines?: number;
24
+ }) => Promise<SandboxBackgroundOutput>;
25
+ stopBackgroundCommand: (cmdId: string) => Promise<SandboxBackgroundStatus>;
26
+ createSession: (sessionId: string) => Promise<void>;
27
+ getSession: (sessionId: string) => Promise<void>;
28
+ executeSessionCommand: (sessionId: any, opts: any) => Promise<SandboxSessionResult>;
29
+ };
30
+ get fs(): {
31
+ downloadFile: (filePath: string) => Promise<Buffer>;
32
+ uploadFile: (content: Buffer, filePath: string) => Promise<void>;
33
+ createFolder: (path: string, mode?: string) => Promise<void>;
34
+ listFiles: (dirPath: string) => Promise<SandboxFileInfo[]>;
35
+ searchFiles: (path: string, pattern: string) => Promise<SandboxFileSearchResult>;
36
+ findFiles: (path: string, pattern: string) => Promise<SandboxMatch[]>;
37
+ };
38
+ getWorkDir(): Promise<string>;
39
+ getPreviewLink(port: number): Promise<SandboxPreviewLink>;
40
+ private executeManagedCommand;
41
+ private startManagedShellCommand;
42
+ private runnerScript;
43
+ private writeContainerTextFile;
44
+ private getManagedCommandStatus;
45
+ private readManagedCommandOutput;
46
+ private stopManagedCommand;
47
+ private containerFileSize;
48
+ private containerFileLineCount;
49
+ private readContainerTextTail;
50
+ private persistFullOutput;
51
+ }