Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions contracts/hided-ws.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,12 @@
}
},
"serverFrame": {
"description": "snapshot/delta carry the core state; error answers a malformed client event; directory_list answers a `file_list`, and path_refused answers any event whose path failed its boundary - the $HOME line for `create_workspace`, the checkout-root line for `file_list`, `file_open`, `reveal_path`, `file_save`, `file_create`, `dir_create`, `path_rename`, `path_move`, `path_trash` and `file_bytes` (see directoryList and pathRefused). A `file_list`, `file_open`, `reveal_path`, `file_save`, `file_create`, `dir_create`, `path_rename`, `path_move` or `path_trash` that names an SSH device in `device_id` never meets this machine's checkout roots: the core accepts it only for the checkout in front on that device and the device's helper confines every path to that checkout's opened root. file_bytes_error answers a `file_bytes` read the daemon could not serve as bytes (see fileBytes). directory_unavailable answers a `file_list` for a checkout on an SSH device that its helper could not list (see directoryUnavailable). directory_changed announces that a watched folder changed, so the client re-reads that one folder (see directoryChanged). attachment_refused answers an `attachment_stage` or `attachment_commit` that could not be staged (see attachments). file_index_result answers a `file_index` query with the ranked checkout paths (see fileIndex). project_target answers a `project_target` probe (see projectTarget and projectTargetResult). daemon is the first frame after a valid handshake and describes the daemon itself (see daemonInfo). A `file_bytes` read that succeeds is answered with one or more binary frames on the same socket, not a text frame (see fileBytes).",
"description": "snapshot/delta carry the core state; error answers a malformed client event; directory_list answers a `file_list`, and path_refused answers any event whose path failed its boundary - the $HOME line for `create_workspace` and `clone_repository`, the checkout-root line for `file_list`, `file_open`, `reveal_path`, `file_save`, `file_create`, `dir_create`, `path_rename`, `path_move`, `path_trash` and `file_bytes` (see directoryList and pathRefused). A `file_list`, `file_open`, `reveal_path`, `file_save`, `file_create`, `dir_create`, `path_rename`, `path_move` or `path_trash` that names an SSH device in `device_id` never meets this machine's checkout roots: the core accepts it only for the checkout in front on that device and the device's helper confines every path to that checkout's opened root. file_bytes_error answers a `file_bytes` read the daemon could not serve as bytes (see fileBytes). directory_unavailable answers a `file_list` for a checkout on an SSH device that its helper could not list (see directoryUnavailable). directory_changed announces that a watched folder changed, so the client re-reads that one folder (see directoryChanged). attachment_refused answers an `attachment_stage` or `attachment_commit` that could not be staged (see attachments). file_index_result answers a `file_index` query with the ranked checkout paths (see fileIndex). project_target answers a `project_target` probe (see projectTarget and projectTargetResult). clone_target answers a `clone_target` question about where a clone would land (see cloneTarget). daemon is the first frame after a valid handshake and describes the daemon itself (see daemonInfo). A `file_bytes` read that succeeds is answered with one or more binary frames on the same socket, not a text frame (see fileBytes).",
"type": "object",
"additionalProperties": false,
"required": ["type", "payload"],
"properties": {
"type": { "type": "string", "enum": ["daemon", "snapshot", "delta", "error", "directory_list", "directory_unavailable", "path_refused", "project_target", "file_bytes_error", "directory_changed", "file_index_result", "attachment_refused", "open_external_result"] },
"type": { "type": "string", "enum": ["daemon", "snapshot", "delta", "error", "directory_list", "directory_unavailable", "path_refused", "project_target", "file_bytes_error", "directory_changed", "file_index_result", "attachment_refused", "open_external_result", "clone_target"] },
"payload": { "type": "object" },
"message": { "type": "string" }
}
Expand Down Expand Up @@ -241,6 +241,7 @@
"type": "string",
"enum": [
"create_workspace",
"clone_repository",
"file_list",
"file_open",
"reveal_path",
Expand All @@ -262,6 +263,18 @@
"reason": { "$ref": "#/$defs/pathRefusalReason" }
}
},
"cloneTarget": {
"description": "Add a project's Clone from URL asks where a clone would land with a `clone_target` event {parent, name} while the operator types, and hided answers this frame without forwarding the event: parent and name as sent, path the canonical folder the clone would create when it may, and reason null or the `$HOME` line's refusal, `already_exists` when anything (a folder, even an empty one or a `.git`-only leftover, a file, a dangling symlink) already holds the name. parent may be home itself or `~`; name is one plain folder name. The `clone_repository` event {url, parent, name} passes the same check, reaches the core with parent rewritten to its canonical spelling, or is answered with path_refused naming `parent/name`. The core then refuses a URL it cannot clone or a name the URL does not give, and reports the clone in the snapshot's repository_clone.",
"type": "object",
"additionalProperties": false,
"required": ["parent", "name", "path", "reason"],
"properties": {
"parent": { "type": "string" },
"name": { "type": "string" },
"path": { "type": ["string", "null"] },
"reason": { "anyOf": [{ "$ref": "#/$defs/pathRefusalReason" }, { "type": "null" }] }
}
},
"openExternal": {
"description": "A browser WebSocket client open_external event is always answered with open_external_result {path, ok:false, reason:\"untrusted_client\"}, even with a valid token and loopback Origin: localhost may be forwarded from another machine. The bare S3 browser downloads oversized files through file_bytes. The bounded host opener remains implemented for a future transport that can establish local ownership (macOS open, Windows ShellExecuteW default association, Linux xdg-open, or validated absolute HIDE_OPEN_COMMAND); no such transport is present in S3. Windows never passes the pathname through cmd.",
"type": "object",
Expand Down
86 changes: 86 additions & 0 deletions desktop/e2e/add-project.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Add a project in the desktop app: the dialog's Browse folder asks the main
// process for macOS's folder picker, which this spec replaces with a queue of
// answers, so a pick, a cancel and a refused folder run with no native sheet.
// Clone from URL clones a local bare repository through the same dialog.

import { expect, test, type ElectronApplication, type Page } from "@playwright/test";
import { execFileSync } from "node:child_process";
Expand Down Expand Up @@ -208,6 +209,91 @@ test("Create new project makes a Git repository and adds it; a name already take
}
});

