Skip to content

The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.

feat: name a new project and its agent after the first task (#94)

bubu-dudu9e2fd1fe7974
diff --git a/cli/src/lib/agentNames.spec.ts b/cli/src/lib/agentNames.spec.ts
index e8350ecd7..6e11bc926 100644
--- a/cli/src/lib/agentNames.spec.ts
+++ b/cli/src/lib/agentNames.spec.ts
@@ -1,7 +1,16 @@
import { describe, expect, it } from 'vitest'
-import { automaticAgentName, engineLabel, isAutomaticName, projectFolderName } from './agentNames.js'
+import { automaticAgentName, engineLabel, foldDiacritics, isAutomaticName, projectFolderName, projectFolderSlug } from './agentNames.js'
import { ENGINES } from '../engines/types.js'
+describe('project folder slugs', () => {
+ it('keeps an accented letter as its base letter rather than dropping it', () => {
+ expect(projectFolderSlug('Robot nói chuyện với Gemini')).toBe('Robot-noi-chuyen-voi-Gemini')
+ expect(projectFolderSlug('Đèn bàn')).toBe('Den-ban')
+ expect(foldDiacritics('Straße, smørrebrød, façade')).toBe('Strasse, smorrebrod, facade')
+ expect(projectFolderSlug('机器人')).toBeNull()
+ })
+})
+
describe('agent names: who and when', () => {
it('names every engine the way the app does, and passes an unknown one through', () => {
for (const engine of ENGINES) expect(engineLabel(engine)).toMatch(/^[A-Z]/)
diff --git a/cli/src/lib/agentNames.ts b/cli/src/lib/agentNames.ts
index d4cad7b6c..bbb1bba7e 100644
--- a/cli/src/lib/agentNames.ts
+++ b/cli/src/lib/agentNames.ts
@@ -196,8 +196,16 @@ export function plausibleBranchName(name: unknown): name is string {
/** The folder for a project somebody named: their words with spaces as dashes and nothing a path or
* a shell reads specially. Null when nothing usable is left. Mirrors `projectFolderSlug` in
- * desktop/lib/core/project_folder.dart. */
+ * desktop/lib/core/project_folder.dart. Accented letters keep their base letter (`nói` → `noi`)
+ * rather than being dropped. */
export function projectFolderSlug(name: string): string | null {
- const slug = name.trim().replace(/\s+/g, '-').replace(/[^A-Za-z0-9._-]+/g, '').replace(/^[.-]+|[.-]+$/g, '')
+ const slug = foldDiacritics(name).trim().replace(/\s+/g, '-').replace(/[^A-Za-z0-9._-]+/g, '').replace(/^[.-]+|[.-]+$/g, '')
return slug ? slug.slice(0, 64) : null
}
+
+/** [text] with Latin letters' accents removed — `đ` and `ß` by hand, since neither decomposes. Mirrors
+ * `foldDiacritics` in desktop/lib/core/project_folder.dart. */
+export function foldDiacritics(text: string): string {
+ return text.normalize('NFD').replace(/\p{M}+/gu, '')
+ .replace(/đ/g, 'd').replace(/Đ/g, 'D').replace(/ß/g, 'ss').replace(/ø/g, 'o').replace(/Ø/g, 'O')
+}
diff --git a/cli/src/lib/projectFolder.spec.ts b/cli/src/lib/projectFolder.spec.ts
index 63759809d..d53b12583 100644
--- a/cli/src/lib/projectFolder.spec.ts
+++ b/cli/src/lib/projectFolder.spec.ts
@@ -43,6 +43,18 @@ describe('project folder preparation', () => {
expect(await readdir(root)).toEqual(['My-Game-v2'])
})
+ it('numbers a suggested name past a folder that exists, instead of refusing it', async () => {
+ expect(parseProjectFolder({ projectSource: 'new', projectName: 'robot-noi-chuyen', projectNameMode: 'suggested' }))
+ .toEqual({ source: 'new', name: 'robot-noi-chuyen', suggested: true })
+ // Any other mode is an ordinary chosen name.
+ expect(parseProjectFolder({ projectSource: 'new', projectName: 'robot', projectNameMode: 'mine' }))
+ .toEqual({ source: 'new', name: 'robot' })
+ const suggested = { source: 'new', name: 'robot-noi-chuyen', suggested: true } as const
+ await writeFile(join(root, 'robot-noi-chuyen-2'), 'a file takes the name too')
+ expect(await prepareProjectFolder(suggested, { root, label: 'Codex', now })).toBe(join(root, 'robot-noi-chuyen'))
+ expect(await prepareProjectFolder(suggested, { root, label: 'Codex', now })).toBe(join(root, 'robot-noi-chuyen-3'))
+ })
+
it('gives two projects in the same minute the seconds, then a suffix, and never takes a file’s name', async () => {
await writeFile(join(root, 'codex-2026-09-03-09-05'), 'keep')
const folders = await Promise.all([1, 2, 3].map(() => prepareProjectFolder({ source: 'new' }, { root, label: 'Codex', now })))
diff --git a/cli/src/lib/projectFolder.ts b/cli/src/lib/projectFolder.ts
index e0dccbf31..f302646f4 100644
--- a/cli/src/lib/projectFolder.ts
+++ b/cli/src/lib/projectFolder.ts
@@ -6,8 +6,9 @@ import { plausibleBranchName, projectFolderName, projectFolderSlug } from './age
import { GitProjectError, prepareGitProject, validGitPath } from './gitProject.js'
/** `name` on a new project is what the person called it; without one the folder is named after the
- * harness and the time. */
-export type ProjectFolder = { source: 'new'; name?: string } | { source: 'remote'; repositoryUrl: string; name: string }
+ * harness and the time. `suggested` marks a name the app made up (from the first task — the phone has
+ * no name field), which is numbered past a folder that exists rather than refused. */
+export type ProjectFolder = { source: 'new'; name?: string; suggested?: boolean } | { source: 'remote'; repositoryUrl: string; name: string }
| { source: 'worktree'; gitSource: string; branchRef?: string; branchName?: string; existingBranch?: boolean; placeholder?: boolean }
| { source: 'branch'; gitSource: string; branchRef?: string; branchName?: string }
@@ -53,7 +54,8 @@ export function parseProjectFolder(payload: Record<string, unknown>): ProjectFol
if (payload.projectSource === 'new' && payload.repositoryUrl === undefined) {
// Slugged again here: the name becomes a path segment, so it is never taken on trust.
const name = typeof payload.projectName === 'string' ? projectFolderSlug(payload.projectName) : null
- return name ? { source: 'new', name } : { source: 'new' }
+ if (!name) return { source: 'new' }
+ return payload.projectNameMode === 'suggested' ? { source: 'new', name, suggested: true } : { source: 'new', name }
}
if (payload.projectSource !== 'remote' || typeof payload.repositoryUrl !== 'string') {
throw new ProjectFolderError('INVALID_PROJECT_SOURCE', 'Choose a project.')
@@ -110,12 +112,18 @@ export async function prepareProjectFolder(
await mkdir(root, { recursive: true })
if (project.source === 'new' && project.name) {
// A name somebody chose is never quietly changed: an existing folder is theirs to pick as an
- // existing project, as a clone's is.
- const folder = join(root, project.name)
- try { await mkdir(folder); return folder }
- catch (error) {
- if ((error as NodeJS.ErrnoException).code !== 'EEXIST') throw error
- throw new ProjectFolderError('PROJECT_EXISTS', `“${project.name}” already exists. Select that folder from your projects.`)
+ // existing project, as a clone's is. A suggested one is only a guess, so a second "robot" task
+ // gets `robot-2` beside the first rather than an error (openharness#94).
+ for (let attempt = 1; ; attempt++) {
+ const name = attempt === 1 ? project.name : `${project.name.slice(0, 60)}-${attempt}`
+ const folder = join(root, name)
+ try { await mkdir(folder); return folder }
+ catch (error) {
+ if ((error as NodeJS.ErrnoException).code !== 'EEXIST') throw error
+ if (!project.suggested) {
+ throw new ProjectFolderError('PROJECT_EXISTS', `“${project.name}” already exists. Select that folder from your projects.`)
+ }
+ }
}
}
if (project.source === 'new') {
diff --git a/desktop/lib/core/project_folder.dart b/desktop/lib/core/project_folder.dart
index 717cf3e30..fc05cb740 100644
--- a/desktop/lib/core/project_folder.dart
+++ b/desktop/lib/core/project_folder.dart
@@ -17,10 +17,16 @@ class ProjectFolderRequest {
createsWorktree = false,
repository = null,
generatedLabel = null,
- generatedAt = null;
+ generatedAt = null,
+ generatedTask = null;
+
+ /// A suggested new project: named after the first [task] when it has words
+ /// to name it by (openharness#94 — five `solder-2026-…` folders said nothing
+ /// about which board was which), otherwise after [label] and the time.
ProjectFolderRequest.generated({
required String label,
required DateTime at,
+ String? task,
String? name,
}) : gitSource = null,
branchRef = null,
@@ -31,7 +37,11 @@ class ProjectFolderRequest {
repository = null,
generatedLabel = label,
generatedAt = at,
- name = name ?? _suggestedFolderName(label, at);
+ generatedTask = taskProjectSlug(task ?? '') == null ? null : task,
+ name =
+ name ??
+ taskProjectSlug(task ?? '') ??
+ _suggestedFolderName(label, at);
const ProjectFolderRequest.remote(GitHubRepository value)
: gitSource = null,
branchRef = null,
@@ -42,7 +52,8 @@ class ProjectFolderRequest {
repository = value,
name = null,
generatedLabel = null,
- generatedAt = null;
+ generatedAt = null,
+ generatedTask = null;
/// A new worktree on [branchName]: created from [branchRef], or with
/// [existingBranch] that local branch checked out as it is. Without a name
@@ -58,7 +69,8 @@ class ProjectFolderRequest {
repository = null,
name = null,
generatedLabel = null,
- generatedAt = null;
+ generatedAt = null,
+ generatedTask = null;
/// The folder itself on [ref], or with [newBranch] on that new branch, made
/// where the folder is now. [ref] then names the new branch, so a daemon that
@@ -76,7 +88,8 @@ class ProjectFolderRequest {
repository = null,
name = null,
generatedLabel = null,
- generatedAt = null;
+ generatedAt = null,
+ generatedTask = null;
final String? gitSource, branchRef, branchName;
@@ -90,11 +103,33 @@ class ProjectFolderRequest {
final String? name;
final String? generatedLabel;
final DateTime? generatedAt;
+
+ /// The first task a suggested name was made from, or null for one made from
+ /// the label and the time.
+ final String? generatedTask;
bool get isGenerated => generatedAt != null;
+ /// What the agent is called before its engine titles the session: the
+ /// person's own name for the project, or the words of the task it was named
+ /// after. Null for a clock-named one, which the machine names itself.
+ String? get agentName => generatedTask != null
+ ? taskProjectTitle(generatedTask!)
+ : isGenerated
+ ? null
+ : name?.trim().isEmpty ?? true
+ ? null
+ : name!.trim();
+
/// The preview and Start share a frozen timestamp. Only an untouched
/// suggestion can advance to another name if its folder is taken.
String nextGeneratedName(String taken) {
+ // Named after the task: the same words again, numbered.
+ if (taskProjectSlug(generatedTask ?? '') case final base?) {
+ final suffix = int.tryParse(taken.split('-').last);
+ return taken.startsWith('$base-') && suffix != null && suffix >= 2
+ ? '$base-${suffix + 1}'
+ : '$base-2';
+ }
final precise = _suggestedFolderName(
generatedLabel!,
generatedAt!,
@@ -127,6 +162,7 @@ class ProjectFolderRequest {
ProjectFolderRequest.generated(
label: generatedLabel!,
at: generatedAt!,
+ task: generatedTask,
name: name,
);
@@ -148,6 +184,11 @@ class ProjectFolderRequest {
if (repository != null) 'repositoryUrl': repository!.url,
// A daemon that predates the field ignores it and names the folder itself.
if (repository == null && folderName != null) 'projectName': folderName!,
+ // A suggestion the machine may number past a folder that exists (`-2`)
+ // rather than refuse; a name the person typed stays refused. A daemon that
+ // predates it treats every name as typed.
+ if (repository == null && folderName != null && isGenerated)
+ 'projectNameMode': 'suggested',
};
/// A new project is named after who it is for and when: [label] ("Codex", "Blender") and the
@@ -284,8 +325,12 @@ String projectFolderName(
/// and nothing a path or a shell reads specially. Null when nothing usable is
/// left, which callers treat as "not named". Mirrors `projectFolderSlug` in
/// cli/src/lib/agentNames.ts.
+///
+/// Accented letters keep their base letter (`nói` → `noi`, `đèn` → `den`)
+/// rather than being dropped, which turned "Robot nói chuyện" into
+/// `Robot-ni-chuyn`.
String? projectFolderSlug(String name) {
- final slug = name
+ final slug = foldDiacritics(name)
.trim()
.replaceAll(RegExp(r'\s+'), '-')
.replaceAll(RegExp(r'[^A-Za-z0-9._-]+'), '')
@@ -293,3 +338,78 @@ String? projectFolderSlug(String name) {
if (slug.isEmpty) return null;
return slug.length > 64 ? slug.substring(0, 64) : slug;
}
+
+/// How many of a first task's words name the project and the agent.
+const _taskNameWords = 6;
+
+/// The first line of [task], cut to its first few words — what a project named
+/// after its task is called ("Robot nói chuyện với Gemini"). Null when the
+/// task has no letters or digits to name anything by.
+String? taskProjectTitle(String task) {
+ final line = task
+ .trim()
+ .split('\n')
+ .first
+ .split(RegExp(r'\s+'))
+ .where((word) => word.isNotEmpty)
+ .take(_taskNameWords)
+ .join(' ');
+ if (!RegExp(r'[\p{L}\p{N}]', unicode: true).hasMatch(line)) return null;
+ return line.length > 60 ? line.substring(0, 60).trimRight() : line;
+}
+
+/// The folder a project named after [task] gets: its [taskProjectTitle] in
+/// lowercase words joined by dashes, accents folded (`robot-noi-chuyen-voi-
+/// gemini`). Null when nothing usable is left.
+String? taskProjectSlug(String task) {
+ final title = taskProjectTitle(task);
+ if (title == null) return null;
+ final slug = foldDiacritics(title)
+ .toLowerCase()
+ .replaceAll(RegExp(r'[^a-z0-9]+'), '-')
+ .replaceAll(RegExp(r'^-+|-+$'), '');
+ if (slug.isEmpty) return null;
+ return slug.length > 48
+ ? slug.substring(0, 48).replaceAll(RegExp(r'-+$'), '')
+ : slug;
+}
+
+/// [text] with Latin letters' accents removed: Vietnamese (`đ` included),
+/// French, German, Spanish, Portuguese and the like. Other scripts pass
+/// through untouched. Mirrors `foldDiacritics` in cli/src/lib/agentNames.ts.
+String foldDiacritics(String text) {
+ final out = StringBuffer();
+ for (final rune in text.runes) {
+ final char = String.fromCharCode(rune);
+ out.write(_folds[char] ?? char);
+ }
+ return out.toString();
+}
+
+final Map<String, String> _folds = () {
+ const groups = {
+ 'a': 'àáảãạăằắẳẵặâầấẩẫậäåā',
+ 'A': 'ÀÁẢÃẠĂẰẮẲẴẶÂẦẤẨẪẬÄÅĀ',
+ 'e': 'èéẻẽẹêềếểễệëē',
+ 'E': 'ÈÉẺẼẸÊỀẾỂỄỆËĒ',
+ 'i': 'ìíỉĩịïī',
+ 'I': 'ÌÍỈĨỊÏĪ',
+ 'o': 'òóỏõọôồốổỗộơờớởỡợöøō',
+ 'O': 'ÒÓỎÕỌÔỒỐỔỖỘƠỜỚỞỠỢÖØŌ',
+ 'u': 'ùúủũụưừứửữựüū',
+ 'U': 'ÙÚỦŨỤƯỪỨỬỮỰÜŪ',
+ 'y': 'ỳýỷỹỵÿ',
+ 'Y': 'ỲÝỶỸỴŸ',
+ 'd': 'đ',
+ 'D': 'Đ',
+ 'c': 'ç',
+ 'C': 'Ç',
+ 'n': 'ñ',
+ 'N': 'Ñ',
+ 'ss': 'ß',
+ };
+ return {
+ for (final MapEntry(key: base, value: letters) in groups.entries)
+ for (final letter in letters.runes) String.fromCharCode(letter): base,
+ };
+}();
diff --git a/desktop/lib/state/new_harness.dart b/desktop/lib/state/new_harness.dart
index e49fc2937..947f7817c 100644
--- a/desktop/lib/state/new_harness.dart
+++ b/desktop/lib/state/new_harness.dart
@@ -1400,6 +1400,15 @@ class NewHarnessController extends ChangeNotifier {
? 'A first message can be $kFirstTaskMaxLength characters; '
'this is ${value.trim().length}.'
: null;
+ // A suggested project follows the task it will be named after; a name
+ // the person typed is theirs and stays.
+ if (_project.generated case final suggested?) {
+ final next = _generatedProject();
+ if (next.generated?.generatedTask != suggested.generatedTask) {
+ _project = next;
+ unawaited(_refreshGeneratedProject());
+ }
+ }
notifyListeners();
return;
}
@@ -1883,6 +1892,8 @@ class NewHarnessController extends ChangeNotifier {
ProjectFolderRequest.generated(
label: _harnessId == null ? engineIdentity(_engine).label : harnessLabel,
at: _now(),
+ // Only a task the agent will actually be sent names the project.
+ task: takesTask ? task : null,
),
);
@@ -3250,6 +3261,10 @@ class NewHarnessController extends ChangeNotifier {
dsh: harness,
// Sent exactly as written; an agent that cannot take one is never sent it.
prompt: takesTask && firstMessage.isNotEmpty ? firstMessage : null,
+ // A new project named by the person, or after its task, names the agent
+ // too — until the engine titles the session. A clock-named one leaves
+ // it to the machine ("Solder harness 9-18 13:02").
+ name: projectFolderRequest?.agentName,
attempt: attempt,
);
if (_disposed) return NewHarnessOutcome.failed;
diff --git a/desktop/test/new_harness_controller_edges_test.dart b/desktop/test/new_harness_controller_edges_test.dart
index 77da0ae69..1a071f133 100644
--- a/desktop/test/new_harness_controller_edges_test.dart
+++ b/desktop/test/new_harness_controller_edges_test.dart
@@ -515,6 +515,41 @@ void main() {
expect(fixture.connection.requests('agent_create'), isEmpty);
});
+ test('a suggested project is named after its first task, and names the agent too (#94)', () async {
+ final fixture = _Fixture();
+ fixture.connection.replies['fs_list_dir'] = (payload) => {
+ 'path': payload['path'] ?? '/home/test',
+ 'entries': [
+ if (payload['path'] == '/home/test/harnesses')
+ {'name': 'robot-noi-chuyen-voi-gemini', 'isDir': true},
+ ],
+ };
+ final box = fixture.box(folder: null, autoProject: true);
+ await _settle();
+ expect(box.project.name, startsWith('codex-'), reason: 'no task yet');
+
+ box.focusField(NewHarnessField.task);
+ box.setQuery('Robot nói chuyện với Gemini\nthen a speaker board');
+ await _settle();
+ // Accents folded, the first line only, and a taken folder numbered.
+ expect(box.project.name, 'robot-noi-chuyen-voi-gemini-2');
+ expect(box.project.generated!.isGenerated, isTrue);
+
+ await box.create();
+ final create = fixture.connection.requests('agent_create').single;
+ expect(create['name'], 'Robot nói chuyện với Gemini');
+ expect(create['projectName'], 'robot-noi-chuyen-voi-gemini-2');
+ });
+
+ test('a clock-named project leaves the agent for the machine to name', () async {
+ final fixture = _Fixture();
+ final box = fixture.box(folder: null, autoProject: true);
+ await _settle();
+ await box.create();
+ final create = fixture.connection.requests('agent_create').single;
+ expect(create.containsKey('name'), isFalse);
+ });
+
test('profile discovery includes observed agent paths and link failures preserve selection', () async {
final fixture = _Fixture();
fixture.app.machineStates['m']!.agents = [
diff --git a/desktop/test/project_folder_test.dart b/desktop/test/project_folder_test.dart
index 0fdc23041..93c51bfab 100644
--- a/desktop/test/project_folder_test.dart
+++ b/desktop/test/project_folder_test.dart
@@ -48,6 +48,47 @@ void main() {
matches(RegExp(r'^harness-\d{4}-\d{2}-\d{2}-\d{2}-\d{2}$')),
);
});
+ test('a project named after its task keeps accented letters and numbers a taken name', () {
+ expect(
+ foldDiacritics('Đèn bàn nói chuyện, façade, Straße'),
+ 'Den ban noi chuyen, facade, Strasse',
+ );
+ expect(projectFolderSlug('Robot nói chuyện'), 'Robot-noi-chuyen');
+ expect(
+ taskProjectTitle(' Robot nói chuyện với Gemini qua loa\nsecond line'),
+ 'Robot nói chuyện với Gemini qua',
+ );
+ expect(
+ taskProjectSlug('Robot nói chuyện với Gemini'),
+ 'robot-noi-chuyen-voi-gemini',
+ );
+ expect(taskProjectSlug('!!! ???'), isNull);
+ expect(taskProjectSlug('机器人'), isNull);
+
+ final at = DateTime(2026, 9, 3, 9, 5, 7);
+ final named = ProjectFolderRequest.generated(
+ label: 'Codex',
+ at: at,
+ task: 'Đèn bàn',
+ );
+ expect(named.name, 'den-ban');
+ expect(named.agentName, 'Đèn bàn');
+ expect(named.availableGeneratedName(['den-ban', 'DEN-BAN-2']), 'den-ban-3');
+ expect(named.withGeneratedName('den-ban-3').agentName, 'Đèn bàn');
+
+ final clock = ProjectFolderRequest.generated(
+ label: 'Codex',
+ at: at,
+ task: ' ',
+ );
+ expect(clock.name, 'codex-2026-09-03-09-05');
+ expect(clock.agentName, isNull);
+ expect(
+ const ProjectFolderRequest.newProject(name: 'Robot board').agentName,
+ 'Robot board',
+ );
+ });
+
test('folder names pad every part and fall back to harness', () {
final at = DateTime(2026, 12, 25, 0, 0, 9);
expect(projectFolderName('Blender', at), 'blender-2026-12-25-00-00');
diff --git a/mobile/lib/core/project_folder.dart b/mobile/lib/core/project_folder.dart
index 9e38a0df8..889e4abca 100644
--- a/mobile/lib/core/project_folder.dart
+++ b/mobile/lib/core/project_folder.dart
@@ -18,7 +18,21 @@ class ProjectFolderRequest {
branchName = null,
existingBranch = false,
placeholder = false,
- createsWorktree = false;
+ createsWorktree = false,
+ suggestedName = null;
+
+ /// A fresh project named after its first [task] (openharness#94): the machine makes
+ /// `~/harnesses/robot-noi-chuyen-voi-gemini`, and numbers it past one that exists. A task with
+ /// no words to name it by leaves the name to the machine, as [ProjectFolderRequest.newProject].
+ ProjectFolderRequest.forTask(String task)
+ : repository = null,
+ gitSource = null,
+ branchRef = null,
+ branchName = null,
+ existingBranch = false,
+ placeholder = false,
+ createsWorktree = false,
+ suggestedName = taskProjectSlug(task);
/// Let the machine clone [value] and work in the checkout.
const ProjectFolderRequest.remote(GitHubRepository value)
@@ -28,7 +42,8 @@ class ProjectFolderRequest {
branchName = null,
existingBranch = false,
placeholder = false,
- createsWorktree = false;
+ createsWorktree = false,
+ suggestedName = null;
/// A new worktree of the repository at [source], on [branchName]: created
/// from [branchRef], or with [existingBranch] that local branch checked out
@@ -45,7 +60,8 @@ class ProjectFolderRequest {
this.placeholder = false,
}) : gitSource = source,
createsWorktree = true,
- repository = null;
+ repository = null,
+ suggestedName = null;
/// The folder at [source] itself on [ref], or with [newBranch] on that new
/// branch, made where the folder is now.
@@ -63,10 +79,15 @@ class ProjectFolderRequest {
existingBranch = false,
placeholder = false,
createsWorktree = false,
- repository = null;
+ repository = null,
+ suggestedName = null;
final GitHubRepository? repository;
+ /// The folder a fresh project is named after its first task, or null to leave the name to the
+ /// machine (engine and time).
+ final String? suggestedName;
+
/// The existing checkout a branch or worktree is taken from. Null for the two
/// sources that have no repository yet.
final String? gitSource;
@@ -95,9 +116,88 @@ class ProjectFolderRequest {
if (existingBranch) 'branchMode': 'existing',
if (placeholder) 'branchMode': 'placeholder',
if (repository != null) 'repositoryUrl': repository!.url,
+ // A made-up name: the machine numbers it past a folder that exists rather than refusing it. A
+ // daemon that predates `projectNameMode` refuses a taken name instead; one that predates
+ // `projectName` names the folder itself.
+ 'projectName': ?suggestedName,
+ if (suggestedName != null) 'projectNameMode': 'suggested',
};
}
+/// How many of a first task's words name the project and the agent. The desktop's
+/// `core/project_folder.dart` holds the same rule; the two apps name the same task the same way.
+const _taskNameWords = 6;
+
+/// The first line of [task], cut to its first few words — what a project named after its task, and
+/// the agent in it, are called ("Robot nói chuyện với Gemini"). Null when the task has no letters or
+/// digits to name anything by.
+String? taskProjectTitle(String task) {
+ final line = task
+ .trim()
+ .split('\n')
+ .first
+ .split(RegExp(r'\s+'))
+ .where((word) => word.isNotEmpty)
+ .take(_taskNameWords)
+ .join(' ');
+ if (!RegExp(r'[\p{L}\p{N}]', unicode: true).hasMatch(line)) return null;
+ return line.length > 60 ? line.substring(0, 60).trimRight() : line;
+}
+
+/// The folder a project named after [task] gets: lowercase words joined by dashes, accents folded
+/// (`robot-noi-chuyen-voi-gemini`). Null when nothing usable is left.
+String? taskProjectSlug(String task) {
+ final title = taskProjectTitle(task);
+ if (title == null) return null;
+ final slug = foldDiacritics(title)
+ .toLowerCase()
+ .replaceAll(RegExp(r'[^a-z0-9]+'), '-')
+ .replaceAll(RegExp(r'^-+|-+$'), '');
+ if (slug.isEmpty) return null;
+ return slug.length > 48
+ ? slug.substring(0, 48).replaceAll(RegExp(r'-+$'), '')
+ : slug;
+}
+
+/// [text] with Latin letters' accents removed: Vietnamese (`đ` included), French, German,
+/// Spanish, Portuguese and the like. Other scripts pass through untouched.
+String foldDiacritics(String text) {
+ final out = StringBuffer();
+ for (final rune in text.runes) {
+ final char = String.fromCharCode(rune);
+ out.write(_folds[char] ?? char);
+ }
+ return out.toString();
+}
+
+final Map<String, String> _folds = () {
+ const groups = {
+ 'a': 'àáảãạăằắẳẵặâầấẩẫậäåā',
+ 'A': 'ÀÁẢÃẠĂẰẮẲẴẶÂẦẤẨẪẬÄÅĀ',
+ 'e': 'èéẻẽẹêềếểễệëē',
+ 'E': 'ÈÉẺẼẸÊỀẾỂỄỆËĒ',
+ 'i': 'ìíỉĩịïī',
+ 'I': 'ÌÍỈĨỊÏĪ',
+ 'o': 'òóỏõọôồốổỗộơờớởỡợöøō',
+ 'O': 'ÒÓỎÕỌÔỒỐỔỖỘƠỜỚỞỠỢÖØŌ',
+ 'u': 'ùúủũụưừứửữựüū',
+ 'U': 'ÙÚỦŨỤƯỪỨỬỮỰÜŪ',
+ 'y': 'ỳýỷỹỵÿ',
+ 'Y': 'ỲÝỶỸỴŸ',
+ 'd': 'đ',
+ 'D': 'Đ',
+ 'c': 'ç',
+ 'C': 'Ç',
+ 'n': 'ñ',
+ 'N': 'Ñ',
+ 'ss': 'ß',
+ };
+ return {
+ for (final MapEntry(key: base, value: letters) in groups.entries)
+ for (final letter in letters.runes) String.fromCharCode(letter): base,
+ };
+}();
+
/// A GitHub repository named by URL — `owner/repo`, an https link, or an ssh remote.
///
/// Ported from the desktop's `core/repository_clone.dart` without the cloning it sits beside there.
diff --git a/mobile/lib/phone/new_agent_page.dart b/mobile/lib/phone/new_agent_page.dart
index 727468439..e601d7636 100644
--- a/mobile/lib/phone/new_agent_page.dart
+++ b/mobile/lib/phone/new_agent_page.dart
@@ -619,18 +619,30 @@ class _NewAgentPageState extends State<NewAgentPage> {
// for turning the rows above into what the machine is asked to do. A folder
// that is not a repository, or one this form never read, falls through to
// the plain path — and `New project` / `Git…` keep the request they made.
- final request =
- project ??
- (folder == null || _repository == null
- ? null
- : gitFolderRequest(
- folder,
- _repository!,
- worktree: _worktree,
- branchRef: _branchRef,
- branchName: _branchName,
- placeholder: _placeholder ?? 'new-branch',
- ));
+ // A New folder is named after the first task when there is one to send — the phone has no name
+ // field, and five `codex-2026-…` folders told nobody which was which (openharness#94). The agent
+ // takes the same words until its engine titles the session.
+ final task = engine == 'terminal' || !takesFirstTask(engine)
+ ? ''
+ : _task.text;
+ final namedByTask =
+ project != null &&
+ project.repository == null &&
+ project.gitSource == null &&
+ taskProjectSlug(task) != null;
+ final request = namedByTask
+ ? ProjectFolderRequest.forTask(task)
+ : project ??
+ (folder == null || _repository == null
+ ? null
+ : gitFolderRequest(
+ folder,
+ _repository!,
+ worktree: _worktree,
+ branchRef: _branchRef,
+ branchName: _branchName,
+ placeholder: _placeholder ?? 'new-branch',
+ ));
final error = await widget.notifier.createAgent(
_machineId,
engine: engine,
@@ -647,6 +659,7 @@ class _NewAgentPageState extends State<NewAgentPage> {
model: _model,
attempt: creation,
prompt: _engine != null && takesFirstTask(_engine!) ? _task.text : null,
+ name: namedByTask ? taskProjectTitle(task) : null,
);
if (!mounted) return;
if (error == null) {
diff --git a/mobile/lib/state/app_state.dart b/mobile/lib/state/app_state.dart
index 735b06f38..54b618833 100644
--- a/mobile/lib/state/app_state.dart
+++ b/mobile/lib/state/app_state.dart
@@ -3624,6 +3624,7 @@ class AppNotifier extends ChangeNotifier {
String? swarmId,
AgentCreationAttempt? attempt,
String? prompt,
+ String? name,
}) {
final creation = attempt ?? AgentCreationAttempt();
final task = prompt?.trim();
@@ -3632,6 +3633,9 @@ class AppNotifier extends ChangeNotifier {
// The harness's first task — the machine types it into the agent once it is up. Only
// claude, codex and opencode take one (see `kFirstTaskEngines`); an empty one is left out.
if (task != null && task.isNotEmpty) 'prompt': task,
+ // What the agent is called until its engine titles the session. Absent, the machine names it
+ // after the engine and the time ("Codex harness 9-17 15:26").
+ if (name != null && name.trim().isNotEmpty) 'name': name.trim(),
if (projectFolder == null) 'cwd': folder,
...?projectFolder?.payload,
'permissionMode': ?permissionMode,
diff --git a/mobile/test/project_folder_test.dart b/mobile/test/project_folder_test.dart
index 311774559..c44474617 100644
--- a/mobile/test/project_folder_test.dart
+++ b/mobile/test/project_folder_test.dart
@@ -9,6 +9,30 @@ void main() {
});
});
+ test(
+ 'a new project named after its task asks for a numbered suggestion (#94)',
+ () {
+ expect(
+ ProjectFolderRequest.forTask('Robot nói chuyện với Gemini\nmore')
+ .payload,
+ {
+ 'projectSource': 'new',
+ 'projectName': 'robot-noi-chuyen-voi-gemini',
+ 'projectNameMode': 'suggested',
+ },
+ );
+ expect(
+ taskProjectTitle('Đèn bàn cho phòng làm việc nhỏ gọn đẹp'),
+ 'Đèn bàn cho phòng làm việc',
+ );
+ // Nothing to name it by: the machine names it, as a plain new project.
+ expect(ProjectFolderRequest.forTask('!!! ???').payload, {
+ 'projectSource': 'new',
+ });
+ expect(taskProjectSlug('机器人'), isNull);
+ },
+ );
+
test('a repository travels as its canonical clone URL', () {
final repo = GitHubRepository.parse('owner/repo')!;
expect(ProjectFolderRequest.remote(repo).payload, {