Skip to content

Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins

feat(desktop): default the project name to the primary folder

vastsa9108447064be
diff --git a/apps/desktop/src/components/ProjectCreateDialog.tsx b/apps/desktop/src/components/ProjectCreateDialog.tsx
index a4b552aca..c746b4201 100644
--- a/apps/desktop/src/components/ProjectCreateDialog.tsx
+++ b/apps/desktop/src/components/ProjectCreateDialog.tsx
@@ -4,6 +4,11 @@ import { useTranslation } from "react-i18next";
import { MAX_PROJECT_NAME_CHARS } from "../lib/sidebar-preferences";
import { api } from "../lib/api";
import { parseGitCloneUrl } from "../lib/git-clone-url";
+import {
+ defaultProjectName,
+ folderNameFromPath,
+ resolveProjectName,
+} from "../lib/project-name";
import { useAppStore } from "../stores/app-store";
import { Button, TooltipButton } from "./ui";
import {
@@ -23,10 +28,6 @@ function pathParts(path: string) {
return path.split(/[\\/]/).filter(Boolean);
}
-function folderName(path: string) {
- return pathParts(path).at(-1) ?? path;
-}
-
function folderParent(path: string) {
const parts = pathParts(path);
return parts.length > 1 ? `…/${parts.slice(-2, -1)[0]}` : path;
@@ -55,9 +56,15 @@ export function ProjectCreateDialog() {
const inputRef = useRef<HTMLInputElement | null>(null);
const dialogRef = useRef<HTMLDivElement | null>(null);
const busyRef = useRef(false);
- // The repository name seeds the project name until the user types their own.
+ // The picked source seeds the project name until the user types their own.
const nameTouchedRef = useRef(false);
const cloneTarget = parseGitCloneUrl(gitUrl);
+ const defaultName = defaultProjectName({
+ source,
+ folders,
+ repositoryName: cloneTarget?.name,
+ });
+ const projectName = resolveProjectName(name, defaultName);
useEffect(() => {
if (!open) return;
@@ -104,11 +111,12 @@ export function ProjectCreateDialog() {
};
}, [close, open]);
- // A pasted repository URL names the project without stealing a typed name.
+ // The first folder or the repository name fills the field until the user
+ // types their own name; an emptied field still falls back to it on submit.
useEffect(() => {
- if (source !== "git" || nameTouchedRef.current) return;
- setName(cloneTarget?.name ?? "");
- }, [cloneTarget?.name, source]);
+ if (nameTouchedRef.current) return;
+ setName(defaultName);
+ }, [defaultName]);
if (!open) return null;
@@ -144,8 +152,8 @@ export function ProjectCreateDialog() {
};
const submit = async () => {
- const trimmedName = name.trim();
- if (!trimmedName || busyRef.current) return;
+ const projectName = resolveProjectName(name, defaultName);
+ if (!projectName || busyRef.current) return;
if (source === "git") {
if (!cloneTarget || !cloneParent) return;
} else if (folders.length === 0) {
@@ -156,13 +164,13 @@ export function ProjectCreateDialog() {
try {
if (source === "git" && cloneTarget) {
await createProjectFromGit({
- name: trimmedName,
+ name: projectName,
url: cloneTarget.url,
parentPath: cloneParent,
});
} else {
await createProject({
- name: trimmedName,
+ name: projectName,
folders,
primaryPath: folders[0],
});
@@ -329,7 +337,7 @@ export function ProjectCreateDialog() {
<IconFolder size={17} />
</span>
<span className="project-create-folder-copy" title={path}>
- <span className="project-create-folder-name">{folderName(path)}</span>
+ <span className="project-create-folder-name">{folderNameFromPath(path)}</span>
<span className="project-create-folder-path">{folderParent(path)}</span>
</span>
{index === 0 ? (
@@ -342,7 +350,7 @@ export function ProjectCreateDialog() {
type="button"
className="project-create-folder-remove"
tooltip={t("project.createRemoveFolder")}
- ariaLabel={`${t("project.createRemoveFolder")}: ${folderName(path)}`}
+ ariaLabel={`${t("project.createRemoveFolder")}: ${folderNameFromPath(path)}`}
disabled={busy}
onClick={() => setFolders((current) => current.filter((item) => item !== path))}
>
@@ -414,7 +422,7 @@ export function ProjectCreateDialog() {
<span className="project-create-dialog-location-copy">
<span className="project-create-dialog-location-title">
{cloneParent
- ? folderName(cloneParent)
+ ? folderNameFromPath(cloneParent)
: t("project.createChooseLocation")}
</span>
<span className="project-create-dialog-location-path">
@@ -443,8 +451,8 @@ export function ProjectCreateDialog() {
variant="primary"
disabled={
source === "git"
- ? !name.trim() || !cloneTarget || !cloneParent || busy
- : !name.trim() || folders.length === 0 || busy
+ ? !projectName || !cloneTarget || !cloneParent || busy
+ : !projectName || folders.length === 0 || busy
}
>
{busy
diff --git a/apps/desktop/src/lib/project-name.ts b/apps/desktop/src/lib/project-name.ts
new file mode 100644
index 000000000..6eeb97a59
--- /dev/null
+++ b/apps/desktop/src/lib/project-name.ts
@@ -0,0 +1,52 @@
+import { MAX_PROJECT_NAME_CHARS } from "./sidebar-preferences";
+
+/**
+ * Default display names for the Create project dialog. A local pick is named
+ * after its first (primary) folder and a git source after its repository, so a
+ * user never has to type a title before Create becomes available. A typed name
+ * always wins, and every derived name is cut to the length the name field and
+ * the persisted sidebar preference accept.
+ */
+
+/** The last segment of a local path, in either slash direction. */
+export function folderNameFromPath(path: string): string {
+ const parts = path.split(/[\\/]/).filter(Boolean);
+ return parts.at(-1) ?? path.trim();
+}
+
+/**
+ * Cut a derived name to the character budget the name field enforces. The
+ * field counts UTF-16 units in `maxLength` and in its own counter, so the cut
+ * happens there too, and a trailing high surrogate is dropped rather than left
+ * as half a character. Both downstream checks (the sidebar preference and the
+ * host's `chars().count()`) count code points, which such a cut still satisfies.
+ */
+export function clampProjectName(name: string): string {
+ const trimmed = name.trim();
+ if (trimmed.length <= MAX_PROJECT_NAME_CHARS) return trimmed;
+ const cut = trimmed.slice(0, MAX_PROJECT_NAME_CHARS);
+ const last = cut.charCodeAt(cut.length - 1);
+ const splitPair = last >= 0xd800 && last <= 0xdbff;
+ return splitPair ? cut.slice(0, -1) : cut;
+}
+
+/**
+ * The name the dialog offers for the current source: the first selected
+ * folder, or the parsed repository name for a git checkout.
+ */
+export function defaultProjectName(input: {
+ source: "local" | "git";
+ folders: readonly string[];
+ repositoryName?: string | null;
+}): string {
+ const raw =
+ input.source === "git"
+ ? (input.repositoryName ?? "")
+ : folderNameFromPath(input.folders[0] ?? "");
+ return clampProjectName(raw);
+}
+
+/** A typed name wins; an empty field falls back to the derived default. */
+export function resolveProjectName(typed: string, fallback: string): string {
+ return typed.trim() || fallback.trim();
+}
diff --git a/apps/desktop/test/project-create-dialog.test.mjs b/apps/desktop/test/project-create-dialog.test.mjs
index 1aedcbf67..9e2a18916 100644
--- a/apps/desktop/test/project-create-dialog.test.mjs
+++ b/apps/desktop/test/project-create-dialog.test.mjs
@@ -29,7 +29,11 @@ test("create project dialog supports named multi-folder setup", () => {
assert.match(dialog, /project-create-dialog-content/);
assert.match(dialog, /project-create-dialog-section/);
assert.match(dialog, /project-create-dialog-field-label/);
- assert.match(dialog, /!name\.trim\(\) \|\| folders\.length === 0 \|\| busy/);
+ // The name field is optional: the dialog derives a default from the source.
+ assert.match(dialog, /defaultProjectName\(\{/);
+ assert.match(dialog, /resolveProjectName\(name, defaultName\)/);
+ assert.match(dialog, /setName\(defaultName\)/);
+ assert.match(dialog, /: !projectName \|\| folders\.length === 0 \|\| busy/);
assert.match(dialog, /querySelectorAll<HTMLElement>\(/);
});
@@ -47,7 +51,7 @@ test("create project dialog can create the project from a git checkout", () => {
assert.match(dialog, /createProjectFromGit\(\{/);
assert.match(dialog, /url: cloneTarget\.url/);
assert.match(dialog, /parentPath: cloneParent/);
- assert.match(dialog, /!name\.trim\(\) \|\| !cloneTarget \|\| !cloneParent \|\| busy/);
+ assert.match(dialog, /!projectName \|\| !cloneTarget \|\| !cloneParent \|\| busy/);
assert.match(dialog, /project\.cloning/);
assert.match(store, /createProjectFromGit: async \(\{ name, url, parentPath \}\)/);
assert.match(store, /api\.cloneProjectInto\(url, parentPath\)/);
diff --git a/apps/desktop/test/project-name.test.mjs b/apps/desktop/test/project-name.test.mjs
new file mode 100644
index 000000000..2e2191705
--- /dev/null
+++ b/apps/desktop/test/project-name.test.mjs
@@ -0,0 +1,64 @@
+import assert from "node:assert/strict";
+import { register } from "node:module";
+import test from "node:test";
+
+register(new URL("./helpers/ts-import-hooks.mjs", import.meta.url));
+const {
+ clampProjectName,
+ defaultProjectName,
+ folderNameFromPath,
+ resolveProjectName,
+} = await import("../src/lib/project-name.ts");
+
+test("folderNameFromPath reads the last segment in either slash direction", () => {
+ assert.equal(folderNameFromPath("/Users/dev/work/api-server"), "api-server");
+ assert.equal(folderNameFromPath("/Users/dev/work/api-server/"), "api-server");
+ assert.equal(folderNameFromPath("C:\\work\\api-server"), "api-server");
+ assert.equal(folderNameFromPath("api-server"), "api-server");
+});
+
+test("defaultProjectName names a local pick after its first folder", () => {
+ assert.equal(
+ defaultProjectName({
+ source: "local",
+ folders: ["/Users/dev/work/api-server", "/Users/dev/work/web"],
+ }),
+ "api-server",
+ );
+ assert.equal(defaultProjectName({ source: "local", folders: [] }), "");
+});
+
+test("defaultProjectName names a git source after its repository", () => {
+ assert.equal(
+ defaultProjectName({ source: "git", folders: [], repositoryName: "PI-Desktop" }),
+ "PI-Desktop",
+ );
+ assert.equal(
+ defaultProjectName({ source: "git", folders: ["/Users/dev/work/api-server"] }),
+ "",
+ );
+});
+
+test("derived names stay inside the name field budget", () => {
+ const long = "a".repeat(120);
+ assert.equal(clampProjectName(long).length, 80);
+ assert.equal(
+ defaultProjectName({ source: "local", folders: [`/Users/dev/work/${long}`] }).length,
+ 80,
+ );
+ assert.equal(clampProjectName(" spaced "), "spaced");
+ // The name field counts UTF-16 units, so a derived name has to fit that
+ // budget too and never end on half a surrogate pair.
+ const emoji = clampProjectName("😀".repeat(100));
+ assert.equal(emoji.length, 80);
+ assert.equal(Array.from(emoji).length, 40);
+ assert.equal(clampProjectName(`${"a".repeat(79)}😀`), "a".repeat(79));
+});
+
+test("resolveProjectName keeps a typed name and falls back when the field is empty", () => {
+ assert.equal(resolveProjectName("My project", "api-server"), "My project");
+ assert.equal(resolveProjectName(" api-server ", "ignored"), "api-server");
+ assert.equal(resolveProjectName("", "api-server"), "api-server");
+ assert.equal(resolveProjectName(" ", "api-server"), "api-server");
+ assert.equal(resolveProjectName("", ""), "");
+});
diff --git a/docs/spec/04-ux/08-component-spec.md b/docs/spec/04-ux/08-component-spec.md
index 0a0124d25..1100fa159 100644
--- a/docs/spec/04-ux/08-component-spec.md
+++ b/docs/spec/04-ux/08-component-spec.md
@@ -499,17 +499,19 @@ visually distinct from list content.
without deleting tabs; the work-panel header keeps its tab strip and fixed `+`
menu, while each tab owns resource closing
- Click the `Projects` heading folder-plus action: open the Create project
- dialog. The dialog accepts a project name and one or more local folders,
- lists every selected folder with a remove action, and marks the first folder
- as Primary. Creation makes one logical project group: the primary folder is
- activated and names the group, while every other selected folder is retained
- as a group root and is shown in Project archive details, not as an open
- project tab. Group chats, instructions, and memory use the same group
- identity. A source selector offers This computer and Git repository: the git
- source swaps the folder list for a repository URL field plus a clone
- destination row, seeds the project name from the repository name until the
- user types their own, and creates the project by cloning into the chosen
- folder first. The dialog follows
+ dialog. The dialog accepts an optional project name and one or more local
+ folders, lists every selected folder with a remove action, and marks the
+ first folder as Primary. The name field seeds from the picked source until
+ the user types their own name: the first selected folder names a local pick
+ and the repository name names a git checkout. Create falls back to the same
+ derived name, so an empty name field never blocks creation. Creation makes
+ one logical project group: the primary folder is activated and names the
+ group, while every other selected folder is retained as a group root and is
+ shown in Project archive details, not as an open project tab. Group chats,
+ instructions, and memory use the same group identity. A source selector
+ offers This computer and Git repository: the git source swaps the folder
+ list for a repository URL field plus a clone destination row and creates
+ the project by cloning into the chosen folder first. The dialog follows
the shell's neutral gray surfaces, with a 480px maximum width,
`--radius-lg-plus` (18px) corners, and the shared `--ds-shadow-dialog`
elevation. Its compact type hierarchy uses `--text-lg` for the title,
diff --git a/docs/spec/06-delivery/04-e2e-test-plan.md b/docs/spec/06-delivery/04-e2e-test-plan.md
index 91e1e3506..534b57e9c 100644
--- a/docs/spec/06-delivery/04-e2e-test-plan.md
+++ b/docs/spec/06-delivery/04-e2e-test-plan.md
@@ -1693,8 +1693,9 @@ identify the platform validation still needed.
- **Steps**:
1. Invoke Add project from Settings → Project archive or the sidebar Projects
heading and inspect the empty dialog.
- 2. Enter a project name and add two folders with the folder picker. Confirm
- both rows render and the first row is marked Primary.
+ 2. Add two folders with the folder picker without typing a name. Confirm the
+ name field seeds with the first folder's name, both rows render, and the
+ first row is marked Primary.
3. Remove one row, check the count, and add it again.
4. Inspect the empty and populated states in light and dark themes, including
a narrow window and reduced-motion settings.
@@ -1708,8 +1709,9 @@ identify the platform validation still needed.
- **Expected**: The dialog traps focus, closes on Escape or outside click while
idle, and keeps the name and selected folders visible without horizontal
overflow. The native picker allows multiple directories in one selection.
- Removing a folder updates the count and never removes another row. Create is
- disabled until both a name and one folder are present. On creation one
+ Removing a folder updates the count and never removes another row. Create
+ needs one folder and no typed name; an empty name field falls back to the
+ first folder's name. On creation one
logical project group receives the entered display name; its primary folder
becomes the active workspace and every selected folder is retained as a group
root. The Project archive shows one group row, and its sessions, shared
@@ -12642,7 +12644,8 @@ plugin-form fixtures in an isolated temporary directory at runtime.
a clone destination row and keeps one project name field. Source options and
fields are filled tiles without strokes; keyboard focus uses the shared
accent-tinted ring. Create stays
- disabled until the URL parses and a folder is chosen. Confirming runs
+ disabled until the URL parses and a folder is chosen; a name left empty falls
+ back to the parsed repository name. Confirming runs
`git clone` into the chosen folder with the renderer still owning project
creation: the checkout becomes the primary root and the entered name names the
group. Private, loopback, link-local, credential-bearing, and malformed
diff --git a/docs/spec/08-meta/decisions-log.md b/docs/spec/08-meta/decisions-log.md
index eaf7b1ea3..ef1001879 100644
--- a/docs/spec/08-meta/decisions-log.md
+++ b/docs/spec/08-meta/decisions-log.md
@@ -6399,3 +6399,23 @@ that was sitting at the bottom — including after the turn had finished.
- `out/renderer` emits no application font face any more; only KaTeX's `woff2`
glyphs remain. See ADR 0298, `04-ux/06-settings-ia.md`,
`04-ux/07-ui-design-system.md`, and E2E-126.
+
+## 2026-09-20 — The Create project name defaults to the primary folder (D600)
+
+- The Create project dialog required a typed name before Create became
+ available, so a local folder pick could not be confirmed without inventing a
+ title; the git source already seeded the field from the repository name
+ (D438, ADR 0273).
+- The name field is now optional for both sources. It seeds from the picked
+ source — the first selected folder's name for a local pick, the repository
+ name for a git checkout — and stops following the source as soon as the user
+ types their own name. Create is gated by the source alone (one folder, or a
+ parsed URL plus a destination), and a field left empty falls back to the same
+ derived name.
+- Derived names are cut to `MAX_PROJECT_NAME_CHARS` (80) so the persisted
+ sidebar preference and the name field accept them unchanged. Folder-name
+ parsing moves to `apps/desktop/src/lib/project-name.ts` and is shared with the
+ dialog's folder rows.
+- Renderer only: no protocol, storage, host, permission, or migration change,
+ and no new default. See `04-ux/08-component-spec.md`, ADR 0233, ADR 0273, and
+ E2E-012a / E2E-256.
diff --git a/docs/zh-CN/spec/08-meta/decisions-log.md b/docs/zh-CN/spec/08-meta/decisions-log.md
index d3849b62d..d34376044 100644
--- a/docs/zh-CN/spec/08-meta/decisions-log.md
+++ b/docs/zh-CN/spec/08-meta/decisions-log.md
@@ -4570,3 +4570,17 @@ that amendment are retired by ADR 0268; the upstream work-panel lifecycle stays.
渲染。无迁移、协议或 schema 变更。
- 渲染器产物不再产出任何应用字体面,只剩 KaTeX 的 `woff2` 字形。见 ADR 0298、
`04-ux/06-settings-ia.md`、`04-ux/07-ui-design-system.md` 与 E2E-126。
+
+## 2026-09-20 —— 新建项目的名称默认取主要文件夹(D600)
+
+- 新建项目对话框原本要求先填名称才能创建,本地选文件夹时不得不先编一个标题;
+ Git 来源此前已用仓库名预填该字段(D438、ADR 0273)。
+- 名称字段现在对两种来源都可选。它按所选来源预填——本地来源取第一个(主要)
+ 文件夹的名称,Git 来源取仓库名——用户一旦自己输入就不再跟随来源。创建按钮
+ 只由来源决定是否可用(一个文件夹,或解析成功的地址加保存位置),字段留空时
+ 回退为同一个默认名。
+- 派生名称会截断到 `MAX_PROJECT_NAME_CHARS`(80),以保证侧边栏偏好持久化和
+ 名称字段都能原样接受。文件夹名解析移到
+ `apps/desktop/src/lib/project-name.ts`,与对话框的文件夹行共用。
+- 仅渲染器改动:不改协议、存储、宿主、权限或迁移,也不新增默认值。见
+ `04-ux/08-component-spec.md`、ADR 0233、ADR 0273、E2E-012a / E2E-256。