From eb7c6c7b21c65fd04f5484a89eca348c9424841e Mon Sep 17 00:00:00 2001 From: Josh Knapp Date: Sun, 15 Nov 2026 10:15:14 -0800 Subject: [PATCH] feat(aws): AWS project settings and the stop guard Add Project picks Local or an AWS connection, a region and a ready, joined environment, with repositories instead of folders. The Config tab's Host section edits CPU/memory (valid pairs only), architecture, storage, ephemeral size, Spot, idle stop, WIP push and repositories, and can remove the AWS resources or move the project back to this machine. Docker access, VPN, port mappings and the gateway backend are disabled on AWS with the reason; the sandbox shows Off on AWS for now. Stop on an AWS workspace with unsaved work asks first (Push to WIP branch preselected); a failed start shows the task's last log lines; removing an AWS project can delete its saved files, and asks again when its connection is gone. Co-Authored-By: Claude Opus 5.5 --- .../projects/AddProjectDialog.test.tsx | 99 +++++ .../components/projects/AddProjectDialog.tsx | 309 ++++++++++--- .../projects/ConfirmRemoveModal.test.tsx | 37 ++ .../projects/ConfirmRemoveModal.tsx | 119 ++++- app/src/components/projects/ProjectRow.tsx | 21 +- .../components/projects/RepoListEditor.tsx | 133 ++++++ .../projects/StopGuardModal.test.tsx | 51 +++ .../components/projects/StopGuardModal.tsx | 102 +++++ .../components/projects/home/ConfigTab.tsx | 5 + .../components/projects/home/ProjectHome.tsx | 97 ++-- .../projects/home/config/AccessSection.tsx | 27 +- .../projects/home/config/AwsConfig.test.tsx | 132 ++++++ .../projects/home/config/HostSection.tsx | 419 ++++++++++++++++++ .../projects/home/config/ModelSection.tsx | 24 +- .../projects/home/config/RuntimeSection.tsx | 28 +- .../projects/home/config/WorkspaceSection.tsx | 159 ++++--- app/src/components/ui/Button.tsx | 4 +- app/src/hooks/useProjectActions.test.ts | 122 +++++ app/src/hooks/useProjectActions.ts | 76 +++- app/src/hooks/useProjects.ts | 14 +- app/src/lib/awsWorkspace.test.ts | 53 +++ app/src/lib/awsWorkspace.ts | 125 ++++++ app/src/lib/tauri-commands.ts | 31 +- app/src/lib/types.ts | 34 ++ app/src/test/awsFixtures.ts | 76 ++++ 25 files changed, 2065 insertions(+), 232 deletions(-) create mode 100644 app/src/components/projects/ConfirmRemoveModal.test.tsx create mode 100644 app/src/components/projects/RepoListEditor.tsx create mode 100644 app/src/components/projects/StopGuardModal.test.tsx create mode 100644 app/src/components/projects/StopGuardModal.tsx create mode 100644 app/src/components/projects/home/config/AwsConfig.test.tsx create mode 100644 app/src/components/projects/home/config/HostSection.tsx create mode 100644 app/src/hooks/useProjectActions.test.ts create mode 100644 app/src/lib/awsWorkspace.test.ts create mode 100644 app/src/lib/awsWorkspace.ts create mode 100644 app/src/test/awsFixtures.ts diff --git a/app/src/components/projects/AddProjectDialog.test.tsx b/app/src/components/projects/AddProjectDialog.test.tsx index 4179f43..b9ba61a 100644 --- a/app/src/components/projects/AddProjectDialog.test.tsx +++ b/app/src/components/projects/AddProjectDialog.test.tsx @@ -1,6 +1,9 @@ import { describe, it, expect, vi, beforeEach } from "vitest"; import { render, screen, fireEvent, waitFor, act } from "@testing-library/react"; import AddProjectDialog from "./AddProjectDialog"; +import { useAppState } from "../../store/appState"; +import type { AppSettings, EnvironmentScan } from "../../lib/types"; +import { environment } from "../../test/awsFixtures"; const add = vi.fn(); @@ -12,6 +15,11 @@ vi.mock("@tauri-apps/plugin-dialog", () => ({ open: vi.fn(async () => null), })); +const detectAwsEnvironments = vi.fn(); +vi.mock("../../lib/tauri-commands", () => ({ + detectAwsEnvironments: (c: string, r: string) => detectAwsEnvironments(c, r), +})); + /** A promise whose resolution this test controls, so `loading` can be held open. */ function deferred() { let resolve!: (v: unknown) => void; @@ -116,3 +124,94 @@ describe("AddProjectDialog", () => { expect(submitButton()).toHaveAccessibleDescription(""); }); }); + +describe("AddProjectDialog on AWS", () => { + const scan = (envs: EnvironmentScan["environments"]): EnvironmentScan => ({ + region: "eu-west-1", + account: "111122223333", + owner_id: "AROA:alice", + owner_key: "abc", + state_bucket: "yes", + boundary: "yes", + environments: envs, + }); + + beforeEach(() => { + vi.clearAllMocks(); + useAppState.setState({ + appSettings: { + hosts: [ + { + id: "c1", + name: "Work account", + kind: { type: "aws", auth: { method: "profile", name: "work" }, default_region: "eu-west-1" }, + }, + ], + } as unknown as AppSettings, + }); + }); + + function chooseAws() { + fireEvent.change(screen.getByLabelText("Runs on"), { target: { value: "c1" } }); + } + + it("sends the host, placement and workspace with repositories instead of folders", async () => { + detectAwsEnvironments.mockResolvedValue( + scan([environment("staging", "deploying", true), environment("dev", "ready", true)]), + ); + add.mockResolvedValue({ id: "p1" }); + const onClose = vi.fn(); + render(); + chooseAws(); + expect(screen.getByLabelText("Region")).toHaveValue("eu-west-1"); + await waitFor(() => expect(screen.getByLabelText("Environment")).toHaveValue("dev")); + expect(detectAwsEnvironments).toHaveBeenCalledWith("c1", "eu-west-1"); + expect( + (screen.getByRole("option", { name: /staging/ }) as HTMLOptionElement).disabled, + ).toBe(true); + expect(screen.queryByLabelText("Folder 1 host path")).toBeNull(); + + fireEvent.change(screen.getByLabelText("Project name"), { target: { value: "api" } }); + fireEvent.change(screen.getByLabelText("Repository 1 URL"), { + target: { value: "git@github.com:org/api.git" }, + }); + fireEvent.change(screen.getByLabelText("Repository 1 branch"), { target: { value: "develop" } }); + fireEvent.click(submitButton()); + + await waitFor(() => expect(add).toHaveBeenCalled()); + const [name, paths, host] = add.mock.calls[0]; + expect(name).toBe("api"); + expect(paths).toEqual([]); + expect(host.hostId).toBe("c1"); + expect(host.awsPlacement).toEqual({ region: "eu-west-1", environment: "dev" }); + expect(host.aws.repos).toEqual([ + { url: "git@github.com:org/api.git", branch: "develop", folder: "api" }, + ]); + expect(host.aws).toMatchObject({ cpu: 1024, memory_mib: 4096, wip_push_on_stop: true, task_arn: null }); + await waitFor(() => expect(onClose).toHaveBeenCalled()); + }); + + it("points at Settings → Hosts when no environment is usable", async () => { + detectAwsEnvironments.mockResolvedValue(scan([environment("dev", "ready", false)])); + render(); + chooseAws(); + expect(await screen.findByText(/Settings → Hosts/)).toBeInTheDocument(); + expect(screen.queryByLabelText("Environment")).toBeNull(); + fireEvent.change(screen.getByLabelText("Project name"), { target: { value: "api" } }); + fireEvent.click(submitButton()); + expect(await screen.findByRole("alert")).toHaveTextContent(/Choose an environment/); + expect(add).not.toHaveBeenCalled(); + }); + + it("shows the backend's validation message when the add is refused", async () => { + detectAwsEnvironments.mockResolvedValue(scan([environment("dev", "update_available", true)])); + add.mockRejectedValue('Repository URL "ftp://x": use https://..., ssh://... or git@host:path'); + render(); + chooseAws(); + await waitFor(() => expect(screen.getByLabelText("Environment")).toHaveValue("dev")); + fireEvent.change(screen.getByLabelText("Project name"), { target: { value: "api" } }); + fireEvent.change(screen.getByLabelText("Repository 1 URL"), { target: { value: "ftp://x" } }); + fireEvent.click(submitButton()); + expect(await screen.findByRole("alert")).toHaveTextContent(/use https:\/\//); + }); +}); diff --git a/app/src/components/projects/AddProjectDialog.tsx b/app/src/components/projects/AddProjectDialog.tsx index 0187fd3..a306ac2 100644 --- a/app/src/components/projects/AddProjectDialog.tsx +++ b/app/src/components/projects/AddProjectDialog.tsx @@ -1,10 +1,15 @@ -import { useId, useRef, useState } from "react"; +import { useEffect, useId, useRef, useState } from "react"; import { open } from "@tauri-apps/plugin-dialog"; import { useProjects } from "../../hooks/useProjects"; -import type { ProjectPath } from "../../lib/types"; +import type { DetectedEnvironment, HostConnection, ProjectPath, RepoSource } from "../../lib/types"; +import { detectAwsEnvironments } from "../../lib/tauri-commands"; +import { awsErrorMessage, toAwsError } from "../../lib/aws-error"; +import { cleanRepos, defaultAwsWorkspace, environmentSelectable } from "../../lib/awsWorkspace"; +import { useAppState } from "../../store/appState"; import Modal from "../ui/Modal"; import Button from "../ui/Button"; -import { inputClass, monoInputClass } from "../ui/Field"; +import { inputClass, monoInputClass, selectClass } from "../ui/Field"; +import { RepoRows, emptyRepo } from "./RepoListEditor"; interface Props { onClose: () => void; @@ -15,12 +20,36 @@ interface PathEntry { mount_name: string; } +/** Why an environment can't take a new project, for its disabled option. */ +function unavailableReason(env: DetectedEnvironment): string { + const st = env.state.state; + if (st !== "ready" && st !== "update_available") return st.replace(/_/g, " "); + return "you have not joined it"; +} + +type Scan = + | { status: "idle" } + | { status: "loading" } + | { status: "error"; message: string } + | { status: "done"; environments: DetectedEnvironment[] }; + function basenameFromPath(p: string): string { return p.replace(/[/\\]$/, "").split(/[/\\]/).pop() || ""; } +/** Stable, so the store selector does not return a new array each render. */ +const NO_HOSTS: HostConnection[] = []; + export default function AddProjectDialog({ onClose }: Props) { const { add } = useProjects(); + const hosts = useAppState((s) => s.appSettings?.hosts ?? NO_HOSTS); + const [hostId, setHostId] = useState(""); + const connection = hosts.find((h) => h.id === hostId) ?? null; + const [region, setRegion] = useState(""); + const [scanRegion, setScanRegion] = useState(""); + const [scan, setScan] = useState({ status: "idle" }); + const [environment, setEnvironment] = useState(""); + const [repos, setRepos] = useState([emptyRepo()]); const [name, setName] = useState(""); const [pathEntries, setPathEntries] = useState([ { host_path: "", mount_name: "" }, @@ -30,6 +59,39 @@ export default function AddProjectDialog({ onClose }: Props) { const nameInputRef = useRef(null); const formId = useId(); + // Look for environments when the connection or the region (on blur) changes. + useEffect(() => { + if (!connection || !scanRegion) { + setScan({ status: "idle" }); + return; + } + let cancelled = false; + setScan({ status: "loading" }); + detectAwsEnvironments(connection.id, scanRegion).then( + (found) => { + if (cancelled) return; + setScan({ status: "done", environments: found.environments }); + const first = found.environments.find(environmentSelectable); + setEnvironment(first?.name ?? ""); + }, + (e) => { + if (!cancelled) setScan({ status: "error", message: awsErrorMessage(toAwsError(e)) }); + }, + ); + return () => { + cancelled = true; + }; + }, [connection, scanRegion]); + + const chooseHost = (id: string) => { + setHostId(id); + setEnvironment(""); + const conn = hosts.find((h) => h.id === id); + const r = conn?.kind.default_region ?? ""; + setRegion(r); + setScanRegion(r); + }; + const handleBrowse = async (index: number) => { const selected = await open({ directory: true, multiple: false }); if (typeof selected === "string") { @@ -63,6 +125,33 @@ export default function AddProjectDialog({ onClose }: Props) { setError("Project name is required"); return; } + if (connection) { + if (!environment) { + setError("Choose an environment to run the project in"); + return; + } + const cleaned = cleanRepos(repos); + if (cleaned.some((r) => !r.url)) { + setError("Every repository needs a URL"); + return; + } + setLoading(true); + setError(null); + try { + await add(name.trim(), [], { + hostId: connection.id, + awsPlacement: { region: scanRegion, environment }, + aws: { ...defaultAwsWorkspace(), repos: cleaned }, + }); + onClose(); + } catch (err) { + // The backend's validation message (repository URL, folder, …). + setError(String(err)); + } finally { + setLoading(false); + } + return; + } const validPaths: ProjectPath[] = pathEntries .filter((p) => p.host_path.trim()) .map((p) => ({ @@ -137,62 +226,166 @@ export default function AddProjectDialog({ onClose }: Props) { /> -
- Folders -
- {pathEntries.map((entry, i) => ( -
-
- updateEntry(i, "host_path", e.target.value)} - placeholder="/path/to/folder" - aria-label={`Folder ${i + 1} host path`} - className={inputClass} - /> - - {pathEntries.length > 1 && ( - - )} -
-
- - /workspace/ - - updateEntry(i, "mount_name", e.target.value)} - placeholder="mount-name" - aria-label={`Folder ${i + 1} mount name`} - className={monoInputClass} - /> -
-
- ))} + {hosts.length > 0 && ( +
+ +
- -
+ )} + + {connection ? ( + <> +
+ + setRegion(e.target.value)} + onBlur={() => setScanRegion(region.trim())} + onKeyDown={(e) => { + if (e.key === "Enter") { + e.preventDefault(); + setScanRegion(region.trim()); + } + }} + className={monoInputClass} + /> +
+
+ + {scan.status === "loading" && ( +

+ Looking for environments in {scanRegion}… +

+ )} + {scan.status === "error" && ( +

{scan.message}

+ )} + {scan.status === "done" && ( + <> + {scan.environments.some(environmentSelectable) ? ( + + ) : ( +

+ No environment in {scanRegion} is ready for you to use. Deploy or join + one in Settings → Hosts. +

+ )} + + )} +
+
+ Repositories +

+ Cloned into /workspace/<folder> when + the workspace starts. Memory, storage and the rest are in the project’s + Config tab. +

+ +
+ + ) : ( +
+ Folders +
+ {pathEntries.map((entry, i) => ( +
+
+ updateEntry(i, "host_path", e.target.value)} + placeholder="/path/to/folder" + aria-label={`Folder ${i + 1} host path`} + className={inputClass} + /> + + {pathEntries.length > 1 && ( + + )} +
+
+ + /workspace/ + + updateEntry(i, "mount_name", e.target.value)} + placeholder="mount-name" + aria-label={`Folder ${i + 1} mount name`} + className={monoInputClass} + /> +
+
+ ))} +
+ +
+ )} {error && (
{ + it("keeps an AWS workspace's saved files unless asked", () => { + const onConfirm = vi.fn(); + render(); + const box = screen.getByRole("checkbox", { name: /saved files \(EFS\)/ }); + expect(box).not.toBeChecked(); + fireEvent.click(screen.getByRole("button", { name: "Remove" })); + fireEvent.click(box); + fireEvent.click(screen.getByRole("button", { name: "Remove" })); + expect(onConfirm.mock.calls).toEqual([[{ discardData: false }], [{ discardData: true }]]); + }); + + it("offers no EFS choice for a local project", () => { + render(); + expect(screen.queryByRole("checkbox")).toBeNull(); + expect(screen.getByText(/mounted in, not copied/)).toBeInTheDocument(); + }); + + it("says what is left in AWS when the connection is gone", () => { + const onConfirm = vi.fn(); + render( + , + ); + expect(screen.getByText(/task definitions, its secret and its saved files/)).toBeInTheDocument(); + fireEvent.click(screen.getByRole("button", { name: "Remove and leave them in AWS" })); + expect(onConfirm).toHaveBeenCalled(); + }); +}); diff --git a/app/src/components/projects/ConfirmRemoveModal.tsx b/app/src/components/projects/ConfirmRemoveModal.tsx index 1fc53b4..f081606 100644 --- a/app/src/components/projects/ConfirmRemoveModal.tsx +++ b/app/src/components/projects/ConfirmRemoveModal.tsx @@ -1,13 +1,20 @@ +import { useState } from "react"; import Modal from "../ui/Modal"; import Button from "../ui/Button"; interface Props { projectName: string; - onConfirm: () => void; + /** An AWS project: its task, task definitions and secret go instead of Docker state. */ + aws?: boolean; + onConfirm: (opts: { discardData: boolean }) => void; onCancel: () => void; } -export default function ConfirmRemoveModal({ projectName, onConfirm, onCancel }: Props) { +const REMOVE_CLASS = + "bg-[var(--error-emphasis)] text-white border border-transparent hover:opacity-90"; + +export default function ConfirmRemoveModal({ projectName, aws = false, onConfirm, onCancel }: Props) { + const [discardData, setDiscardData] = useState(false); return ( Cancel - } > - {/* - Everything remove_project() destroys, named. It removes the container, - *both* named volumes (triple-c-home-{id} and triple-c-claude-config-{id}), - the triple-c-snapshot-{id} image and the project's keychain secrets — so - an accurate warning has to reach past "the config volume". The last - sentence is the reassuring half and matters just as much: project folders - are bind mounts from the host and nothing here touches them. - */} -

- Are you sure you want to remove{" "} - {projectName}? This deletes - its container, both of its volumes and its saved container image — so the home - directory, the Claude login and config, installed skills, session transcripts, - scheduled tasks and any stored credentials all go with it. -

+ {aws ? ( + <> +

+ Are you sure you want to remove{" "} + {projectName}? This stops its + workspace on AWS and removes its task definitions and its secret (the secret is + deleted after AWS’s 7-day recovery window). Work that was not pushed to a + remote is lost. +

+ + + ) : ( + <> + {/* + Everything remove_project() destroys, named. It removes the container, + *both* named volumes (triple-c-home-{id} and triple-c-claude-config-{id}), + the triple-c-snapshot-{id} image and the project's keychain secrets — so + an accurate warning has to reach past "the config volume". The last + sentence is the reassuring half and matters just as much: project folders + are bind mounts from the host and nothing here touches them. + */} +

+ Are you sure you want to remove{" "} + {projectName}? This deletes + its container, both of its volumes and its saved container image — so the home + directory, the Claude login and config, installed skills, session transcripts, + scheduled tasks and any stored credentials all go with it. +

+

+ Your project folders on this machine are mounted in, not copied, and are left + untouched. +

+ + )} +
+ ); +} + +/** The second confirm when an AWS project's connection is gone. */ +export function ConfirmForgetAwsModal({ + projectName, + reason, + onConfirm, + onCancel, +}: { + projectName: string; + reason: string; + onConfirm: () => void; + onCancel: () => void; +}) { + return ( + + + + + } + > +

{reason}

- Your project folders on this machine are mounted in, not copied, and are left - untouched. + Removing {projectName} now + leaves its AWS resources in the account: the task (which may still be running and + billed), its task definitions, its secret and its saved files. You would have to + remove them in AWS yourself.

); diff --git a/app/src/components/projects/ProjectRow.tsx b/app/src/components/projects/ProjectRow.tsx index 87e981e..f6eef6e 100644 --- a/app/src/components/projects/ProjectRow.tsx +++ b/app/src/components/projects/ProjectRow.tsx @@ -4,6 +4,8 @@ import { useAppState, homeTabKey } from "../../store/appState"; import { useProjectActions } from "../../hooks/useProjectActions"; import { ProjectStatusIndicator } from "../ui/StatusIndicator"; import { useUnavailable } from "../ui/unavailable"; +import { isAwsProject } from "../../lib/awsWorkspace"; +import StopGuardModal from "./StopGuardModal"; interface Props { project: Project; @@ -23,8 +25,13 @@ export default function ProjectRow({ project }: Props) { progress: s.containerProgress[project.id], })), ); - const { busy, handleStart, handleStop, openClaudeTerminal } = + const { busy, handleStart, handleStop, openClaudeTerminal, stopGuard, resolveStopGuard } = useProjectActions(project); + const aws = isAwsProject(project); + // An AWS project mounts nothing; its clones are what /workspace holds. + const folders = aws + ? (project.aws?.repos ?? []).map((r) => r.folder) + : project.paths.map((pp) => pp.mount_name); const isSelected = activeTabKey === homeTabKey(project.id) || selectedProjectId === project.id; @@ -64,12 +71,17 @@ export default function ProjectRow({ project }: Props) {
- {project.paths.map((pp, i) => ( + {aws && ( +
+ AWS · {project.aws_placement?.environment ?? "?"} ({project.aws_placement?.region ?? "?"}) +
+ )} + {folders.map((folder, i) => (
- /workspace/{pp.mount_name} + /workspace/{folder}
))}
@@ -149,6 +161,9 @@ export default function ProjectRow({ project }: Props) { {terminal.reasonNode}
+ {stopGuard && ( + + )}
); } diff --git a/app/src/components/projects/RepoListEditor.tsx b/app/src/components/projects/RepoListEditor.tsx new file mode 100644 index 0000000..285feb5 --- /dev/null +++ b/app/src/components/projects/RepoListEditor.tsx @@ -0,0 +1,133 @@ +import { useEffect, useState } from "react"; +import type { RepoSource } from "../../lib/types"; +import { cleanRepos, repoFolderFromUrl } from "../../lib/awsWorkspace"; +import Button from "../ui/Button"; +import { inputClass, monoInputClass } from "../ui/Field"; + +export interface RepoRowsProps { + rows: RepoSource[]; + onRowsChange: (rows: RepoSource[]) => void; + /** Called when focus leaves a field (save-on-blur editors). */ + onCommit?: () => void; + disabled?: boolean; +} + +export const emptyRepo = (): RepoSource => ({ url: "", branch: null, folder: "" }); + +/** Rows of URL / branch / folder. The folder follows the URL until it is edited. */ +export function RepoRows({ rows, onRowsChange, onCommit, disabled = false }: RepoRowsProps) { + const update = (i: number, patch: Partial) => { + const next = [...rows]; + next[i] = { ...next[i], ...patch }; + onRowsChange(next); + }; + return ( +
+ {rows.map((r, i) => ( +
+ { + const url = e.target.value; + const followed = !r.folder || r.folder === repoFolderFromUrl(r.url); + update(i, { url, ...(followed ? { folder: repoFolderFromUrl(url) } : {}) }); + }} + onBlur={onCommit} + className={monoInputClass} + /> +
+ update(i, { branch: e.target.value })} + onBlur={onCommit} + className={`w-40 ${inputClass}`} + /> + + /workspace/ + + update(i, { folder: e.target.value })} + onBlur={onCommit} + className={monoInputClass} + /> + +
+
+ ))} + +
+ ); +} + +function sameRepos(a: RepoSource[], b: RepoSource[]): boolean { + return ( + a.length === b.length && + a.every((r, i) => r.url === b[i].url && r.branch === b[i].branch && r.folder === b[i].folder) + ); +} + +/** + * The Config tab's save-on-blur repository list. Saves when every row that + * has anything in it has a URL; the backend's validation message (bad URL, + * folder used twice…) comes back through the save's toast. + */ +export default function RepoListEditor({ + repos, + onSave, + disabled = false, +}: { + repos: RepoSource[]; + onSave: (repos: RepoSource[]) => Promise; + disabled?: boolean; +}) { + const [rows, setRows] = useState(repos); + useEffect(() => setRows(repos), [repos]); + + // A commit bumps this; the effect then runs against the rendered rows. + const [pending, setPending] = useState(0); + useEffect(() => { + if (pending === 0) return; + const cleaned = cleanRepos(rows); + if (cleaned.some((r) => !r.url)) return; + if (sameRepos(cleaned, repos)) return; + void onSave(cleaned); + // Only a commit triggers this; `rows` changing alone does not save. + }, [pending]); + + return ( + setPending((n) => n + 1)} + disabled={disabled} + /> + ); +} diff --git a/app/src/components/projects/StopGuardModal.test.tsx b/app/src/components/projects/StopGuardModal.test.tsx new file mode 100644 index 0000000..9994328 --- /dev/null +++ b/app/src/components/projects/StopGuardModal.test.tsx @@ -0,0 +1,51 @@ +import { describe, it, expect, vi } from "vitest"; +import { render, screen, fireEvent, waitFor } from "@testing-library/react"; +import StopGuardModal from "./StopGuardModal"; +import type { UnsavedWork } from "../../lib/types"; + +const dirty: UnsavedWork = { + checked: true, + repos: [ + { folder: "api", branch: "main", dirty: true, unpushed: 2 }, + { folder: "clean", branch: "main", dirty: false, unpushed: 0 }, + ], + error: null, +}; + +describe("StopGuardModal", () => { + it("lists the repositories at risk and defaults to pushing", async () => { + const onChoose = vi.fn(); + render(); + expect(screen.getByText("/workspace/api")).toBeInTheDocument(); + expect(screen.getByText(/uncommitted changes, 2 unpushed commits/)).toBeInTheDocument(); + expect(screen.queryByText("/workspace/clean")).toBeNull(); + const push = screen.getByRole("button", { name: "Push to WIP branch and stop" }); + await waitFor(() => expect(push).toHaveFocus()); + fireEvent.click(push); + expect(onChoose).toHaveBeenCalledWith("push"); + }); + + it("offers Stop anyway and Cancel", () => { + const onChoose = vi.fn(); + render(); + fireEvent.click(screen.getByRole("button", { name: "Stop anyway" })); + fireEvent.click(screen.getByRole("button", { name: "Cancel" })); + expect(onChoose.mock.calls).toEqual([["discard"], [null]]); + }); + + it("hides Push and says why when the workspace could not be checked", async () => { + const onChoose = vi.fn(); + render( + , + ); + expect(screen.queryByRole("button", { name: /Push/ })).toBeNull(); + expect(screen.getByText("Triple-C is not connected to the workspace")).toBeInTheDocument(); + expect(screen.getByText(/could not check/)).toBeInTheDocument(); + const stop = screen.getByRole("button", { name: "Stop anyway" }); + await waitFor(() => expect(stop).toHaveFocus()); + }); +}); diff --git a/app/src/components/projects/StopGuardModal.tsx b/app/src/components/projects/StopGuardModal.tsx new file mode 100644 index 0000000..73dc7ea --- /dev/null +++ b/app/src/components/projects/StopGuardModal.tsx @@ -0,0 +1,102 @@ +import { useRef } from "react"; +import type { UnsavedWork, WipChoice } from "../../lib/types"; +import Modal from "../ui/Modal"; +import Button from "../ui/Button"; + +interface Props { + projectName: string; + work: UnsavedWork; + /** `null` = Cancel. */ + onChoose: (choice: WipChoice | null) => void; +} + +function describeRepo(dirty: boolean, unpushed: number): string { + const parts: string[] = []; + if (dirty) parts.push("uncommitted changes"); + if (unpushed > 0) parts.push(`${unpushed} unpushed commit${unpushed === 1 ? "" : "s"}`); + return parts.join(", "); +} + +/** + * Asked before an AWS workspace stops when its repositories hold work no + * remote has, or when Triple-C could not check. Pushing to a WIP branch is + * the default (it has focus); it is not offered when the check could not + * run, since the push goes the same way the check did. + */ +export default function StopGuardModal({ projectName, work, onChoose }: Props) { + const pushRef = useRef(null); + const stopRef = useRef(null); + const atRisk = work.repos.filter((r) => r.dirty || r.unpushed > 0); + + return ( + onChoose(null)} + widthClassName="w-[30rem]" + initialFocusRef={work.checked ? pushRef : stopRef} + footer={ + <> + + + {work.checked && ( + + )} + + } + > + {work.checked ? ( + <> +

+ Stopping {projectName} ends + its workspace. These repositories have work that no remote has yet: +

+
    + {atRisk.map((r) => ( +
  • + /workspace/{r.folder}{" "} + + ({r.branch}): {describeRepo(r.dirty, r.unpushed)} + +
  • + ))} +
+

+ Push to WIP branch saves a snapshot of each repository to a{" "} + triple-c/wip/… branch on its remote, without + touching your branches. If the push fails, the workspace keeps running. +

+ + ) : ( + <> +

+ Triple-C could not check{" "} + {projectName} for unsaved + work, so it can’t push it to a WIP branch first. +

+ {work.error && ( +

+ {work.error} +

+ )} +

+ Uncommitted or unpushed work in the workspace may be lost if you stop it now. +

+ + )} +
+ ); +} diff --git a/app/src/components/projects/home/ConfigTab.tsx b/app/src/components/projects/home/ConfigTab.tsx index 037f228..e478f58 100644 --- a/app/src/components/projects/home/ConfigTab.tsx +++ b/app/src/components/projects/home/ConfigTab.tsx @@ -6,6 +6,8 @@ import ModelSection from "./config/ModelSection"; import AccessSection from "./config/AccessSection"; import RuntimeSection from "./config/RuntimeSection"; import MarketplaceSection from "./config/MarketplaceSection"; +import HostSection from "./config/HostSection"; +import { isAwsProject } from "../../../lib/awsWorkspace"; interface Props { project: Project; @@ -40,6 +42,9 @@ export default function ConfigTab({ project, save, saveState }: Props) {
+ {isAwsProject(project) && ( + + )} (null); const [confirmReset, setConfirmReset] = useState(false); const [showMigration, setShowMigration] = useState(false); const { runningSince, progress } = useAppState( @@ -99,6 +103,7 @@ export default function ProjectHome({ projectId, active }: Props) { ); } + const aws = isAwsProject(project); const isRunning = project.status === "running"; const isTransitioning = project.status === "starting" || project.status === "stopping"; @@ -120,6 +125,41 @@ export default function ProjectHome({ projectId, active }: Props) { migration.probeSettled && !!project.container_id; + /** Remove the project; an AWS project whose connection is gone asks again. */ + const removeProject = async (opts: RemoveProjectOptions) => { + try { + const report = await remove(project.id, opts); + if (!projectRemovalIsClean(report)) { + const verb = leftoverVerb(report); + if (report.retry_scheduled) { + useAppState.getState().pushToast({ + kind: "info", + message: `“${project.name}” was removed, but Triple-C could not confirm all its Docker resources were removed`, + detail: `Triple-C could not confirm ${describeLeftovers(report)} ${verb} removed. It will check again the next time it starts.`, + }); + } else { + // The pending-cleanup record itself failed to save — no + // retry will happen, so this must not promise one. + useAppState.getState().pushToast({ + kind: "error", + message: `“${project.name}” was removed, but Triple-C could not confirm its Docker resources were removed`, + detail: `Triple-C could not confirm ${describeLeftovers(report)} ${verb} removed, and could not record this for a retry. You may need to remove ${leftoverPronoun(report)} manually (\`docker rm\` / \`docker rmi\` / \`docker volume rm\`).`, + }); + } + } + } catch (e) { + if (aws && !opts.forgetAwsResources && /connection no longer exists/i.test(String(e))) { + setForgetAws({ reason: String(e), discardData: !!opts.discardData }); + return; + } + useAppState.getState().pushToast({ + kind: "error", + message: `Could not remove “${project.name}”`, + detail: String(e), + }); + } + }; + return (
{/* Header */} @@ -188,12 +228,13 @@ export default function ProjectHome({ projectId, active }: Props) { { label: "Update container base…", onSelect: () => setShowMigration(true), - disabled: !canMigrate, + // Docker-only: the backend refuses both for an AWS project. + disabled: aws || !canMigrate, }, { label: "Reset container…", onSelect: () => setConfirmReset(true), - disabled: !isStopped || actions.busy, + disabled: aws || !isStopped || actions.busy, danger: true, }, { @@ -280,39 +321,33 @@ export default function ProjectHome({ projectId, active }: Props) { }} /> )} + {actions.stopGuard && ( + + )} + {forgetAws && ( + setForgetAws(null)} + onConfirm={() => { + const { discardData } = forgetAws; + setForgetAws(null); + void removeProject({ discardData, forgetAwsResources: true }); + }} + /> + )} {confirmRemove && ( setConfirmRemove(false)} - onConfirm={async () => { + onConfirm={({ discardData }) => { setConfirmRemove(false); - try { - const report = await remove(project.id); - if (!projectRemovalIsClean(report)) { - const verb = leftoverVerb(report); - if (report.retry_scheduled) { - useAppState.getState().pushToast({ - kind: "info", - message: `“${project.name}” was removed, but Triple-C could not confirm all its Docker resources were removed`, - detail: `Triple-C could not confirm ${describeLeftovers(report)} ${verb} removed. It will check again the next time it starts.`, - }); - } else { - // The pending-cleanup record itself failed to save — no - // retry will happen, so this must not promise one. - useAppState.getState().pushToast({ - kind: "error", - message: `“${project.name}” was removed, but Triple-C could not confirm its Docker resources were removed`, - detail: `Triple-C could not confirm ${describeLeftovers(report)} ${verb} removed, and could not record this for a retry. You may need to remove ${leftoverPronoun(report)} manually (\`docker rm\` / \`docker rmi\` / \`docker volume rm\`).`, - }); - } - } - } catch (e) { - useAppState.getState().pushToast({ - kind: "error", - message: `Could not remove “${project.name}”`, - detail: String(e), - }); - } + void removeProject({ discardData }); }} /> )} diff --git a/app/src/components/projects/home/config/AccessSection.tsx b/app/src/components/projects/home/config/AccessSection.tsx index 85c7f42..9676698 100644 --- a/app/src/components/projects/home/config/AccessSection.tsx +++ b/app/src/components/projects/home/config/AccessSection.tsx @@ -7,6 +7,7 @@ import Field, { ConfigGroup, inputClass } from "../../../ui/Field"; import CaCertPathInput from "../../../settings/CaCertPathInput"; import EnvVarsEditor from "../../EnvVarsEditor"; import PortMappingsEditor from "../../PortMappingsEditor"; +import { NOT_ON_AWS, isAwsProject } from "../../../../lib/awsWorkspace"; interface Props { project: Project; @@ -161,16 +162,22 @@ export default function AccessSection({ Port mappings -

- Expose container ports on the host so you can reach dev servers running inside - the sandbox. -

- save({ port_mappings: mappings })} - /> + {isAwsProject(project) ? ( +

{NOT_ON_AWS}

+ ) : ( + <> +

+ Expose container ports on the host so you can reach dev servers running inside + the sandbox. +

+ save({ port_mappings: mappings })} + /> + + )}
); diff --git a/app/src/components/projects/home/config/AwsConfig.test.tsx b/app/src/components/projects/home/config/AwsConfig.test.tsx new file mode 100644 index 0000000..f1f18ca --- /dev/null +++ b/app/src/components/projects/home/config/AwsConfig.test.tsx @@ -0,0 +1,132 @@ +import { describe, it, expect, vi, beforeEach } from "vitest"; +import { render, screen, fireEvent, waitFor, within } from "@testing-library/react"; +import RuntimeSection from "./RuntimeSection"; +import AccessSection from "./AccessSection"; +import WorkspaceSection from "./WorkspaceSection"; +import ModelSection from "./ModelSection"; +import HostSection from "./HostSection"; +import { awsProject, localProject } from "../../../../test/awsFixtures"; +import type { AuthBridgeStatus, Project } from "../../../../lib/types"; + +const OFF_BRIDGE: AuthBridgeStatus = { enabled: false, active_ports: [], conflicts: [] }; +const removeAwsResources = vi.fn(); + +vi.mock("../../../../lib/tauri-commands", () => ({ + getAuthBridgeStatus: vi.fn(async () => OFF_BRIDGE), + setAuthBridgeEnabled: vi.fn(), + inspectCaCertPath: vi.fn(async () => null), + removeAwsResources: (id: string, discard: boolean) => removeAwsResources(id, discard), +})); +vi.mock("@tauri-apps/api/event", () => ({ listen: vi.fn(async () => () => {}) })); +vi.mock("@tauri-apps/plugin-dialog", () => ({ open: vi.fn(async () => null) })); + +const save = vi.fn().mockResolvedValue(true); + +beforeEach(() => vi.clearAllMocks()); + +function toggle(name: string) { + return screen.getByRole("switch", { name }); +} + +describe("AWS project config", () => { + it("locks Docker access, VPN and the sandbox on AWS, saying why", () => { + render(); + for (const name of ["Allow container spawning", "VPN support", "Sandbox mode"]) { + expect(toggle(name)).toBeDisabled(); + expect(toggle(name)).toHaveAttribute("aria-checked", "false"); + } + expect(screen.getAllByText("Not available on AWS (Fargate)")).toHaveLength(2); + expect(screen.getByText(/Off on AWS for now/)).toBeInTheDocument(); + }); + + it("leaves those options alone for a local project", () => { + render(); + expect(toggle("VPN support")).not.toBeDisabled(); + expect(toggle("Sandbox mode")).toHaveAttribute("aria-checked", "true"); + expect(screen.queryByText("Not available on AWS (Fargate)")).toBeNull(); + }); + + it("replaces port mappings and folders on AWS", () => { + render(); + expect(screen.getByText("Not available on AWS (Fargate)")).toBeInTheDocument(); + expect(screen.queryByText(/Expose container ports/)).toBeNull(); + + render(); + expect(screen.queryByText("Folders")).toBeNull(); + expect(screen.getByText(/mounts no folders/)).toBeInTheDocument(); + }); + + it("disables the gateway backend and warns about local model URLs on AWS", () => { + render(); + const gateway = screen.getByRole("option", { name: /OpenAI Compatible/ }) as HTMLOptionElement; + expect(gateway.disabled).toBe(true); + expect(gateway.textContent).toMatch(/Not available on AWS/); + expect(screen.getByText(/must be reachable from the AWS task/)).toBeInTheDocument(); + }); +}); + +describe("HostSection", () => { + const renderHost = (p: Project = awsProject(), disabled = false) => + render(); + + it("saves a CPU change with a memory size valid for it", async () => { + renderHost(); // 1024 CPU / 4096 MiB + fireEvent.change(screen.getByLabelText("CPU"), { target: { value: "256" } }); + await waitFor(() => expect(save).toHaveBeenCalled()); + const aws = save.mock.calls[0][0].aws; + expect([aws.cpu, aws.memory_mib]).toEqual([256, 2048]); + }); + + it("saves a valid memory size and refuses an invalid one", async () => { + renderHost(); + const mem = screen.getByLabelText("Memory (MiB)"); + fireEvent.change(mem, { target: { value: "5000" } }); + fireEvent.blur(mem); + expect(screen.getByRole("alert")).toHaveTextContent(/5000 MiB of memory is not valid with 1024/); + expect(save).not.toHaveBeenCalled(); + + fireEvent.change(mem, { target: { value: "8192" } }); + fireEvent.blur(mem); + await waitFor(() => expect(save).toHaveBeenCalledTimes(1)); + expect(save.mock.calls[0][0].aws).toMatchObject({ cpu: 1024, memory_mib: 8192 }); + expect(screen.queryByRole("alert")).toBeNull(); + }); + + it("warns that Ephemeral storage loses the login and history", () => { + const p = awsProject(); + p.aws = { ...p.aws!, storage: "ephemeral" }; + renderHost(p); + expect(screen.getByText(/Claude login and history are lost when the workspace stops/)).toBeInTheDocument(); + expect(screen.getByText(/EFS .* coming later/)).toBeInTheDocument(); + }); + + it("saves repository edits on blur", async () => { + renderHost(); + fireEvent.click(screen.getByRole("button", { name: "+ Add repository" })); + const url = screen.getByLabelText("Repository 2 URL"); + fireEvent.change(url, { target: { value: "git@github.com:org/web.git" } }); + fireEvent.blur(url); + await waitFor(() => expect(save).toHaveBeenCalled()); + expect(save.mock.calls[0][0].aws.repos).toEqual([ + { url: "https://example.com/org/api.git", branch: null, folder: "api" }, + { url: "git@github.com:org/web.git", branch: null, folder: "web" }, + ]); + }); + + it("removes AWS resources after a confirm, and only then allows moving to this machine", async () => { + const p = awsProject(); + p.aws = { ...p.aws!, task_definition_arn: "arn:td:1" }; + removeAwsResources.mockResolvedValue({ ...p, aws: { ...p.aws, task_definition_arn: null } }); + renderHost(p); + const move = screen.getByRole("button", { name: "Run on this machine instead" }); + expect(move).toHaveAttribute("aria-disabled", "true"); + fireEvent.click(move); + expect(save).not.toHaveBeenCalled(); + + fireEvent.click(screen.getByRole("button", { name: "Remove AWS resources…" })); + const dialog = screen.getByRole("dialog"); + fireEvent.click(within(dialog).getByRole("checkbox")); + fireEvent.click(within(dialog).getByRole("button", { name: "Remove" })); + await waitFor(() => expect(removeAwsResources).toHaveBeenCalledWith(p.id, true)); + }); +}); diff --git a/app/src/components/projects/home/config/HostSection.tsx b/app/src/components/projects/home/config/HostSection.tsx new file mode 100644 index 0000000..3c1fa4f --- /dev/null +++ b/app/src/components/projects/home/config/HostSection.tsx @@ -0,0 +1,419 @@ +import { useEffect, useState } from "react"; +import type { AwsWorkspaceConfig, HostConnection, Project, RepoSource } from "../../../../lib/types"; +import * as commands from "../../../../lib/tauri-commands"; +import { useAppState } from "../../../../store/appState"; +import { + EPHEMERAL_WARNING, + FARGATE_CPUS, + defaultAwsWorkspace, + formatCpu, + formatMemory, + memoryError, + memoryOptions, + nearestMemory, +} from "../../../../lib/awsWorkspace"; +import Button from "../../../ui/Button"; +import Modal from "../../../ui/Modal"; +import Toggle from "../../../ui/Toggle"; +import SegmentedControl from "../../../ui/SegmentedControl"; +import Field, { ConfigGroup, SwitchRow, inputClass, selectClass } from "../../../ui/Field"; +import RepoListEditor from "../../RepoListEditor"; + +interface Props { + project: Project; + save: (patch: Partial) => Promise; + disabled: boolean; +} + +const DEFAULT_IDLE_MINUTES = 60; + +/** + * Where an AWS project runs and what its Fargate task looks like. Only shown + * for AWS projects; a local project's host is chosen when it is added. + */ +/** Stable, so the store selector does not return a new array each render. */ +const NO_HOSTS: HostConnection[] = []; + +export default function HostSection({ project, save, disabled }: Props) { + const aws: AwsWorkspaceConfig = project.aws ?? defaultAwsWorkspace(); + const hosts = useAppState((s) => s.appSettings?.hosts ?? NO_HOSTS); + const connection = hosts.find((h) => h.id === project.host_id); + + const [memory, setMemory] = useState(String(aws.memory_mib)); + const [memoryProblem, setMemoryProblem] = useState(null); + const [ephemeral, setEphemeral] = useState(String(aws.ephemeral_gib)); + const [ephemeralProblem, setEphemeralProblem] = useState(null); + const [idle, setIdle] = useState(String(aws.idle_stop_minutes ?? DEFAULT_IDLE_MINUTES)); + const [idleProblem, setIdleProblem] = useState(null); + const [confirmRemoveResources, setConfirmRemoveResources] = useState(false); + + useEffect(() => { + setMemory(String(aws.memory_mib)); + setEphemeral(String(aws.ephemeral_gib)); + setIdle(String(aws.idle_stop_minutes ?? DEFAULT_IDLE_MINUTES)); + }, [aws.memory_mib, aws.ephemeral_gib, aws.idle_stop_minutes]); + + const saveAws = (patch: Partial) => save({ aws: { ...aws, ...patch } }); + + const hasResources = !!(aws.task_arn || aws.access_point_id || aws.task_definition_arn); + + const commitMemory = () => { + const value = Number(memory); + const problem = memoryError(aws.cpu, value); + setMemoryProblem(problem); + if (problem || value === aws.memory_mib) return; + void saveAws({ memory_mib: value }); + }; + + const commitEphemeral = () => { + const value = Number(ephemeral); + const ok = Number.isInteger(value) && value >= 21 && value <= 200; + setEphemeralProblem(ok ? null : "Ephemeral storage must be 21 to 200 GiB"); + if (ok && value !== aws.ephemeral_gib) void saveAws({ ephemeral_gib: value }); + }; + + const commitIdle = () => { + const value = Number(idle); + const ok = Number.isInteger(value) && value >= 5 && value <= 1440; + setIdleProblem(ok ? null : "Idle stop must be 5 to 1440 minutes"); + if (ok && value !== aws.idle_stop_minutes) void saveAws({ idle_stop_minutes: value }); + }; + + return ( + +
+
Connection
+
+ {connection?.name ?? ( + + Removed — add it again in Settings → Hosts to start this project + + )} +
+
Region
+
{project.aws_placement?.region}
+
Environment
+
+ {project.aws_placement?.environment} +
+
+ +
+ + {(id) => ( + + )} + + { + const opts = memoryOptions(aws.cpu); + return `${formatMemory(opts[0])} to ${formatMemory(opts[opts.length - 1])} with ${formatCpu(aws.cpu)}.`; + })()} + > + {(id) => ( + <> + setMemory(e.target.value)} + onBlur={commitMemory} + onKeyDown={(e) => e.key === "Enter" && commitMemory()} + className={`w-32 ${inputClass}`} + /> + + {memoryOptions(aws.cpu).map((m) => ( + + + )} + +
+ + Architecture + + void saveAws({ arch })} + segments={[ + { value: "x86_64", label: "x86_64" }, + { value: "arm64", label: "ARM64 (Graviton)" }, + ]} + /> +
+
+ {memoryProblem && ( +

+ {memoryProblem} +

+ )} + +
+ + Storage + +
+ void saveAws({ storage })} + segments={[ + { value: "ephemeral", label: "Ephemeral", caution: true }, + { value: "hybrid", label: "Hybrid" }, + ]} + /> + + EFS (everything persists) — coming later + +
+ {aws.storage === "ephemeral" ? ( +

+ {EPHEMERAL_WARNING} Push your work to a remote before stopping. +

+ ) : ( +

+ The Claude login, history and SSH keys are kept on EFS between starts; everything + else, repositories included, starts fresh. +

+ )} +
+ + + {(id) => ( + setEphemeral(e.target.value)} + onBlur={commitEphemeral} + className={`w-24 ${inputClass}`} + /> + )} + + {ephemeralProblem && ( +

+ {ephemeralProblem} +

+ )} + + void saveAws({ spot })} + /> + } + /> + + + void saveAws({ idle_stop_minutes: on ? Number(idle) || DEFAULT_IDLE_MINUTES : null }) + } + /> + } + /> + {aws.idle_stop_minutes !== null && ( + + {(id) => ( + setIdle(e.target.value)} + onBlur={commitIdle} + className={`w-24 ${inputClass}`} + /> + )} + + )} + {idleProblem && ( +

+ {idleProblem} +

+ )} + + void saveAws({ wip_push_on_stop })} + /> + } + /> + +
+ + Repositories + +

