Skip to content

Use Codex workspace labels for project names#9

Merged
achimala merged 1 commit into
achimala:mainfrom
davej:pr/sidebar-collapse-and-project-labels
Feb 26, 2026
Merged

Use Codex workspace labels for project names#9
achimala merged 1 commit into
achimala:mainfrom
davej:pr/sidebar-collapse-and-project-labels

Conversation

@davej
Copy link
Copy Markdown
Contributor

@davej davej commented Feb 22, 2026

CleanShot 2026-02-22 at 10  41 44@2x

In Codex desktop app you can rename a project. This respects the renamed project name in Farfield. Also ensured that it works for users that don't have Codex desktop app installed.

Disclaimer: Code written with AI (Codex 5.3).

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Feb 22, 2026

📝 Walkthrough

Walkthrough

This PR introduces workspace root label support by adding a projectLabels field to agent descriptors. The server reads labels from a JSON file and propagates them via the agents API, while the web client uses these labels to display custom project group names instead of directory basenames.

Changes

Cohort / File(s) Summary
Type Definitions
apps/server/src/agents/types.ts
Adds projectLabels: Record<string, string> field to AgentDescriptor interface to carry per-project label mappings.
Server Implementation
apps/server/src/index.ts
Implements label reading from electron-workspace-root-labels JSON file with error handling; extends buildAgentDescriptor to accept and include projectLabels parameter; integrates label reading into /api/agents generation with graceful fallback to empty labels.
API Schema
apps/web/src/lib/api.ts
Updates AgentsResponseSchema to include projectLabels: Record<string, string> with default empty object on each agent descriptor.
Client UI
apps/web/src/App.tsx
Introduces memoized mapping projectLabelsByPath aggregating labels from all agent descriptors; updates thread grouping logic to resolve group labels from projectLabelsByPath with fallback to basenameFromPath.
Tests
apps/web/test/app.test.tsx
Adds test verifying project labels display in UI; extends agent fixture with optional projectLabels field.

Sequence Diagram

sequenceDiagram
    participant Server as Server/index.ts
    participant FS as File System
    participant API as /api/agents Endpoint
    participant Client as Web Client (App.tsx)
    participant UI as UI Render

    Server->>FS: Read electron-workspace-root-labels.json
    FS-->>Server: Return labels map
    Note over Server: Parse labels & handle errors gracefully
    
    Server->>Server: buildAgentDescriptor with projectLabels
    Server->>API: Generate /api/agents response
    API-->>Client: Return agents with projectLabels
    
    Client->>Client: Create projectLabelsByPath mapping
    Client->>Client: Resolve group labels via projectLabelsByPath.get()
    Client-->>UI: Render with custom project labels
    Note over UI: Display custom label or fallback to basename
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • achimala

Poem

🐰 Labels bloom where paths once bare,
From workspace roots we read with care,
Through agents flow the custom names,
Project groups wear their rightful claims! 📝

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Use Codex workspace labels for project names' directly and specifically describes the main objective of the changeset: implementing Codex workspace labels to display as project names/labels throughout the application.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
apps/web/src/App.tsx (1)

589-599: Optionally trim/skip empty project label entries to preserve fallbacks.

If a label is empty/whitespace, the map will store it and suppress the basename fallback. Trimming and skipping empty labels avoids blank group names and keeps lookups consistent.

♻️ Optional refinement
   const projectLabelsByPath = useMemo(() => {
     const labels = new Map<string, string>();
     for (const descriptor of agentDescriptors) {
       for (const [projectPath, label] of Object.entries(descriptor.projectLabels)) {
-        if (!labels.has(projectPath)) {
-          labels.set(projectPath, label);
-        }
+        const normalizedPath = projectPath.trim();
+        const normalizedLabel = label.trim();
+        if (!normalizedPath || !normalizedLabel || labels.has(normalizedPath)) {
+          continue;
+        }
+        labels.set(normalizedPath, normalizedLabel);
       }
     }
     return labels;
   }, [agentDescriptors]);

Also applies to: 616-618, 655-665

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/web/src/App.tsx` around lines 589 - 599, The projectLabelsByPath builder
currently saves empty or whitespace-only labels from descriptor.projectLabels
which suppresses the basename fallback; update the loop in projectLabelsByPath
to trim each label and only set it when trimmedLabel is non-empty (skip storing
empty/whitespace labels), and apply the same trim-and-skip change to the other
equivalent label-collection blocks that iterate agentDescriptors/descriptors and
assign project labels so fallbacks remain usable (look for the same pattern
around the other label-aggregation code).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@apps/server/src/index.ts`:
- Line 9: CodexGlobalStateSchema currently calls .passthrough(), which lets
unknown keys through; remove that and make the schema strict so unknown
properties are rejected (or stripped) by replacing .passthrough() with .strict()
on the z.object used to define CodexGlobalStateSchema; update any downstream
assumptions if they relied on unknown keys, but keep use of the
"electron-workspace-root-labels" property intact (refer to
CodexGlobalStateSchema and any usages such as parsing logic that calls
parse/parseAsync).

---

Nitpick comments:
In `@apps/web/src/App.tsx`:
- Around line 589-599: The projectLabelsByPath builder currently saves empty or
whitespace-only labels from descriptor.projectLabels which suppresses the
basename fallback; update the loop in projectLabelsByPath to trim each label and
only set it when trimmedLabel is non-empty (skip storing empty/whitespace
labels), and apply the same trim-and-skip change to the other equivalent
label-collection blocks that iterate agentDescriptors/descriptors and assign
project labels so fallbacks remain usable (look for the same pattern around the
other label-aggregation code).

Comment thread apps/server/src/index.ts
Copy link
Copy Markdown
Owner

@achimala achimala left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for the PR!

@achimala achimala merged commit eb81b58 into achimala:main Feb 26, 2026
1 check passed
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.

2 participants