test("Clone from URL clones a repository into a folder under home and adds it as a project", async () => {
const herdr = await startHerdr();
const run = isolate(herdr, "clone-project");
let app: ElectronApplication | undefined;
try {
const home = run.env.HOME!;
// A local bare repository stands in for a remote one; its folder name is `origin`.
const work = path.join(run.root, "work");
fs.mkdirSync(work, { recursive: true });
const git = (cwd: string, args: string[]) =>
execFileSync("git", args, { cwd, env: { ...process.env, GIT_AUTHOR_NAME: "t", GIT_AUTHOR_EMAIL: "t@example.com", GIT_COMMITTER_NAME: "t", GIT_COMMITTER_EMAIL: "t@example.com" } });
git(work, ["init", "-q", "-b", "main"]);
fs.writeFileSync(path.join(work, "README.md"), "fixture\n");
git(work, ["add", "."]);
git(work, ["commit", "-q", "-m", "fixture"]);
const bare = path.join(run.root, "origin.git");
git(run.root, ["clone", "-q", "--bare", work, bare]);
const url = `file://${fs.realpathSync(bare)}`;
// `~/origin` is taken, so the default parent (home: nothing is registered yet) is refused.
fs.mkdirSync(path.join(home, "origin"));
const projects = fs.realpathSync(path.join(home, "projects"));

const launched = await launch(run.env, { switches: ["--disable-backgrounding-occluded-windows"] });
app = launched.app;
const page = launched.page;
await expect(page.locator("[data-main-screen], [data-workspace-screen]")).toBeVisible({ timeout: 30_000 });
await page.locator('[data-sidebar-mode="projects"]').click();
const dialog = page.locator("[data-add-project]");
await page.locator("[data-sidebar-new-workspace]").click();
await expect(dialog.locator("[data-add-project-other-ways]")).toContainText("Other ways to add");
await dialog.locator('[data-add-project-way="clone"]').click();

// The sub-view: Back, its own title, the URL field holding the keyboard, and home as the parent.
await expect(dialog.getByRole("heading", { name: "Clone from URL" })).toBeVisible();
await expect(dialog.locator("[data-add-project-back]")).toBeVisible();
const field = dialog.locator("[data-clone-url]");
await expect(field).toBeFocused();
await expect(dialog.locator("[data-clone-parent]")).toHaveValue("~");
const submit = dialog.locator("[data-clone-submit]");
await expect(submit).toBeDisabled();

// What Git cannot clone is said at once, and Clone stays off.
await field.fill("not a url");
await expect(dialog.locator("[data-clone-url-reason]")).toBeVisible();
await expect(submit).toBeDisabled();

// The folder the URL names is shown; hided finds it taken under home.
await field.fill(url);
await expect(dialog.locator("[data-clone-target-reason]")).toHaveAttribute("data-clone-target-reason", "already_exists");
await expect(submit).toBeDisabled();

// Another parent from the folder picker frees it.
await stubPicker(app, [{ canceled: false, filePaths: [projects] }]);
await dialog.locator("[data-clone-browse]").click();
await expect(dialog.locator("[data-clone-parent]")).toHaveValue(projects);
await expect(dialog.locator("[data-clone-target]")).toHaveAttribute("data-clone-target", path.join(projects, "origin"));
await expect(submit).toBeEnabled();
await captureWindow(app, page, "clone-from-url-ready");

// Clone: the repository lands under the parent, and the dialog closes when the project appears.
await submit.click();
await expect(dialog).toHaveCount(0, { timeout: 30_000 });
await expect(page.locator("[data-project-list]")).toContainText("origin", { timeout: 20_000 });
expect(fs.readFileSync(path.join(projects, "origin", "README.md"), "utf8")).toBe("fixture\n");
expect(fs.readdirSync(projects)).toEqual(["origin"]);

// Opened again, the parent defaults beside the project just added, where the folder is now taken.
await page.keyboard.press("Meta+Shift+KeyN");
await dialog.locator('[data-add-project-way="clone"]').click();
await expect(dialog.locator("[data-clone-parent]")).toHaveValue(path.join(projects));
await dialog.locator("[data-clone-url]").fill(url);
await expect(dialog.locator("[data-clone-target-reason]")).toHaveAttribute("data-clone-target-reason", "already_exists");
await expect(dialog.locator("[data-clone-submit]")).toBeDisabled();
// Back returns to the first view.
await dialog.locator("[data-add-project-back]").click();
await expect(dialog.getByRole("heading", { name: "Add a project" })).toBeVisible();
await page.keyboard.press("Escape");
await expect(dialog).toHaveCount(0);
} finally {
await app?.close();
run.cleanup();
herdr.stop();
}
});