+ Cloned into /workspace/<folder> when the + workspace starts, with the project’s SSH key or Git token. +

+ saveAws({ repos })} + /> +
+ +
+ + +
+ + {confirmRemoveResources && ( + setConfirmRemoveResources(false)} + /> + )} +
+ ); +} + +function RemoveAwsResourcesModal({ project, onClose }: { project: Project; onClose: () => void }) { + const [discardData, setDiscardData] = useState(false); + const [running, setRunning] = useState(false); + const [error, setError] = useState(null); + + const confirm = async () => { + if (running) return; + setRunning(true); + setError(null); + try { + const updated = await commands.removeAwsResources(project.id, discardData); + useAppState.getState().updateProjectInList(updated); + onClose(); + } catch (e) { + setError(String(e)); + } finally { + setRunning(false); + } + }; + + return ( + + + + + } + > +

+ Removes {project.name}’s + task definitions and secret from AWS (the secret after a 7-day recovery window) and + keeps the project, so it can run somewhere else. Its next start on AWS sets them up + again. +

+ + {error && ( +

+ {error} +

+ )} +
+ ); +} diff --git a/app/src/components/projects/home/config/ModelSection.tsx b/app/src/components/projects/home/config/ModelSection.tsx index e43e6a1..302afe5 100644 --- a/app/src/components/projects/home/config/ModelSection.tsx +++ b/app/src/components/projects/home/config/ModelSection.tsx @@ -16,6 +16,11 @@ import Field, { selectClass, } from "../../../ui/Field"; import Toggle from "../../../ui/Toggle"; +import { NOT_ON_AWS, isAwsProject } from "../../../../lib/awsWorkspace"; + +/** P6: an AWS workspace can reach a local model only over the network. */ +const LOCAL_MODEL_ON_AWS = + "This project runs on AWS: the URL must be reachable from the AWS task, so host.docker.internal and this machine's LAN addresses will not work."; /** Bedrock fields held in the OS keychain, never serialized back to us. */ const BEDROCK_SECRET_KEYS = [ @@ -181,6 +186,8 @@ export default function ModelSection({ project, save, disabled }: Props) { // that predates it, should still pick the shared token up. const useSharedToken = project.use_shared_auth_token !== false; + const aws = isAwsProject(project); + const handleBackendChange = (mode: Backend) => { const patch: Partial = { backend: mode }; if (mode === "bedrock" && !project.bedrock_config) @@ -212,10 +219,25 @@ export default function ModelSection({ project, save, disabled }: Props) { - + )} + {aws && project.backend === "open_ai_compatible" && ( +

+ OpenAI Compatible (gateway): {NOT_ON_AWS}. Choose another backend. +

+ )} + {aws && (project.backend === "ollama" || project.backend === "llama_cpp") && ( +

+ {LOCAL_MODEL_ON_AWS} +

+ )} {/* Only Anthropic reads CLAUDE_CODE_OAUTH_TOKEN; the other backends authenticate through their own credentials entirely. */} diff --git a/app/src/components/projects/home/config/RuntimeSection.tsx b/app/src/components/projects/home/config/RuntimeSection.tsx index 7fe7a2e..099564b 100644 --- a/app/src/components/projects/home/config/RuntimeSection.tsx +++ b/app/src/components/projects/home/config/RuntimeSection.tsx @@ -5,6 +5,7 @@ import PermissionModeControl, { permissionModePatch } from "../../PermissionMode import ClaudeInstructionsEditor from "../../ClaudeInstructionsEditor"; import ClaudeCodeSettingsEditor from "../../ClaudeCodeSettingsEditor"; import AuthBridgeRow from "./AuthBridgeRow"; +import { NOT_ON_AWS, SANDBOX_OFF_ON_AWS, isAwsProject } from "../../../../lib/awsWorkspace"; interface Props { project: Project; @@ -19,6 +20,7 @@ export default function RuntimeSection({ disabled, disabledReason, }: Props) { + const aws = isAwsProject(project); return ( <> save({ sandbox_mode_enabled: v })} /> } @@ -47,12 +53,16 @@ export default function RuntimeSection({ save({ allow_docker_access: v })} /> } @@ -60,12 +70,12 @@ export default function RuntimeSection({ save({ vpn_support_enabled: v })} /> } diff --git a/app/src/components/projects/home/config/WorkspaceSection.tsx b/app/src/components/projects/home/config/WorkspaceSection.tsx index cc6790c..9390bfb 100644 --- a/app/src/components/projects/home/config/WorkspaceSection.tsx +++ b/app/src/components/projects/home/config/WorkspaceSection.tsx @@ -3,6 +3,7 @@ import { open } from "@tauri-apps/plugin-dialog"; import type { Project, ProjectPath } from "../../../../lib/types"; import Button from "../../../ui/Button"; import Field, { ConfigGroup, inputClass, monoInputClass } from "../../../ui/Field"; +import { isAwsProject } from "../../../../lib/awsWorkspace"; interface Props { project: Project; @@ -73,7 +74,11 @@ export default function WorkspaceSection({ project, save, disabled }: Props) { return ( -
- - Folders - -

