Skip to content

The open-source agent harness - the runtime layer that turns an LLM into a working agent.

fix: remove YAML editor support from environment form (#975)

harshil-2096d40c38083a97
diff --git a/.changeset/remove-environment-yaml-editor.md b/.changeset/remove-environment-yaml-editor.md
new file mode 100644
index 000000000..3d2b2c4a7
--- /dev/null
+++ b/.changeset/remove-environment-yaml-editor.md
@@ -0,0 +1,5 @@
+---
+'@truefoundry/trueforge-ui': patch
+---
+
+Remove YAML create/edit from the environment form drawer so environments are configured only through the UI form.
diff --git a/packages/trueforge-ui/package.json b/packages/trueforge-ui/package.json
index 571a27cad..dab1a8dc9 100644
--- a/packages/trueforge-ui/package.json
+++ b/packages/trueforge-ui/package.json
@@ -112,7 +112,6 @@
"remark-gfm": "^4.0.1",
"tailwind-merge": "^3.6.0",
"thinking-orbs": "^0.3.1",
- "yaml": "^2.9.0",
"zod": "^4.4.3"
},
"devDependencies": {
diff --git a/packages/trueforge-ui/src/atoms/draft/DraftCompositeSelector.tsx b/packages/trueforge-ui/src/atoms/draft/DraftCompositeSelector.tsx
index 19d39a61f..7f9fa3854 100644
--- a/packages/trueforge-ui/src/atoms/draft/DraftCompositeSelector.tsx
+++ b/packages/trueforge-ui/src/atoms/draft/DraftCompositeSelector.tsx
@@ -17,7 +17,6 @@ import { useReadySandboxEnvironments } from '../environments/useReadySandboxEnvi
import { auiButtonClass } from '../lib/buttonClasses.js';
import { cn } from '../lib/cn.js';
import { useCompactLayout } from '../lib/CompactLayoutContext.js';
-import { formatRelativeTime } from '../lib/dateFormat.js';
import { auiInputClass } from '../lib/inputClasses.js';
import { useIsMobile } from '../lib/useIsMobile.js';
import { BottomSheet } from '../primitives/BottomSheet.js';
@@ -526,7 +525,7 @@ export function DraftCompositeSelector({ disabled, isRunning, onAttach }: DraftC
const filteredEnvironments = useMemo(() => {
const all = readyEnvironments.map(e => ({
name: e.name,
- description: e.manifest.description || `Created ${formatRelativeTime(e.createdAt)}`,
+ description: e.manifest.description,
}));
const needle = query.trim().toLowerCase();
if (!needle) return all;
diff --git a/packages/trueforge-ui/src/atoms/environments/EnvironmentFormDrawer.tsx b/packages/trueforge-ui/src/atoms/environments/EnvironmentFormDrawer.tsx
index faefab64b..5711e0c01 100644
--- a/packages/trueforge-ui/src/atoms/environments/EnvironmentFormDrawer.tsx
+++ b/packages/trueforge-ui/src/atoms/environments/EnvironmentFormDrawer.tsx
@@ -1,17 +1,14 @@
'use client';
-import { useEffect, useMemo, useState, type FormEvent } from 'react';
+import { useEffect, useState, type FormEvent } from 'react';
import { useTrackAnalytics } from '../../analytics/AnalyticsProvider.js';
import { AnalyticsEvents } from '../../analytics/events.js';
import { useToasterOptional } from '../../containers/ToasterContainer.js';
import { useSandboxEnvironmentServer } from '../../server/ServerContext.js';
-import type { SandboxEnvironment, SandboxEnvironmentManifest } from '../../server/types.js';
+import type { SandboxEnvironment } from '../../server/types.js';
import { getErrorMessage } from '../../utils/getErrorMessage.js';
-import { CodeEditor } from '../CodeEditor.js';
-import { cn } from '../lib/cn.js';
import { Button } from '../primitives/Button.js';
-import { Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle } from '../primitives/Dialog.js';
import { SideDrawer } from '../primitives/SideDrawer.js';
import { defaultEnvironmentManifest } from './environmentDisplay.js';
import {
@@ -21,7 +18,6 @@ import {
validateEnvironmentForm,
type EnvironmentFormValues,
} from './EnvironmentFormFields.js';
-import { manifestToYaml, parseManifestYaml } from './environmentYaml.js';
export type EnvironmentFormDrawerProps = {
open: boolean;
@@ -31,101 +27,37 @@ export type EnvironmentFormDrawerProps = {
onSaved?: () => void;
};
-type EditorMode = 'form' | 'yaml';
-
export function EnvironmentFormDrawer({ open, onOpenChange, mode, environment, onSaved }: EnvironmentFormDrawerProps) {
const environmentServer = useSandboxEnvironmentServer();
const toaster = useToasterOptional();
const track = useTrackAnalytics();
- const [editorMode, setEditorMode] = useState<EditorMode>('form');
const [form, setForm] = useState<EnvironmentFormValues>(() => manifestToFormValues(defaultEnvironmentManifest()));
- const [yamlText, setYamlText] = useState(() => manifestToYaml(defaultEnvironmentManifest()));
- const [baselineForm, setBaselineForm] = useState(form);
- const [baselineYaml, setBaselineYaml] = useState(yamlText);
- const [pendingSwitch, setPendingSwitch] = useState<EditorMode | null>(null);
const [saving, setSaving] = useState(false);
const [error, setError] = useState<string | null>(null);
useEffect(() => {
if (!open) {
- setEditorMode('form');
setError(null);
- setPendingSwitch(null);
setSaving(false);
return;
}
const manifest = mode === 'edit' && environment != null ? environment.manifest : defaultEnvironmentManifest();
- const nextForm = manifestToFormValues(manifest);
- const nextYaml = manifestToYaml(manifest);
- setForm(nextForm);
- setYamlText(nextYaml);
- setBaselineForm(nextForm);
- setBaselineYaml(nextYaml);
- setEditorMode('form');
+ setForm(manifestToFormValues(manifest));
setError(null);
- setPendingSwitch(null);
}, [open, mode, environment]);
- const formDirty = useMemo(() => JSON.stringify(form) !== JSON.stringify(baselineForm), [baselineForm, form]);
- const yamlDirty = yamlText !== baselineYaml;
- const dirty = editorMode === 'form' ? formDirty : yamlDirty;
-
- const requestSwitch = (next: EditorMode) => {
- if (next === editorMode) return;
- if (dirty) {
- setPendingSwitch(next);
- return;
- }
- applySwitch(next);
- };
-
- const applySwitch = (next: EditorMode) => {
- if (next === 'yaml') {
- const manifest = formValuesToManifest(form);
- const nextYaml = manifestToYaml(manifest);
- setYamlText(nextYaml);
- setBaselineYaml(nextYaml);
- setBaselineForm(form);
- } else {
- const parsed = parseManifestYaml(yamlText);
- if ('error' in parsed) {
- setError(parsed.error);
- setPendingSwitch(null);
- return;
- }
- const nextForm = manifestToFormValues(parsed.manifest);
- setForm(nextForm);
- setBaselineForm(nextForm);
- setBaselineYaml(yamlText);
- }
- setEditorMode(next);
- setPendingSwitch(null);
- setError(null);
- };
-
const handleSave = async (event: FormEvent) => {
event.preventDefault();
setError(null);
- let manifest: SandboxEnvironmentManifest;
- if (editorMode === 'form') {
- const validationError = validateEnvironmentForm(form);
- if (validationError != null) {
- setError(validationError);
- return;
- }
- manifest = formValuesToManifest(form);
- } else {
- const parsed = parseManifestYaml(yamlText);
- if ('error' in parsed) {
- setError(parsed.error);
- return;
- }
- manifest = parsed.manifest;
+ const validationError = validateEnvironmentForm(form);
+ if (validationError != null) {
+ setError(validationError);
+ return;
}
setSaving(true);
try {
- const saved = await environmentServer.createOrUpdateEnvironment({ manifest });
+ const saved = await environmentServer.createOrUpdateEnvironment({ manifest: formValuesToManifest(form) });
track(mode === 'create' ? AnalyticsEvents.Environment.CREATED : AnalyticsEvents.Environment.EDITED, {
environment_name: saved.name,
environment_id: saved.id,
@@ -145,111 +77,31 @@ export function EnvironmentFormDrawer({ open, onOpenChange, mode, environment, o
const title = mode === 'create' ? 'New environment' : (environment?.name ?? 'Edit environment');
return (
- <>
- <SideDrawer
- open={open}
- onOpenChange={onOpenChange}
- title={title}
- description={
- mode === 'create'
- ? 'Configure the environment.'
- : 'Configure the environment as a form or edit its manifest directly.'
- }
- size="xl"
- headerActions={
- mode === 'edit' ? (
- <div className="inline-flex shrink-0 rounded-md bg-secondary-bg p-0.5 border border-border">
- <button
- type="button"
- className={cn(
- 'rounded-sm px-2.5 py-1 text-xs font-medium transition-colors',
- editorMode === 'form'
- ? 'bg-primary-bg text-text-primary shadow-xs'
- : 'text-text-secondary hover:text-text-primary',
- )}
- onClick={() => requestSwitch('form')}
- >
- UI Form
- </button>
- <button
- type="button"
- className={cn(
- 'rounded-sm px-2.5 py-1 text-xs font-medium transition-colors',
- editorMode === 'yaml'
- ? 'bg-primary-bg text-text-primary shadow-xs'
- : 'text-text-secondary hover:text-text-primary',
- )}
- onClick={() => requestSwitch('yaml')}
- >
- YAML
- </button>
- </div>
- ) : undefined
- }
- footer={
- <div className="flex justify-end gap-2">
- <Button.Secondary type="button" disabled={saving} onClick={() => onOpenChange(false)}>
- Cancel
- </Button.Secondary>
- <Button.Primary type="submit" form="environment-form" disabled={saving}>
- {saving ? 'Saving…' : mode === 'create' ? 'Create' : 'Save'}
- </Button.Primary>
- </div>
- }
+ <SideDrawer
+ open={open}
+ onOpenChange={onOpenChange}
+ title={title}
+ description="Configure the environment."
+ size="xl"
+ footer={
+ <div className="flex justify-end gap-2">
+ <Button.Secondary type="button" disabled={saving} onClick={() => onOpenChange(false)}>
+ Cancel
+ </Button.Secondary>
+ <Button.Primary type="submit" form="environment-form" disabled={saving}>
+ {saving ? 'Saving…' : mode === 'create' ? 'Create' : 'Save'}
+ </Button.Primary>
+ </div>
+ }
+ >
+ <form
+ id="environment-form"
+ className="flex min-h-0 flex-1 flex-col gap-4 px-5 pt-4 pb-10"
+ onSubmit={event => void handleSave(event)}
>
- <form
- id="environment-form"
- className={cn(
- 'flex min-h-0 flex-1 flex-col gap-4 px-5 pt-4',
- editorMode === 'form' ? 'pb-10' : 'h-full pb-4',
- )}
- onSubmit={event => void handleSave(event)}
- >
- {error != null ? <p className="text-sm text-failure-bg">{error}</p> : null}
-
- {editorMode === 'form' ? (
- <EnvironmentFormFields values={form} onChange={setForm} nameDisabled={mode === 'edit'} />
- ) : (
- <div className="flex min-h-[30rem] flex-1 flex-col">
- <CodeEditor
- language="yaml"
- value={yamlText}
- height="100%"
- showToolbar={false}
- defaultShowLineNumbers
- className="flex-1"
- onChange={value => setYamlText(value)}
- />
- </div>
- )}
- </form>
- </SideDrawer>
-
- <Dialog open={pendingSwitch != null} onOpenChange={openDialog => !openDialog && setPendingSwitch(null)}>
- <DialogContent>
- <DialogHeader>
- <DialogTitle>Warning</DialogTitle>
- </DialogHeader>
- <p className="text-sm text-text-secondary">
- {pendingSwitch === 'form'
- ? 'The YAML changes will be lost. Are you sure you want to switch to UI form?'
- : 'You might lose all your changes from the form. Are you sure you want to switch to YAML Editor?'}
- </p>
- <DialogFooter>
- <Button.Secondary type="button" onClick={() => setPendingSwitch(null)}>
- Cancel
- </Button.Secondary>
- <Button.Primary
- type="button"
- onClick={() => {
- if (pendingSwitch != null) applySwitch(pendingSwitch);
- }}
- >
- Yes
- </Button.Primary>
- </DialogFooter>
- </DialogContent>
- </Dialog>
- </>
+ {error != null ? <p className="text-sm text-failure-bg">{error}</p> : null}
+ <EnvironmentFormFields values={form} onChange={setForm} nameDisabled={mode === 'edit'} />
+ </form>
+ </SideDrawer>
);
}
diff --git a/packages/trueforge-ui/src/atoms/environments/environmentYaml.ts b/packages/trueforge-ui/src/atoms/environments/environmentYaml.ts
deleted file mode 100644
index b66d7503d..000000000
--- a/packages/trueforge-ui/src/atoms/environments/environmentYaml.ts
+++ /dev/null
@@ -1,36 +0,0 @@
-import { parse as parseYaml, stringify as stringifyYaml } from 'yaml';
-
-import type { SandboxEnvironmentManifest } from '../../server/types.js';
-import { getErrorMessage } from '../../utils/getErrorMessage.js';
-import { isReservedEnvironmentName } from './environmentDisplay.js';
-
-export function manifestToYaml(manifest: SandboxEnvironmentManifest): string {
- return stringifyYaml(manifest, { lineWidth: 0 });
-}
-
-function isSandboxEnvironmentManifest(value: unknown): value is SandboxEnvironmentManifest {
- if (value == null || typeof value !== 'object' || Array.isArray(value)) return false;
- if (!('name' in value) || typeof value.name !== 'string' || value.name.trim().length === 0) {
- return false;
- }
- return true;
-}
-
-export function parseManifestYaml(text: string): { manifest: SandboxEnvironmentManifest } | { error: string } {
- let parsed: unknown;
- try {
- parsed = parseYaml(text);
- } catch (caught) {
- return { error: getErrorMessage(caught, 'Invalid YAML') };
- }
- if (!isSandboxEnvironmentManifest(parsed)) {
- if (parsed == null || typeof parsed !== 'object' || Array.isArray(parsed)) {
- return { error: 'YAML must be an object manifest' };
- }
- return { error: 'Manifest name is required' };
- }
- if (isReservedEnvironmentName(parsed.name)) {
- return { error: 'Name "default" is reserved' };
- }
- return { manifest: parsed };
-}
diff --git a/packages/trueforge-ui/test/atoms/environments/EnvironmentFormDrawer.test.tsx b/packages/trueforge-ui/test/atoms/environments/EnvironmentFormDrawer.test.tsx
index ce333b97f..b9359f496 100644
--- a/packages/trueforge-ui/test/atoms/environments/EnvironmentFormDrawer.test.tsx
+++ b/packages/trueforge-ui/test/atoms/environments/EnvironmentFormDrawer.test.tsx
@@ -131,17 +131,17 @@ describe('EnvironmentFormDrawer', () => {
});
});
- it('confirms when switching modes while dirty in edit', async () => {
- renderDrawer({ mode: 'edit', environment: editEnvironment });
+ it('saves UI form values in edit without a YAML switch', async () => {
+ const { createOrUpdateEnvironment, onSaved } = renderDrawer({ mode: 'edit', environment: editEnvironment });
+ expect(screen.queryByRole('button', { name: 'YAML' })).not.toBeInTheDocument();
fireEvent.change(screen.getByPlaceholderText('write description ...'), {
- target: { value: 'dirty description' },
+ target: { value: 'updated description' },
});
- fireEvent.click(screen.getByRole('button', { name: 'YAML' }));
- expect(await screen.findByRole('button', { name: 'Yes' })).toBeInTheDocument();
- fireEvent.click(screen.getByRole('button', { name: 'Yes' }));
+ fireEvent.click(screen.getByRole('button', { name: 'Save' }));
await waitFor(() => {
- expect(screen.queryByPlaceholderText('write description ...')).not.toBeInTheDocument();
+ expect(createOrUpdateEnvironment).toHaveBeenCalled();
});
- expect(screen.queryByRole('button', { name: 'Yes' })).not.toBeInTheDocument();
+ expect(createOrUpdateEnvironment.mock.calls[0]?.[0]?.manifest.description).toBe('updated description');
+ expect(onSaved).toHaveBeenCalled();
});
});
diff --git a/packages/trueforge-ui/test/atoms/environments/environmentYaml.test.ts b/packages/trueforge-ui/test/atoms/environments/environmentYaml.test.ts
deleted file mode 100644
index 2526d8895..000000000
--- a/packages/trueforge-ui/test/atoms/environments/environmentYaml.test.ts
+++ /dev/null
@@ -1,27 +0,0 @@
-import { describe, expect, it } from 'vitest';
-
-import { manifestToYaml, parseManifestYaml } from '@/atoms/environments/environmentYaml.js';
-
-describe('environmentYaml', () => {
- it('round-trips a manifest', () => {
- const yaml = manifestToYaml({
- name: 'yaml-env',
- description: 'from yaml',
- resources: { cpu: 2, memory: 2, disk: 5 },
- });
- const parsed = parseManifestYaml(yaml);
- expect(parsed).toEqual({
- manifest: {
- name: 'yaml-env',
- description: 'from yaml',
- resources: { cpu: 2, memory: 2, disk: 5 },
- },
- });
- });
-
- it('rejects reserved default name and invalid YAML', () => {
- expect(parseManifestYaml('name: default\n')).toEqual({ error: 'Name "default" is reserved' });
- expect(parseManifestYaml('name: ')).toMatchObject({ error: expect.any(String) });
- expect(parseManifestYaml('- just a list')).toEqual({ error: 'YAML must be an object manifest' });
- });
-});
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 6fcba7b20..49eff1dca 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -462,9 +462,6 @@ importers:
thinking-orbs:
specifier: ^0.3.1
version: 0.3.2([email protected])
- yaml:
- specifier: ^2.9.0
- version: 2.9.1
zod:
specifier: ^4.4.3
version: 4.6.5