Skip to content

Conversation

@kaichen
Copy link

@kaichen kaichen commented Jan 5, 2026

Issue: on desktop, no project setup will read(project scope commands/skills etc.).

Root cause: only one project instance created, won't rebuild when switching project.

Solution: added ProcessCwd utility to safely manages process.cwd() changes. And wrap some process in Instance.provide to make sure use right project instance.

- Replace stack-based nested call tracking with simpler local variable
- Replace manual release/chained lock with promise queue pattern
- Extract getDirectory helper in server.ts to reduce duplication
- Use fs.exists() instead of fs.stat().then() pattern in config.ts
Tests cover:
- Running functions in specified directory
- Directory restoration after execution
- Skip optimization when already in target directory
- Error handling with proper cleanup
- Nested call handling
- Concurrent call serialization
- Async function support
- Deeply nested directory changes
Copilot AI review requested due to automatic review settings January 5, 2026 17:01
@kaichen kaichen requested a review from adamdotdevin as a code owner January 5, 2026 17:01
@github-actions
Copy link
Contributor

github-actions bot commented Jan 5, 2026

The following comment was made by an LLM, it may be inaccurate:

Duplicate Search Results

No duplicate PRs found.

The search queries returned only the PR mentioned in your file (PR #6963: "fix(desktop): desktop won't read project scope commands/skills"), which is the current PR being checked.

I searched using multiple relevant terms:

  • Desktop project scope commands/skills
  • ProcessCwd and process.cwd project management
  • Desktop switching and project rebuild
  • Instance.provide context management

All searches confirm there are no other open PRs addressing the same desktop project scope issue.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a critical issue on desktop where project-scoped commands, skills, and configurations were not being loaded when switching between projects. The root cause was that only a single project instance was created and reused across different directories without rebuilding.

Key changes:

  • Added ProcessCwd utility to safely manage process.cwd() changes with proper serialization for concurrent calls and restoration on completion
  • Wrapped project instance creation and execution with ProcessCwd.run() to ensure correct working directory context
  • Wrapped tool execution in server endpoints with Instance.provide() to guarantee proper project context
  • Added support for loading commands from .claude/commands/ directories for Claude Desktop compatibility
  • Enhanced desktop-specific project identification using directory hashing for non-git directories

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
packages/opencode/src/util/process-cwd.ts New utility to safely manage process.cwd() changes with concurrency control and nested call support
packages/opencode/test/util/process-cwd.test.ts Comprehensive test suite for ProcessCwd utility covering edge cases
packages/opencode/src/project/instance.ts Integrated ProcessCwd.run() to ensure tool execution happens in correct working directory context
packages/opencode/src/project/project.ts Added desktop-specific project identification using directory hashing for non-git directories
packages/opencode/src/config/config.ts Added support for loading commands from .claude/commands/ directories
packages/opencode/src/server/server.ts Extracted getDirectory helper and wrapped prompt endpoints with Instance.provide for proper project context
packages/opencode/src/session/prompt.ts Wrapped tool execution with Instance.provide to ensure commands/skills are loaded from correct project
packages/opencode/src/tool/skill.ts Fixed error message to properly display available skills using map instead of Promise
packages/app/src/context/permission.tsx Refactored directory decoding logic to avoid redundant operations (contains bug)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Directory is now passed directly without base64 encoding,
simplifying the permission check logic.
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.

1 participant