- Each host folder is mounted at /workspace/<name>{" "} - inside the container. + {isAwsProject(project) ? ( +

+ This project runs on AWS, so it mounts no folders from this machine: its + repositories are cloned into /workspace. Edit them + under Host below.

+ ) : ( +
+ + Folders + +

+ Each host folder is mounted at /workspace/<name>{" "} + inside the container. +

-
- {paths.map((pp, i) => ( -
- { - const updated = [...paths]; - updated[i] = { ...updated[i], host_path: e.target.value }; - setPaths(updated); - }} - onBlur={() => saveIfComplete()} - placeholder="/path/to/folder" - disabled={disabled} - className={`flex-1 min-w-0 ${inputClass}`} - /> -
- - - /workspace/ - +
+ {paths.map((pp, i) => ( +
{ const updated = [...paths]; - updated[i] = { ...updated[i], mount_name: e.target.value }; + updated[i] = { ...updated[i], host_path: e.target.value }; setPaths(updated); }} onBlur={() => saveIfComplete()} - placeholder="name" + placeholder="/path/to/folder" disabled={disabled} - className={`w-40 ${monoInputClass}`} + className={`flex-1 min-w-0 ${inputClass}`} /> - {paths.length > 1 && ( +
- )} + + /workspace/ + + { + const updated = [...paths]; + updated[i] = { ...updated[i], mount_name: e.target.value }; + setPaths(updated); + }} + onBlur={() => saveIfComplete()} + placeholder="name" + disabled={disabled} + className={`w-40 ${monoInputClass}`} + /> + {paths.length > 1 && ( + + )} +
-
- ))} -
+ ))} +
- -
+ +
+ )} ); } diff --git a/app/src/components/ui/Button.tsx b/app/src/components/ui/Button.tsx index be41f79..0f10fb4 100644 --- a/app/src/components/ui/Button.tsx +++ b/app/src/components/ui/Button.tsx @@ -1,4 +1,4 @@ -import type { ButtonHTMLAttributes, ReactNode } from "react"; +import type { ButtonHTMLAttributes, ReactNode, Ref } from "react"; import { useUnavailable } from "./unavailable"; export type ButtonVariant = "primary" | "secondary" | "danger" | "ghost"; @@ -19,6 +19,8 @@ interface Props extends ButtonHTMLAttributes { unavailable?: boolean; /** Why the button cannot be used. Required for `unavailable` to say anything. */ unavailableReason?: string; + /** React 19 passes `ref` as a prop; it lands on the `