|
| 1 | +## Copilot-for-Xcode — quick onboarding for AI coding agents |
| 2 | + |
| 3 | +This file gives concise, repo-specific guidance so an AI agent can be productive immediately. |
| 4 | + |
| 5 | +Goals |
| 6 | +- Understand the multi-process Xcode architecture (host app, XPC services, editor extension). |
| 7 | +- Know the canonical local build/run steps and important files to edit. |
| 8 | +- Recognize cross-component contracts (XPC service name, entitlements, versioning). |
| 9 | + |
| 10 | +Key components (big picture) |
| 11 | +- `Copilot for Xcode/` — the host macOS app (settings UI, ships the extension host). See `Version.xcconfig` for centralized versioning. |
| 12 | +- `EditorExtension/` — Xcode Source Editor Extension. It only forwards editor content to an XPC service and applies returned edits. Primary file: `EditorExtension/SourceEditorExtension.swift`. |
| 13 | +- `ExtensionService/` + `CommunicationBridge/` — non-sandboxed background services that implement most features and maintain XPC communication. Important files: `ExtensionService/ServiceDelegate.swift`, `ExtensionService/XPCController.swift`, `CommunicationBridge/main.swift`. |
| 14 | +- `Core/` and `Tool/` — Swift packages containing the main logic used by the services and host app. `Core/Sources/` contains core behavior; `Tool/` has command-line helpers. |
| 15 | +- `Server/` — local web UI and language server bundling. Uses `webpack` and `@github/copilot-language-server` packages. |
| 16 | + |
| 17 | +Developer workflows (explicit commands) |
| 18 | +- Local macOS app build (clean & build): |
| 19 | + - From repo root: `sh ./Script/uninstall-app.sh && rm -rf ./build && sh ./Script/localbuild-app.sh` — this produces `GitHub Copilot for Xcode.app` in `build/`. |
| 20 | + - Note: The build run scripts expect `node`/`npm` on PATH. The repo historically recommends symlinking system `node`/`npm` into `/usr/local/bin` (see `DEVELOPMENT.md`). |
| 21 | +- Run server build (for Server UI / language server packaging): |
| 22 | + - `cd Server && npm ci && npm run build` (script maps to `webpack`). |
| 23 | +- Testing the Source Editor Extension: |
| 24 | + - Launch `ExtensionService`, `CommunicationBridge` and the `EditorExtension` target in Xcode (see Apple docs: "Testing Your Source Editor Extension"). |
| 25 | +- Unit tests / test plan: |
| 26 | + - Run tests from the `Copilot for Xcode` target in Xcode. New tests should be added to `TestPlan.xctestplan`. |
| 27 | + |
| 28 | +Project-specific conventions & gotchas |
| 29 | +- XPC contract: the editor extension is sandboxed and must call a trusted non-sandboxed XPC service. The XPC service name must be listed in `com.apple.security.temporary-exception.mach-lookup.global-name` entitlements. When renaming services, update entitlements and both sides (see `ExtensionService` and `CommunicationBridge`). |
| 30 | +- Versioning: all target versions are controlled in `Version.xcconfig`. Change it there rather than editing target plist files directly. |
| 31 | +- Build scripts use a limited PATH: ensure `node` and `npm` are resolvable by run scripts (see `DEVELOPMENT.md` symlink suggestion) to avoid Xcode build-time failures. |
| 32 | +- Swift formatting: the project uses `swiftformat`. Follow the existing style (Ray Wenderlich guide with 4-space indentation) and the repo toolchain. |
| 33 | +- Packaging for the server: `Server/package.json` contains architecture-specific language-server packages (`darwin-arm64` and `darwin-x64`). When updating the copilot language server, keep those in sync. |
| 34 | + |
| 35 | +Integration points worth knowing |
| 36 | +- XPC wiring: `CommunicationBridge/main.swift` ↔ `ExtensionService/*` ↔ `EditorExtension/` — these three are the most important files to trace when fixing editor-to-service bugs. |
| 37 | +- Host ↔ Core: `Copilot for Xcode/` uses `Core` package APIs. Look in `Core/Sources/` for service and host API definitions (Service vs Host separation — `Service` implementations live under `Core`/`Service` and host implementations under `Core`/`HostApp`). |
| 38 | +- Native UI vs server UI: Some tooling and debug UIs are bundled under `Server/` and built via `webpack`. The `Server` bundle is not required to build the macOS app but is used for dev/debugging the language server and web-based UIs. |
| 39 | + |
| 40 | +Examples of common edits/tasks (where to look) |
| 41 | +- Change XPC service name: update `ExtensionService` and `CommunicationBridge` code and the entitlements file (search for `mach-lookup` in the repo). |
| 42 | +- Update app version: edit `Version.xcconfig`. |
| 43 | +- Add server dependency or rebuild UI: `cd Server && npm ci && npm run build`. |
| 44 | +- Local manual install: after `localbuild-app.sh`, copy `build/GitHub Copilot for Xcode.app` into `/Applications` to run and test. |
| 45 | + |
| 46 | +Files to inspect first (fast path) |
| 47 | +- `DEVELOPMENT.md` — local build notes and PATH caveat. |
| 48 | +- `README.md` — user-facing overview and Agent Mode description. |
| 49 | +- `ExtensionService/ServiceDelegate.swift`, `CommunicationBridge/main.swift`, `EditorExtension/SourceEditorExtension.swift` — XPC path. |
| 50 | +- `Version.xcconfig`, `Script/localbuild-app.sh`, `Script/uninstall-app.sh`, `TestPlan.xctestplan`. |
| 51 | +- `Server/package.json` and `Server/src/` for language server/web UI details. |
| 52 | + |
| 53 | +If anything here is out-of-date or you rely on a different workflow (CI-only changes, alternate dev environment), tell me which steps to adjust and I will update this file. |
| 54 | + |
| 55 | +— End of instructions |
0 commit comments