@flowdular/sandbox 0.2.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 (139) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +696 -0
  3. package/bin/flowdular-sandbox.mjs +394 -0
  4. package/bin/register-types.mjs +53 -0
  5. package/dist/client/assets/App-ClMOrpyg.js +11 -0
  6. package/dist/client/assets/PreviewHost-BHiHrfbQ.js +1 -0
  7. package/dist/client/assets/auto-buGEq6de.js +3 -0
  8. package/dist/client/assets/ibm-plex-mono-cyrillic-400-normal-BSMlKf0J.woff2 +0 -0
  9. package/dist/client/assets/ibm-plex-mono-cyrillic-400-normal-CEL4l2ZJ.woff +0 -0
  10. package/dist/client/assets/ibm-plex-mono-cyrillic-500-normal-Ael50iVv.woff +0 -0
  11. package/dist/client/assets/ibm-plex-mono-cyrillic-500-normal-Bq9vWWag.woff2 +0 -0
  12. package/dist/client/assets/ibm-plex-mono-cyrillic-ext-400-normal-DMdlQ8Kv.woff +0 -0
  13. package/dist/client/assets/ibm-plex-mono-cyrillic-ext-400-normal-xuaO2J-f.woff2 +0 -0
  14. package/dist/client/assets/ibm-plex-mono-cyrillic-ext-500-normal-BIfNGwUT.woff +0 -0
  15. package/dist/client/assets/ibm-plex-mono-cyrillic-ext-500-normal-BqneJy0T.woff2 +0 -0
  16. package/dist/client/assets/ibm-plex-mono-latin-400-normal-CvHOgSBP.woff +0 -0
  17. package/dist/client/assets/ibm-plex-mono-latin-400-normal-DMJ8VG8y.woff2 +0 -0
  18. package/dist/client/assets/ibm-plex-mono-latin-500-normal-CB9ihrfo.woff +0 -0
  19. package/dist/client/assets/ibm-plex-mono-latin-500-normal-DSY6xOcd.woff2 +0 -0
  20. package/dist/client/assets/ibm-plex-mono-latin-ext-400-normal-BmRBH3aV.woff2 +0 -0
  21. package/dist/client/assets/ibm-plex-mono-latin-ext-400-normal-D3D2R8hC.woff +0 -0
  22. package/dist/client/assets/ibm-plex-mono-latin-ext-500-normal-CAhNIIs5.woff2 +0 -0
  23. package/dist/client/assets/ibm-plex-mono-latin-ext-500-normal-CZ70TYgx.woff +0 -0
  24. package/dist/client/assets/ibm-plex-mono-vietnamese-400-normal-BulugwFq.woff2 +0 -0
  25. package/dist/client/assets/ibm-plex-mono-vietnamese-400-normal-DDuiU_S-.woff +0 -0
  26. package/dist/client/assets/ibm-plex-mono-vietnamese-500-normal-C8zxqsMH.woff +0 -0
  27. package/dist/client/assets/ibm-plex-mono-vietnamese-500-normal-DZ4AoWbu.woff2 +0 -0
  28. package/dist/client/assets/ibm-plex-sans-cyrillic-ext-wght-normal-d45eAU9y.woff2 +0 -0
  29. package/dist/client/assets/ibm-plex-sans-cyrillic-wght-normal-BAAhND-U.woff2 +0 -0
  30. package/dist/client/assets/ibm-plex-sans-greek-wght-normal-CmyJS8uq.woff2 +0 -0
  31. package/dist/client/assets/ibm-plex-sans-latin-ext-wght-normal-CIII54If.woff2 +0 -0
  32. package/dist/client/assets/ibm-plex-sans-latin-wght-normal-IvpUvPa2.woff2 +0 -0
  33. package/dist/client/assets/ibm-plex-sans-vietnamese-wght-normal-Dg1JeJN0.woff2 +0 -0
  34. package/dist/client/assets/index-CvwhlQ87.js +4 -0
  35. package/dist/client/assets/styles-BPWaGf55.js +3 -0
  36. package/dist/client/assets/styles-Dx1_KOag.css +1 -0
  37. package/dist/client/favicon.svg +1 -0
  38. package/dist/server/assets/auto-CVGNYyb3.js +12785 -0
  39. package/dist/server/assets/chunk-DDJLRBDX-3OUNo51g.js +4125 -0
  40. package/dist/server/assets/nodefs-DVSI7kG0.js +24 -0
  41. package/dist/server/assets/opfs-ahp-D56iokt1.js +388 -0
  42. package/dist/server/assets/token-Bvaq7Anz.js +55 -0
  43. package/dist/server/assets/token-util-BqSvdIPQ.js +3 -0
  44. package/dist/server/assets/token-util-CktFFT4z.js +494 -0
  45. package/dist/server/entry.js +91671 -0
  46. package/dist/server/favicon.svg +1 -0
  47. package/dist/server/index.html +161 -0
  48. package/index.html +159 -0
  49. package/internal/coding-agent/package.json +44 -0
  50. package/internal/coding-agent/src/drivers/byok.ts +322 -0
  51. package/internal/coding-agent/src/drivers/claude-code.ts +290 -0
  52. package/internal/coding-agent/src/drivers/codex.ts +281 -0
  53. package/internal/coding-agent/src/index.ts +56 -0
  54. package/internal/coding-agent/src/registry.ts +119 -0
  55. package/internal/coding-agent/src/roles/contract.ts +60 -0
  56. package/internal/coding-agent/src/roles/defaults.ts +134 -0
  57. package/internal/coding-agent/src/roles/handoff.ts +41 -0
  58. package/internal/coding-agent/src/roles/registry.ts +156 -0
  59. package/internal/coding-agent/src/roles/skills.ts +72 -0
  60. package/internal/coding-agent/src/roles/sync.ts +88 -0
  61. package/internal/coding-agent/src/types.ts +102 -0
  62. package/internal/coding-agent/src/workspace.ts +275 -0
  63. package/octane.config.ts +36 -0
  64. package/package.json +68 -0
  65. package/public/favicon.svg +1 -0
  66. package/public/og.png +0 -0
  67. package/src/App.tsrx +924 -0
  68. package/src/client/ApprovalHandoff.tsrx +39 -0
  69. package/src/client/ChatPane.tsrx +694 -0
  70. package/src/client/ConnectView.tsrx +86 -0
  71. package/src/client/DiffPane.tsrx +150 -0
  72. package/src/client/EjectModal.tsrx +571 -0
  73. package/src/client/GateResults.tsrx +60 -0
  74. package/src/client/GitHubSettingsModal.tsrx +219 -0
  75. package/src/client/NewSessionForm.tsrx +214 -0
  76. package/src/client/SessionBar.tsrx +151 -0
  77. package/src/client/SessionPicker.tsrx +472 -0
  78. package/src/client/SpecEditor.tsrx +109 -0
  79. package/src/client/SpecReviewCard.tsrx +321 -0
  80. package/src/client/WorkCard.tsrx +128 -0
  81. package/src/client/WorkbenchModal.tsrx +161 -0
  82. package/src/client/WorkspaceMenu.tsrx +100 -0
  83. package/src/client/api.ts +797 -0
  84. package/src/client/attachments.ts +73 -0
  85. package/src/client/dashboard.ts +46 -0
  86. package/src/client/github-settings.ts +48 -0
  87. package/src/client/highlight.ts +105 -0
  88. package/src/client/i18n.ts +32 -0
  89. package/src/client/locales/en.json +466 -0
  90. package/src/client/locales/pl.json +466 -0
  91. package/src/client/session-labels.ts +77 -0
  92. package/src/client/state.ts +108 -0
  93. package/src/index.ts +10 -0
  94. package/src/preview/PreviewHost.tsrx +373 -0
  95. package/src/preview/load-module.ts +16 -0
  96. package/src/server/attachments.ts +308 -0
  97. package/src/server/auto-review.ts +181 -0
  98. package/src/server/checkpoints.ts +90 -0
  99. package/src/server/config.ts +460 -0
  100. package/src/server/dashboard.ts +245 -0
  101. package/src/server/delivery/configuration.ts +193 -0
  102. package/src/server/delivery/git-pr.ts +1473 -0
  103. package/src/server/delivery/index.ts +83 -0
  104. package/src/server/delivery/local.ts +151 -0
  105. package/src/server/delivery/official-modules.ts +516 -0
  106. package/src/server/delivery/plan.ts +218 -0
  107. package/src/server/delivery/policies.ts +239 -0
  108. package/src/server/delivery/record.ts +41 -0
  109. package/src/server/delivery/steps.ts +464 -0
  110. package/src/server/delivery/types.ts +158 -0
  111. package/src/server/dependencies.ts +88 -0
  112. package/src/server/diff.ts +230 -0
  113. package/src/server/gates.ts +388 -0
  114. package/src/server/index.ts +139 -0
  115. package/src/server/path-guard.ts +282 -0
  116. package/src/server/planning.ts +749 -0
  117. package/src/server/platform-client.ts +189 -0
  118. package/src/server/preview-database-host.ts +340 -0
  119. package/src/server/preview-database-protocol.ts +163 -0
  120. package/src/server/preview-database-proxy.ts +356 -0
  121. package/src/server/preview-database.ts +109 -0
  122. package/src/server/preview-ipc.ts +15 -0
  123. package/src/server/preview-modules.ts +83 -0
  124. package/src/server/preview-revision.ts +44 -0
  125. package/src/server/preview-runtime.ts +467 -0
  126. package/src/server/preview-worker-manager.ts +477 -0
  127. package/src/server/preview-worker.ts +168 -0
  128. package/src/server/reference.ts +251 -0
  129. package/src/server/routes.ts +2258 -0
  130. package/src/server/runtime.ts +188 -0
  131. package/src/server/session-owner.ts +23 -0
  132. package/src/server/sessions.ts +849 -0
  133. package/src/server/spec.ts +471 -0
  134. package/src/server/turn-lifecycle.ts +56 -0
  135. package/src/server/turns.ts +993 -0
  136. package/src/server/workspace-install.ts +266 -0
  137. package/src/server/workspace-root.ts +73 -0
  138. package/src/styles.css +1573 -0
  139. package/vite.config.ts +134 -0
