Skip to content

feat: make accessible_paths optional during agent creation#13126

Merged
kangfenmao merged 6 commits intomainfrom
DeJeune/agent-default-workspace
Mar 5, 2026
Merged

feat: make accessible_paths optional during agent creation#13126
kangfenmao merged 6 commits intomainfrom
DeJeune/agent-default-workspace

Conversation

@DeJeune
Copy link
Copy Markdown
Collaborator

@DeJeune DeJeune commented Mar 1, 2026

What this PR does

Before this PR:
Users were required to manually select at least one workspace folder via the OS file picker when creating an agent. The creation form would block submission if no accessible_paths were provided.

After this PR:
The accessible_paths field is optional during agent creation. When no paths are provided, the backend automatically creates a default workspace at {userData}/Data/agents/{agentId}/. Users can still optionally add paths during creation or change them later in Agent Settings.

Why we need it and why it was done in this way

The mandatory folder picker adds friction to agent creation — especially for new users who may not know what folder to pick. The backend already had fallback logic to create a default workspace when accessible_paths is empty, so this change simply removes the frontend enforcement that prevented that path from being reached.

The following tradeoffs were made:

  • The Zod schema accessible_paths constraint was relaxed from .nonempty() to .array(z.string()). This is safe because the backend handles the empty case.

The following alternatives were considered:

  • Having the frontend auto-fill a placeholder path before submission — rejected because the backend already handles this cleanly.

Breaking changes

None. The backend behavior is unchanged — it already supported empty accessible_paths and auto-created a default workspace.

Special notes for your reviewer

  • The backend AgentService.createAgent() (lines 40-43) already had the default workspace logic. No backend changes were needed.
  • In AccessibleDirsSetting.tsx, the restriction preventing removal of the last path was also removed, since the backend always ensures a valid workspace exists.

Checklist

Release note

Agent creation no longer requires selecting a workspace folder. A default workspace is automatically created under the app's data directory. Users can change or add workspace paths later in Agent Settings.

Default workspace is auto-created at {userData}/Data/agents/{agentId}/
when no paths are provided. Users can still optionally add paths during
creation or change them later in agent settings.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@DeJeune DeJeune requested review from EurFelux and kangfenmao March 1, 2026 11:39
Copy link
Copy Markdown
Collaborator Author

@DeJeune DeJeune left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Summary

The intent of this PR is solid — removing friction from agent creation by making accessible_paths optional is a good UX improvement, and the backend's createAgent() already handles the empty case with a default workspace.

Critical

  • Empty paths on update: The frontend guard in AccessibleDirsSetting.tsx that prevented removing the last path was removed, but the backend updateAgent() and updateSession() methods do not have the same default-workspace fallback that createAgent() has. If a user removes all paths via Agent Settings, the agent will be left with an empty accessible_paths array, causing PluginService.getWorkdirOrThrow() and the Claude Code service to throw errors.

Minor

  • Stale t in the removeAccessiblePath dependency array after toast removal.

Positives

  • Clean, minimal diff — only touches what's necessary.
  • Good PR description with clear before/after, tradeoffs, and backend cross-references.
  • Schema change propagates correctly through all derived types.

Comment on lines 50 to 52
(path: string) => {
if (!base) return
const newPaths = base.accessible_paths.filter((p) => p !== path)
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: The frontend guard preventing removal of the last path is removed, but the backend AgentService.updateAgent() does NOT auto-assign a default workspace when accessible_paths is set to an empty array — the default-path logic only exists in createAgent() (lines 40-43 of AgentService.ts).

This means: if a user removes all accessible paths via Agent Settings, the agent ends up with accessible_paths: [] in the database. Downstream code like PluginService.getWorkdirOrThrow() and ClaudeCodeService (session.accessible_paths[0]) will then throw or error.

Suggested fix options:

  1. Add the same default-path fallback to AgentService.updateAgent() (and SessionService.updateSession()) when accessible_paths is set to an empty array.
  2. Keep the frontend guard here in the settings page (remove-last prevention) while still making it optional during creation.

name: z.string().optional(),
description: z.string().optional(),
accessible_paths: z.array(z.string()).nonempty(), // Array of directory paths the agent can access
accessible_paths: z.array(z.string()), // Array of directory paths the agent can access (empty = use default workspace)
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: The schema change itself looks correct. Worth noting that this also affects AgentSessionEntitySchema (line 131), CreateAgentRequestSchema, UpdateAgentRequestSchema, etc. since they all extend AgentBaseSchema. The relaxation propagates cleanly to all derived schemas — just confirming this was intentional (and it makes sense that it is).

…via update

The backend createAgent() already assigned a default workspace when
accessible_paths was empty, but updateAgent() and updateSession() did not.
This caused PluginService and ClaudeCodeService to throw when a user
removed all paths via Agent Settings. Also removes a stale `t` dependency
in AccessibleDirsSetting.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@DeJeune DeJeune added this to the v1.7.22 milestone Mar 1, 2026
Aligns with the existing convention used by other data directories
(e.g., KnowledgeBase).

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@DeJeune DeJeune requested a review from GeorgeDong32 March 4, 2026 16:18
Copy link
Copy Markdown
Collaborator

@GeorgeDong32 GeorgeDong32 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review Summary

Overall this is a well-designed change that reduces friction in agent creation. The backend already had fallback logic for empty accessible_paths, so removing the frontend validation is a clean improvement.

Key Findings

  1. Path Case Change: The directory name changed from agents to Agents. This may cause compatibility issues with existing agents. Consider keeping lowercase.

  2. Code Duplication: The empty path handling logic is duplicated across 3 locations. A protected method in BaseService could reduce this.

What's Good

  • Frontend/backend consistency maintained
  • Security validation still happens on backend (absolute path check)
  • User experience improved by removing required folder selection
  • Graceful fallback to default workspace when no paths provided

Security

No security issues found. Backend properly validates that paths are absolute.

Comment thread src/main/services/agents/services/AgentService.ts Outdated
Comment thread src/main/services/agents/services/AgentService.ts
Consolidates the duplicated empty-path → default-workspace logic from
AgentService.createAgent, AgentService.updateAgent, and
SessionService.updateSession into a single BaseService method.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@DeJeune DeJeune requested a review from GeorgeDong32 March 4, 2026 16:43
@kangfenmao
Copy link
Copy Markdown
Collaborator

  1. The names of automatically created directories are quite long; you can shorten them.
  2. The directory location should be automatically displayed during creation.
image image

Comment thread src/main/services/agents/BaseService.ts Outdated
- Use last 9 chars of agent ID as folder name instead of full ID
- Show hint text in creation modal when no paths are selected
- Add i18n keys for default workspace hint

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@DeJeune
Copy link
Copy Markdown
Collaborator Author

DeJeune commented Mar 5, 2026

@kangfenmao

@kangfenmao kangfenmao merged commit a801801 into main Mar 5, 2026
9 checks passed
@kangfenmao kangfenmao deleted the DeJeune/agent-default-workspace branch March 5, 2026 05:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants