feat(desktop): per-project workspace/branch naming instructions

Merged
KI
3mo ago
+1557-78

Summary

Adds a per-project Naming instructions setting — a free-text prompt that guides how AI-generated workspace titles and branch names are produced when creating a workspace (e.g. "always include the Linear ticket id (bin-344) in the branch name" or "prefix branches with fix/ or feat/").

  • Storage: new naming_instructions column on the host-service local projects table (migration 0015, auto-applies at startup). Exposed via project.get; new project.setNamingInstructions mutation (trims, blank → NULL, 2000-char cap).
  • Injection: generateWorkspaceNamesFromPrompt takes the project's instructions and appends them to the naming system prompt on both paths (small-model and agent-CLI fallback). Wired into workspaces.create and workspaces.aiRename.
  • Sanitization: with instructions set, the branch candidate allows / (for fix/-style prefixes) and gets a 60-char budget. Unset keeps today's behavior byte-for-byte (25 chars, no slashes, "No prefixes" prompt).
  • UI: self-contained NamingInstructionsSection textarea in V2 project settings (debounced save, Saved/error states), placed under Branch prefix.

Verification

Beyond unit tests, verified end-to-end against the dev app via CDP (real clicks/keystrokes): set instructions on a scratch project, created a workspace through the New Workspace composer with prompt "bin-731: fix the typo in the README heading" → workspace named "Fix typo in README heading", branch fix/bin-731-readme-typo (confirmed in host SQLite + git branch --show-current). Cleared the setting → column back to NULL, default naming restored. Test workspace/branch deleted afterwards.

Test plan

  • bun run lint clean, bun run typecheck 37/37
  • 4 new unit tests: instructions injected into system prompt; default prompt unchanged; slash/60-char sanitization only with instructions; slashes still stripped without
  • V2ProjectSettings.test.tsx wiring test for the new section
  • Live E2E: set → persist (survives reload, raw SQLite row) → honored branch name → clear

Notes for reviewers

  • The AI branch rename does not re-apply the separate branch-prefix setting — pre-existing behavior, unchanged.
  • Only the V2/host-service path is wired; the sunset V1 Electron-main generators are untouched.
  • No-prompt workspace creation (pure random friendly name) has no LLM step, so instructions don't apply there by design.

Summary by cubic

Adds per-project naming instructions to guide generated workspace titles and branch names, and reorganizes V2 project settings into clear sections. Adds a quick link from the new workspace flow to update a project's naming rules, gated on setup and deep-linking to focus the field.

  • New Features

    • Storage: added naming_instructions on local projects (0015); exposed via project.get; new project.setNamingInstructions (trims, blank → NULL, 2000-char cap).
    • Generation: injects instructions into naming prompts in both small-model and agent-CLI paths; applied in workspaces.create and workspaces.aiRename.
    • Sanitization: with instructions, branches allow “/” and up to 60 chars; without, keep the 25-char, no-slash behavior.
    • UI: new NamingInstructionsSection in V2 project settings with debounced save and Saved/error states; “Update naming instructions” button on both new workspace surfaces that deep-links via a focus param and focuses the field, shown only after host setup; adjusted window-drag region so both buttons remain clickable.
  • Refactors

    • Settings UI organized into sections: General, Branches & naming, Location & checkout, Scripts, and Danger zone.
    • Promoted SettingsSection to shared settings components and updated header styling for readability.

Summary by CodeRabbit

  • New Features
    • Added project-specific naming instructions in project settings.
    • Instructions guide AI-generated workspace and branch names.
    • Added shortcuts from workspace creation screens to naming settings.
    • Instructions save automatically and can be cleared by leaving the field blank.
  • Improvements
    • Custom guidance supports longer branch names and slash prefixes.
    • Added a 2,000-character limit and saving, saved, and error states.
    • Reorganized project settings into clearer sections.
    • Settings shortcuts open and focus the naming instructions field.
  • Bug Fixes
    • Preserved existing naming behavior when no custom instructions are provided.