package/vite.config.ts ADDED
@@ -0,0 +1,134 @@
1
+ import { flowdularEnvironment } from '@flowdular/sdk/kernel/runtime-config';
2
+ import { existsSync, readFileSync } from 'node:fs';
3
+ import { dirname, join, resolve } from 'node:path';
4
+ import { fileURLToPath } from 'node:url';
5
+ import { octane } from '@octanejs/vite-plugin';
6
+ import type { Plugin } from 'vite';
7
+ import { defineConfig } from 'vite';
8
+ import { sandboxDirectory } from './src/server/config.ts';
9
+ import { findFlowdularWorkspace } from './src/server/workspace-root.ts';
10
+ import { resolvePreviewModules } from './src/server/preview-modules.ts';
11
+ import type { SandboxSession } from './src/server/sessions.ts';
12
+
13
+ Object.assign(process.env, flowdularEnvironment(process.env));
14
+
15
+ const appRoot = dirname(fileURLToPath(import.meta.url));
16
+ const workspace = await findFlowdularWorkspace(
17
+ process.env.FD_SANDBOX_WORKSPACE ?? process.cwd(),
18
+ );
19
+
20
+ const PREVIEW_MODULE =
21
+ /^\/preview-module\/([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})\/([a-z][a-z0-9-]*)\/(.+)$/;
22
+
23
+ /* The preview imports draft sources by session and module directory. This
24
+ plugin maps that URL onto the session workspace, so the browser never learns
25
+ where the workspace lives on disk and cannot ask for anything outside a
26
+ session's module directory. */
27
+ function previewModules(workspaceRoot: string): Plugin {
28
+ return {
29
+ name: 'flowdular-preview-modules',
30
+ enforce: 'pre',
31
+ async resolveId(source) {
32
+ const support =
33
+ /^\/preview-support\/([0-9a-f-]{36})\/([a-z][a-z0-9-]*)\/(.+)$/.exec(
34
+ source,
35
+ );
36
+ if (support) {
37
+ const [, sessionId, directory, rest] = support;
38
+ if (rest!.split('/').some((part) => part === '..' || !part))
39
+ return null;
40
+ try {
41
+ const session = JSON.parse(
42
+ readFileSync(
43
+ join(
44
+ sandboxDirectory(workspaceRoot),
45
+ 'sessions',
46
+ sessionId!,
47
+ 'session.json',
48
+ ),
49
+ 'utf8',
50
+ ),
51
+ ) as SandboxSession;
52
+ const selected = (
53
+ await resolvePreviewModules(workspaceRoot, session)
54
+ ).find((module) => module.support && module.directory === directory);
55
+ if (!selected) return null;
56
+ const file = join(selected.path, rest!);
57
+ return existsSync(file) ? file : null;
58
+ } catch {
59
+ return null;
60
+ }
61
+ }
62
+ const match = PREVIEW_MODULE.exec(source);
63
+ if (!match) return null;
64
+ const [, sessionId, directory, rest] = match;
65
+ if (rest!.split('/').some((segment) => segment === '..' || !segment)) {
66
+ return null;
67
+ }
68
+ const sessionRoot = join(
69
+ sandboxDirectory(workspaceRoot),
70
+ 'sessions',
71
+ sessionId!,
72
+ );
73
+ let modules: readonly { readonly directory: string }[] = [];
74
+ try {
75
+ const record = JSON.parse(
76
+ readFileSync(join(sessionRoot, 'session.json'), 'utf8'),
77
+ ) as {
78
+ modules?: readonly { readonly directory: string }[];
79
+ moduleSuffix?: string;
80
+ };
81
+ modules =
82
+ record.modules ??
83
+ (record.moduleSuffix ? [{ directory: record.moduleSuffix }] : []);
84
+ } catch {
85
+ return null;
86
+ }
87
+ if (!modules.some((module) => module.directory === directory)) {
88
+ return null;
89
+ }
90
+ const file = join(sessionRoot, 'workspace', 'modules', directory!, rest!);
91
+ return existsSync(file) ? file : null;
92
+ },
93
+ };
94
+ }
95
+
96
+ const config = {
97
+ root: appRoot,
98
+ plugins: [previewModules(workspace.root), octane()],
99
+ resolve: {
100
+ /* Draft module code is loaded from a session workspace outside this app.
101
+ It resolves the workspace packages through the node_modules link the
102
+ session gets, and these must stay single instances or the preview would
103
+ run on a second runtime. */
104
+ dedupe: [
105
+ 'octane',
106
+ 'segment-state',
107
+ '@flowdular/sdk',
108
+ '@flowdular/sdk/client',
109
+ '@flowdular/sdk/ui',
110
+ '@flowdular/sdk/server',
111
+ '@flowdular/sdk/contracts',
112
+ ],
113
+ extensions: ['.tsrx', '.ts', '.tsx', '.mjs', '.js', '.jsx', '.json'],
114
+ },
115
+ build: { target: 'esnext' },
116
+ /* Suites here boot the embedded PostgreSQL, which costs well past the 5s
117
+ vitest default under a full workspace run. Vitest reads this file, so the
118
+ timeouts live here rather than in a vitest.config.ts that would shadow it
119
+ and take the preview plugins with it. */
120
+ test: { testTimeout: 30_000, hookTimeout: 30_000 },
121
+ server: {
122
+ host: '127.0.0.1',
123
+ port: 4320,
124
+ strictPort: true,
125
+ /* Draft module files change on every agent turn and are served from
126
+ outside this app's root. The preview reloads itself instead, and a Vite
127
+ overlay must never cover a module someone is reviewing. */
128
+ hmr: { overlay: false },
129
+ fs: { allow: [appRoot, workspace.root] },
130
+ watch: { ignored: ['**/.flowdular/data/**', '**/.coreloom/data/**'] },
131
+ },
132
+ } satisfies import('vitest/config').UserWorkspaceConfig;
133
+
134
+ export default defineConfig(config);