/** A capture of the candidate window by its own id, when a run directory was named. */
async function captureWindow(app: ElectronApplication, page: Page, name: string): Promise<void> {
const dir = process.env.HIDE_E2E_SCREENSHOT_DIR;
Expand Down
7 changes: 7 additions & 0 deletions docs/ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,11 @@ Each item is one existing event: `focus_checkout`, `create_tab` (a device's `rem
Pin and Remove are offered on a row Herdr shows without a registration too (PRD sidebar-context-menus D-14): `workspace_pin_set` with `pinned: true` on such a row registers it with the id, label, root and device the row already carries and pins it in that event, with no filesystem read under the lock, and the next catalog rebuild adopts it as the same row; a device's row qualifies only once its helper grouped it under its root. `remove_workspace` on such a row closes its panes through the same close worker and retires nothing, so the row leaves with Herdr's workspace, and every row carries the removal gate's counts.
An agent row carries the session id Herdr recorded (`session_id`, absent when none), which Copy session id reads.
The dialogs (`web/src/WorkspaceDialogs.tsx`) send `create_worktree`, `set_checkout_purpose` and `remove_worktree` and read only the receipt for their own request (`task_operation` by kind, id and target; `worktree_removal` by checkout and id), so another page's or an older request's answer is never shown as theirs.
Add a project's Clone from URL is one core job in one slot, `repository_clone` (`herdr-core/src/runtime/clone.rs`): the core parses the URL again (`hide_host::clone::CloneSource`: https, ssh, the scp form and `file://`; the name has to be the one the URL gives), refuses a second clone while one runs (`repository.clone_busy`), and lets the same URL and folder sent again join the running one, so a double submit is one clone and one registration.
A worker thread owns the run and takes the lock only to write progress or the result; `hide_host::clone::clone_repository` runs `git clone --progress` with `GIT_TERMINAL_PROMPT=0`, `ssh -o BatchMode=yes` and `GIT_ALLOW_PROTOCOL=https:ssh:file` in its own process group, into a hidden `.<name>.hide-clone-<pid>` staging folder beside the target that only a finished clone is renamed from (refusing to replace anything that appeared meanwhile).
A cancel (`cancel_repository_clone`), the runtime going away, or `STALL_LIMIT` (120 s) without a line from Git stops the whole group and removes the staging folder, so a cancelled, stalled or failed clone leaves nothing under the target's name; a daemon killed mid-clone can leave its hidden staging folder behind, since nothing runs to remove it.
Failures are read from Git's C-locale stderr into one plain sentence (authentication, unknown host key, not found, unreachable host, or Git's last `fatal:` line with credentials removed); the URL is kept only in the job, never in the snapshot or a log line, which carry the host.
A finished clone goes through the same local `create_workspace` event Browse folder sends, so it is registered, refused or deduplicated exactly like a picked folder.
A created worktree's pane is focused with one `focus_pane` once the snapshot lists it, because only a focus request is tracked until Herdr confirms it; a late focus event for the pane left behind cannot undo the move.
A dialog or sheet returns keyboard focus to a terminal through `focusTerminal` on the core's focused pane (`restoreFocus`), never by re-focusing the textarea that held it, which would be reported as the operator moving there.

Expand Down Expand Up @@ -555,6 +560,8 @@ Create new project names a folder that does not exist yet, so a `create_workspac
The same check answers a client's `project_target` probe as a `project_target` frame, which the dialog shows before anything is sent; the probe is never forwarded and changes nothing on disk.
The core's creation worker, off `Mutex<Runtime>`, makes the folder at the literal path hided checked and runs `git init` in it (`workspace::create_project_folder`) before the registration canonicalizes it, judging the target again without following a symlink at it because the check and the make are not one step; a failure after the folder was made keeps it and says so, and a retry continues into it.
A `new_folder` create that names an SSH device is refused by the core.
A `clone_repository` {url, parent, name} passes the same line through `Boundary::resolve_clone_target`: `parent` may be home itself or a folder under it, `name` has to be one plain folder name, and nothing (a folder, a file, a dangling symlink) may already hold `parent/name`, which is refused as `already_exists` (unlike Create new project, not even an empty or `.git`-only folder is accepted, since a clone never writes into a folder it did not make); the event reaches the core with `parent` rewritten to its canonical spelling, or is answered with `path_refused` naming `parent/name`.
Clone from URL asks the same question while the operator types with a `clone_target` {parent, name}, which hided answers with a `clone_target` frame (`path` when the clone may land there, `reason` otherwise) and never forwards or logs.
The boundary root is read from `HOME` at boot and is not configurable; widening it is a security-policy decision the web Settings does not take, and registering a folder outside home stays with the existing CLI path.
Both frames and the reason codes are in `contracts/hided-ws.schema.json`.

Expand Down
4 changes: 4 additions & 0 deletions docs/UI_BEHAVIOR.md
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,10 @@ The chosen folder is registered with one `create_workspace`; the dialog closes w
A refusal stays inside the dialog as an alert naming the folder, and the dialog stays open for another pick: `already_registered` from the shell's own registrations, before anything is sent, and `outside_home`, `home_root`, `not_found`, `not_a_directory` or `invalid_path` from hided's `$HOME` line, or the core's own error.
A device's folders are not this Mac's to browse, so on a device the dialog shows a `~/` path field instead, sent to that device's helper through the same event, with its refusal shown the same way.
On this Mac an `Other ways to add` group sits under Browse folder, one row per way, each opening its own view of the same dialog with a `Back` that returns to the first view and puts the keyboard on the row it came from.
`Clone from URL` (web owner: `web/src/CloneFromUrl.tsx`) shows a `Git URL` field that holds the keyboard, and a `Parent folder` field with a button that opens the same native folder picker; the parent starts beside the most recently added local project, else at home (`~`).
The folder the URL names is shown as `Clones into a new folder <name>`, and hided is asked whether it is free under that parent, so `Clone` is enabled only for an https, ssh (`git@host:path`, `ssh://`) or `file://` URL, a parent inside home, and a name nothing holds there yet (`already_exists` covers even an empty folder, since a clone never writes into a folder it did not make); each refusal is shown inline under its field.
While the clone runs the dialog shows Git's stage and percent with a progress bar and a `Cancel` button, and the fields and `Back` wait; closing the dialog leaves the clone running, and opening it again shows it.
A finished clone is registered like a picked folder and the dialog closes when the project appears, or says it could not be added and that the repository is on disk for Browse folder; a failure (authentication, a stalled transfer, a missing repository) stays inline in plain words with `Clone` enabled again, and a cancel says nothing was kept.
`Create new project` (web owner: `web/src/CreateProjectView.tsx`) shows a focused `Name` field and a location row naming the folder it goes in (`Git repository in ~/…`) with the full path under it, which follows the name as it is typed.
The folder starts as the parent of the most recently added project on this Mac, else home; the location row opens the native folder picker to choose another.
hided answers a `project_target` probe for every name and folder on the same `$HOME` line the create is checked on, so a name that is not one folder, a folder outside home, something already standing at the path (`already_exists`) or a project already added there is said inline and `Create project` stays disabled until the path is free.
Expand Down
Loading
Loading