@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
@@ -0,0 +1,321 @@
1
+ import { useState } from 'octane';
2
+ import { Button, Icon, Tag } from '@flowdular/sdk/ui';
3
+ import type {
4
+ ModuleSpecReview,
5
+ SpecChangeKind,
6
+ SpecFieldChange,
7
+ } from '../server/spec.ts';
8
+ import { useTranslation } from './i18n.ts';
9
+
10
+ export interface SpecReviewCardProps {
11
+ readonly review: ModuleSpecReview;
12
+ readonly busy: boolean;
13
+ readonly onApprove: () => void;
14
+ readonly onRequestChanges: (comment: string) => void;
15
+ readonly onEdit: () => void;
16
+ }
17
+
18
+ const FIELD_LABELS: Readonly<Record<string, string>> = {
19
+ id: 'id',
20
+ specVersion: 'version',
21
+ status: 'status',
22
+ name: 'name',
23
+ description: 'description',
24
+ profile: 'profile',
25
+ tenancy: 'tenancy',
26
+ capabilities: 'capability',
27
+ locales: 'locale',
28
+ dependencies: 'dependency',
29
+ invariants: 'invariant',
30
+ dataOwnership: 'dataOwnership',
31
+ permissions: 'permission',
32
+ acceptanceScenarios: 'scenario',
33
+ };
34
+
35
+ const IDENTIFIER_FIELDS = new Set([
36
+ 'id',
37
+ 'specVersion',
38
+ 'status',
39
+ 'profile',
40
+ 'tenancy',
41
+ 'capabilities',
42
+ 'locales',
43
+ 'dependencies',
44
+ 'permissions',
45
+ 'acceptanceScenarios',
46
+ ]);
47
+
48
+ function changeSign(kind: SpecChangeKind): string {
49
+ if (kind === 'added') return '+';
50
+ if (kind === 'removed') return '-';
51
+ return '~';
52
+ }
53
+
54
+ function changeKey(change: SpecFieldChange): string {
55
+ return `${change.field}:${change.kind}:${change.key ?? ''}`;
56
+ }
57
+
58
+ /* What the entry became, without repeating the identifier that names it. */
59
+ function changeValue(change: SpecFieldChange): string {
60
+ if (change.kind === 'changed') {
61
+ return `${change.before ?? ''} → ${change.after ?? ''}`;
62
+ }
63
+ const value = change.after ?? change.before ?? '';
64
+ return value === change.key ? '' : value;
65
+ }
66
+
67
+ /* What the operator approves: the specification as it stands, and for a change
68
+ the difference from the copy the session started with. */
69
+ export function SpecReviewCard(props: SpecReviewCardProps) @{
70
+ const { t } = useTranslation();
71
+ const review = props.review;
72
+ const draft = review.draft;
73
+ const changes = review.changes;
74
+ const isEdit = review.kind === 'edit';
75
+ const marks = new Map<string, SpecChangeKind>();
76
+ for (const change of changes) {
77
+ if (change.key) marks.set(change.field + ':' + change.key, change.kind);
78
+ }
79
+ const markOf = (field: string, key: string) => isEdit
80
+ ? marks.get(field + ':' + key) ?? null
81
+ : null;
82
+ const [asking, setAsking] = useState(false);
83
+ const [comment, setComment] = useState('');
84
+
85
+ <section class="spec-review">
86
+ <header class="spec-review__head">
87
+ <span class="ui-mono">{review.moduleId}</span>
88
+ <Tag mono tone={review.approved ? 'success' : 'warning'}>
89
+ {review.status === 'draft' || review.status === 'approved' ||
90
+ review.status === 'rejected'
91
+ ? t('sandbox.spec.status.' + review.status)
92
+ : review.status ?? t('sandbox.spec.status.none')}
93
+ </Tag>
94
+ @if (draft && draft.specVersion) {
95
+ <Tag mono>{'v' + draft.specVersion}</Tag>
96
+ }
97
+ <span class="sandbox__spacer"></span>
98
+ <span class="spec-review__path ui-mono">{review.path}</span>
99
+ </header>
100
+
101
+ @if (!draft) {
102
+ <p class="spec-review__empty">
103
+ {review.present
104
+ ? t('sandbox.spec.unreadable')
105
+ : t('sandbox.spec.missing')}
106
+ </p>
107
+ } @else {
108
+ <>
109
+ @if (isEdit) {
110
+ <div class="spec-review__block">
111
+ <h4 class="spec-review__title">
112
+ {changes.length === 0
113
+ ? t('sandbox.spec.changes.empty')
114
+ : t('sandbox.spec.changes.title')}
115
+ </h4>
116
+ @if (changes.length > 0) {
117
+ <ul class="spec-review__changes">
118
+ @for (const change of changes; key changeKey(change)) {
119
+ <li
120
+ class={'spec-review__change spec-review__change--' +
121
+ change.kind}
122
+ >
123
+ <span class="spec-review__sign">{changeSign(
124
+ change.kind,
125
+ )}</span>
126
+ <span class="spec-review__field">
127
+ {FIELD_LABELS[change.field]
128
+ ? t('sandbox.spec.field.' + FIELD_LABELS[change.field])
129
+ : change.field}
130
+ </span>
131
+ @if (change.key) {
132
+ <span
133
+ class={IDENTIFIER_FIELDS.has(change.field)
134
+ ? 'ui-mono'
135
+ : ''}
136
+ >{change.key}</span>
137
+ }
138
+ @if (changeValue(change)) {
139
+ <span class="spec-review__value">{changeValue(
140
+ change,
141
+ )}</span>
142
+ }
143
+ </li>
144
+ }
145
+ </ul>
146
+ }
147
+ </div>
148
+ }
149
+
150
+ <div class="spec-review__block">
151
+ <h4 class="spec-review__title">{draft.name || review.moduleId}</h4>
152
+ <p class="spec-review__text">{draft.description}</p>
153
+ <dl class="spec-review__facts">
154
+ <dt>{t('sandbox.spec.facts.capabilities')}</dt>
155
+ <dd class="ui-mono">
156
+ {draft.capabilities.join(', ') || t('sandbox.common.none')}
157
+ </dd>
158
+ <dt>{t('sandbox.spec.facts.tenancy')}</dt>
159
+ <dd class="ui-mono">
160
+ {draft.tenancy || t('sandbox.common.unset')}
161
+ </dd>
162
+ <dt>{t('sandbox.spec.facts.profile')}</dt>
163
+ <dd class="ui-mono">
164
+ {draft.profile || t('sandbox.common.unset')}
165
+ </dd>
166
+ </dl>
167
+ </div>
168
+
169
+ @if (draft.permissions.length > 0) {
170
+ <div class="spec-review__block">
171
+ <h4 class="spec-review__title">{t('sandbox.spec.permissions')}</h4>
172
+ <ul class="spec-review__list">
173
+ @for (const permission of draft.permissions; key permission.id) {
174
+ <li
175
+ class={[
176
+ 'spec-review__item',
177
+ markOf('permissions', permission.id) &&
178
+ 'spec-review__item--' +
179
+ markOf('permissions', permission.id),
180
+ ]}
181
+ >
182
+ <span class="ui-mono">{permission.id}</span>
183
+ <span>{permission.description}</span>
184
+ </li>
185
+ }
186
+ </ul>
187
+ </div>
188
+ }
189
+
190
+ @if (draft.invariants.length > 0) {
191
+ <div class="spec-review__block">
192
+ <h4 class="spec-review__title">{t('sandbox.spec.invariants')}</h4>
193
+ <ul class="spec-review__list">
194
+ @for (const invariant of draft.invariants; key invariant) {
195
+ <li
196
+ class={[
197
+ 'spec-review__item',
198
+ markOf('invariants', invariant) &&
199
+ 'spec-review__item--' + markOf('invariants', invariant),
200
+ ]}
201
+ >
202
+ <span>{invariant}</span>
203
+ </li>
204
+ }
205
+ </ul>
206
+ </div>
207
+ }
208
+
209
+ @if (draft.dataOwnership.length > 0) {
210
+ <div class="spec-review__block">
211
+ <h4 class="spec-review__title">{t(
212
+ 'sandbox.spec.dataOwnership',
213
+ )}</h4>
214
+ <ul class="spec-review__list">
215
+ @for (const sentence of draft.dataOwnership; key sentence) {
216
+ <li
217
+ class={[
218
+ 'spec-review__item',
219
+ markOf('dataOwnership', sentence) &&
220
+ 'spec-review__item--' + markOf('dataOwnership', sentence),
221
+ ]}
222
+ >
223
+ <span>{sentence}</span>
224
+ </li>
225
+ }
226
+ </ul>
227
+ </div>
228
+ }
229
+
230
+ @if (draft.acceptanceScenarios.length > 0) {
231
+ <div class="spec-review__block">
232
+ <h4 class="spec-review__title">{t(
233
+ 'sandbox.spec.acceptanceScenarios',
234
+ )}</h4>
235
+ <ul class="spec-review__list">
236
+ @for (const scenario of draft.acceptanceScenarios; key scenario.id) {
237
+ <li
238
+ class={[
239
+ 'spec-review__scenario',
240
+ markOf('acceptanceScenarios', scenario.id) &&
241
+ 'spec-review__item--' +
242
+ markOf('acceptanceScenarios', scenario.id),
243
+ ]}
244
+ >
245
+ <span class="ui-mono">{scenario.id}</span>
246
+ <span>
247
+ <b>{t('sandbox.spec.given')}</b>
248
+ {' ' + scenario.given}
249
+ </span>
250
+ <span>
251
+ <b>{t('sandbox.spec.when')}</b>
252
+ {' ' + scenario.when}
253
+ </span>
254
+ <span>
255
+ <b>{t('sandbox.spec.then')}</b>
256
+ {' ' + scenario.then}
257
+ </span>
258
+ </li>
259
+ }
260
+ </ul>
261
+ </div>
262
+ }
263
+ </>
264
+ }
265
+
266
+ @if (asking) {
267
+ <div class="spec-review__ask">
268
+ <textarea
269
+ class="ui-textarea"
270
+ rows={3}
271
+ placeholder={t('sandbox.spec.request.placeholder')}
272
+ value={comment}
273
+ onInput={(event) => setComment(event.currentTarget.value)}
274
+ ></textarea>
275
+ <div class="ui-form__actions">
276
+ <Button
277
+ size="sm"
278
+ variant="primary"
279
+ disabled={props.busy || comment.trim().length === 0}
280
+ onClick={() => {
281
+ props.onRequestChanges(comment.trim());
282
+ setComment('');
283
+ setAsking(false);
284
+ }}
285
+ >
286
+ <Icon name="play" size={14} />
287
+ {t('sandbox.spec.request.send')}
288
+ </Button>
289
+ <Button size="sm" variant="ghost" onClick={() => setAsking(false)}>{t(
290
+ 'sandbox.common.cancel',
291
+ )}</Button>
292
+ </div>
293
+ </div>
294
+ } @else {
295
+ <div class="ui-form__actions">
296
+ <Button
297
+ size="sm"
298
+ variant="primary"
299
+ disabled={props.busy || !draft}
300
+ onClick={props.onApprove}
301
+ >
302
+ <Icon name="check" size={14} />
303
+ {t('sandbox.spec.approve')}
304
+ </Button>
305
+ <Button
306
+ size="sm"
307
+ variant="secondary"
308
+ disabled={props.busy}
309
+ onClick={() => setAsking(true)}
310
+ >
311
+ <Icon name="help" size={14} />
312
+ {t('sandbox.spec.request.action')}
313
+ </Button>
314
+ <Button size="sm" variant="ghost" onClick={props.onEdit}>
315
+ <Icon name="code" size={14} />
316
+ {t('sandbox.spec.edit')}
317
+ </Button>
318
+ </div>
319
+ }
320
+ </section>
321
+ }
@@ -0,0 +1,128 @@
1
+ import { useEffect } from 'octane';
2
+ import { Button, Icon, Tag } from '@flowdular/sdk/ui';
3
+ import type { SandboxSession } from '../server/sessions.ts';
4
+ import { DiffPane, type ModuleDiff } from './DiffPane.tsrx';
5
+ import { useTranslation } from './i18n.ts';
6
+
7
+ export type WorkCardMode = 'preview' | 'code';
8
+
9
+ export interface WorkCardProps {
10
+ readonly session: SandboxSession;
11
+ readonly diffs: readonly ModuleDiff[];
12
+ readonly mode: WorkCardMode;
13
+ readonly nonce: number;
14
+ /* The module the card shows; empty means every module of the session. */
15
+ readonly activeModule: string;
16
+ readonly previewData: 'fixtures' | 'bridge';
17
+ readonly onMode: (mode: WorkCardMode) => void;
18
+ readonly onOpen: () => void;
19
+ readonly onReload: () => void;
20
+ readonly onAskAbout: (path: string) => void;
21
+ }
22
+
23
+ /* The card floats beside the conversation and carries both surfaces the work
24
+ produces: the running module and its diff. It is a viewport, so a click
25
+ opens the same content full screen where it becomes interactive. */
26
+ /* The preview renders at a real workspace width and is scaled to the card, so
27
+ the card shows the desktop layout rather than a narrow rendering. The factor
28
+ depends on the card width, which only the browser knows. */
29
+ const PREVIEW_WIDTH = 1440;
30
+
31
+ function fitPreview(): void {
32
+ const viewport = document.querySelector<HTMLElement>('.work-card__viewport');
33
+ const frame = viewport?.querySelector<HTMLElement>('.preview-frame');
34
+ if (!viewport || !frame) return;
35
+ const scale = viewport.clientWidth / PREVIEW_WIDTH;
36
+ if (scale <= 0) return;
37
+ frame.style.width = `${PREVIEW_WIDTH}px`;
38
+ frame.style.height = `${Math.round(viewport.clientHeight / scale)}px`;
39
+ frame.style.transform = `scale(${scale})`;
40
+ }
41
+
42
+ export function WorkCard(props: WorkCardProps) @{
43
+ const { t } = useTranslation();
44
+ const source =
45
+ '/preview/' + props.session.id + '?n=' + props.nonce +
46
+ (props.activeModule ? '&module=' + props.activeModule : '');
47
+ const shown =
48
+ props.activeModule
49
+ ? props.diffs.filter((diff) => diff.module === props.activeModule)
50
+ : props.diffs;
51
+
52
+ useEffect(() => {
53
+ fitPreview();
54
+ const observer = new ResizeObserver(() => fitPreview());
55
+ const viewport = document.querySelector('.work-card__viewport');
56
+ if (viewport) observer.observe(viewport);
57
+ return () => observer.disconnect();
58
+ }, [props.mode, props.nonce]);
59
+
60
+ <article class="work-card">
61
+ <header class="work-card__head">
62
+ <Button
63
+ size="sm"
64
+ variant={props.mode === 'preview' ? 'primary' : 'ghost'}
65
+ onClick={() => props.onMode('preview')}
66
+ >{t('sandbox.work.preview')}</Button>
67
+ <Button
68
+ size="sm"
69
+ variant={props.mode === 'code' ? 'primary' : 'ghost'}
70
+ onClick={() => props.onMode('code')}
71
+ >{t('sandbox.work.code', { count: shown.length })}</Button>
72
+ <span class="ui-mono">
73
+ {props.activeModule
74
+ ? 'modules/' + props.activeModule
75
+ : props.session.modules.length === 1
76
+ ? props.session.moduleId
77
+ : t('sandbox.session.modules', {
78
+ count: props.session.modules.length,
79
+ })}
80
+ </span>
81
+ <span class="sandbox__spacer"></span>
82
+ @if (props.mode === 'preview') {
83
+ <Tag tone={props.previewData === 'bridge' ? 'info' : 'neutral'}>
84
+ {props.previewData === 'bridge'
85
+ ? t('sandbox.work.liveData')
86
+ : t('sandbox.work.fixtures')}
87
+ </Tag>
88
+ }
89
+ <Button size="sm" variant="ghost" onClick={props.onReload}>
90
+ <Icon name="refresh" size={14} />
91
+ </Button>
92
+ <Button size="sm" variant="ghost" onClick={props.onOpen}>
93
+ <Icon name="external" size={14} />
94
+ </Button>
95
+ </header>
96
+
97
+ @if (props.mode === 'preview') {
98
+ <div class="work-card__stage">
99
+ <div class="work-card__viewport">
100
+ <iframe
101
+ class="preview-frame"
102
+ src={source}
103
+ title={t('sandbox.work.previewTitle')}
104
+ ></iframe>
105
+ </div>
106
+ <button
107
+ class="work-card__open"
108
+ type="button"
109
+ onClick={props.onOpen}
110
+ aria-label={t('sandbox.work.openFull')}
111
+ >
112
+ <span class="work-card__hint">
113
+ <Icon name="external" size={14} />
114
+ {t('sandbox.work.open')}
115
+ </span>
116
+ </button>
117
+ </div>
118
+ } @else {
119
+ <div class="work-card__stage work-card__stage--code">
120
+ <DiffPane
121
+ diffs={props.diffs}
122
+ activeModule={props.activeModule}
123
+ onAsk={props.onAskAbout}
124
+ />
125
+ </div>
126
+ }
127
+ </article>
128
+ }
@@ -0,0 +1,161 @@
1
+ import { useEffect } from 'octane';
2
+ import { Button, Icon } from '@flowdular/sdk/ui';
3
+ import type { SandboxSession } from '../server/sessions.ts';
4
+ import { SpecEditor } from './SpecEditor.tsrx';
5
+ import { DiffPane, type ModuleDiff } from './DiffPane.tsrx';
6
+ import { useTranslation } from './i18n.ts';
7
+
8
+ export type WorkbenchMode = 'preview' | 'diff' | 'spec';
9
+
10
+ export interface WorkbenchModalProps {
11
+ readonly mode: WorkbenchMode;
12
+ readonly session: SandboxSession;
13
+ readonly diffs: readonly ModuleDiff[];
14
+ readonly nonce: number;
15
+ readonly selecting: boolean;
16
+ /* The module the preview opens on and the diff is filtered to; empty means
17
+ every module of the session. */
18
+ readonly activeModule: string;
19
+ readonly previewData: 'fixtures' | 'bridge';
20
+ readonly onModule: (directory: string) => void;
21
+ readonly onMode: (mode: WorkbenchMode) => void;
22
+ readonly onToggleSelect: () => void;
23
+ readonly onReload: () => void;
24
+ readonly onPreviewData: (mode: 'fixtures' | 'bridge') => void;
25
+ readonly onAskAbout: (path: string) => void;
26
+ /* The specification on disk changed, so the session view is stale. */
27
+ readonly onSpecSaved: () => void;
28
+ readonly onClose: () => void;
29
+ }
30
+
31
+ /* Full screen is where the module is actually worked on: the preview is
32
+ interactive here, and the diff finally has the width it needs. */
33
+ export function WorkbenchModal(props: WorkbenchModalProps) @{
34
+ const { t } = useTranslation();
35
+ const source =
36
+ '/preview/' + props.session.id + '?n=' + props.nonce +
37
+ (props.selecting ? '&select=1' : '') +
38
+ (props.activeModule ? '&module=' + props.activeModule : '');
39
+ const shown =
40
+ props.activeModule
41
+ ? props.diffs.filter((diff) => diff.module === props.activeModule)
42
+ : props.diffs;
43
+ const specModule = props.activeModule || props.session.modules[0]!.directory;
44
+ const sessionId = props.session.id;
45
+
46
+ useEffect(() => {
47
+ const onKey = (event: KeyboardEvent) => {
48
+ if (event.key === 'Escape') props.onClose();
49
+ };
50
+ window.addEventListener('keydown', onKey);
51
+ return () => window.removeEventListener('keydown', onKey);
52
+ }, []);
53
+
54
+ <div class="workbench" role="dialog" aria-modal="true">
55
+ <div class="workbench__panel">
56
+ <header class="workbench__head">
57
+ <Button
58
+ size="sm"
59
+ variant={props.mode === 'preview' ? 'primary' : 'secondary'}
60
+ onClick={() => props.onMode('preview')}
61
+ >{t('sandbox.work.preview')}</Button>
62
+ <Button
63
+ size="sm"
64
+ variant={props.mode === 'diff' ? 'primary' : 'secondary'}
65
+ onClick={() => props.onMode('diff')}
66
+ >{t('sandbox.session.changes', { count: shown.length })}</Button>
67
+ <Button
68
+ size="sm"
69
+ variant={props.mode === 'spec' ? 'primary' : 'secondary'}
70
+ onClick={() => props.onMode('spec')}
71
+ >{t('sandbox.workbench.specification')}</Button>
72
+ <span class="ui-mono">
73
+ {props.session.modules.length === 1
74
+ ? props.session.moduleId
75
+ : t('sandbox.session.modules', {
76
+ count: props.session.modules.length,
77
+ })}
78
+ </span>
79
+ @if (props.session.modules.length > 1) {
80
+ <select
81
+ class="chat__picker"
82
+ aria-label={t('sandbox.workbench.module')}
83
+ value={props.mode === 'spec' ? specModule : props.activeModule}
84
+ onChange={(event) => props.onModule(event.currentTarget.value)}
85
+ >
86
+ @if (props.mode !== 'spec') {
87
+ <option value="">{t('sandbox.session.module.all')}</option>
88
+ }
89
+ @for (const module of props.session.modules; key module.id) {
90
+ <option value={module.directory}>{module.id}</option>
91
+ }
92
+ </select>
93
+ }
94
+ <span class="sandbox__spacer"></span>
95
+ @if (props.mode === 'preview') {
96
+ <>
97
+ <select
98
+ class="ui-select"
99
+ value={props.previewData}
100
+ onChange={(event) => props.onPreviewData(
101
+ event.currentTarget.value === 'bridge' ? 'bridge' : 'fixtures',
102
+ )}
103
+ >
104
+ <option value="fixtures">{t('sandbox.work.fixtures')}</option>
105
+ <option value="bridge">{t('sandbox.workbench.liveData')}</option>
106
+ </select>
107
+ <Button
108
+ size="sm"
109
+ variant={props.selecting ? 'primary' : 'secondary'}
110
+ onClick={props.onToggleSelect}
111
+ >
112
+ <Icon name="filter" size={14} />
113
+ {props.selecting
114
+ ? t('sandbox.workbench.selecting')
115
+ : t('sandbox.workbench.selectElement')}
116
+ </Button>
117
+ <Button size="sm" onClick={props.onReload}>
118
+ <Icon name="refresh" size={14} />
119
+ {t('sandbox.workbench.reload')}
120
+ </Button>
121
+ </>
122
+ }
123
+ <Button size="sm" variant="ghost" onClick={props.onClose}>
124
+ <Icon name="x" size={14} />
125
+ {t('sandbox.common.close')}
126
+ </Button>
127
+ </header>
128
+ @if (props.mode === 'preview') {
129
+ <div
130
+ class={[
131
+ 'workbench__body',
132
+ props.selecting && 'preview-frame__wrap--selecting',
133
+ ]}
134
+ >
135
+ <iframe
136
+ class="preview-frame"
137
+ src={source}
138
+ title={t('sandbox.work.previewTitle')}
139
+ ></iframe>
140
+ </div>
141
+ } @else if (props.mode === 'spec') {
142
+ <div class="workbench__body workbench__body--scroll">
143
+ <SpecEditor
144
+ key={sessionId + '/' + specModule}
145
+ sessionId={sessionId}
146
+ module={specModule}
147
+ onSaved={props.onSpecSaved}
148
+ />
149
+ </div>
150
+ } @else {
151
+ <div class="workbench__body workbench__body--scroll">
152
+ <DiffPane
153
+ diffs={props.diffs}
154
+ activeModule={props.activeModule}
155
+ onAsk={props.onAskAbout}
156
+ />
157
+ </div>
158
+ }
159
+ </div>
160
+ </div>
161
+ }