Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,15 @@ restart buttons. `ui/open_in_editor_buttons.dart` draws them,
fork, and `open -a` on it was confirmed against 2.5.5: the folder opened, and
a second call reused the running copy. **macOS only** — where the Windows
installer puts the IDE has not been seen, so there is no Windows button.
Rechecked against `Antigravity.app` 2.9.1: still no document types, `argv`
is only scanned for a URL, and the renderer's one deep-link route is
`antigravity://teleport/ai_studio?blob_id=…&signature=…` (an AI Studio
import). There is no way to hand it a local folder.
- **Codex is `ChatGPT.app`, bundle id `com.openai.codex`.** OpenAI folded the
Codex app into ChatGPT; looking for `Codex.app` found nothing, so the button
never showed. The bundle id is checked (`_EditorApp.bundleId`, read from the
XML `Info.plist`) because an older `ChatGPT.app` is the chat-only
`com.openai.chat`, with no `codex:` scheme. `Codex.app` is still tried.
- **Order is preference order**, and `ProjectStartedDialog` features the first.
OpenCode is last deliberately: it only appears when the box was ticked, but
App Studio already runs it in the Agent tab, so an editor it does *not* have
Expand Down
86 changes: 74 additions & 12 deletions lib/session/external_editors.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,30 @@ import 'project_settings.dart';
/// Picking the wrong door is not loud: `open` exits 0 for an app that launched
/// and dropped the path exactly as it does for one that opened it.
class _EditorApp {
const _EditorApp(this.appName, {this.deepLink, this.cli});
const _EditorApp(
this.appName, {
this.alsoNamed = const [],
this.bundleId,
this.deepLink,
this.cli,
});

/// Bundle name under one of [_applicationDirectories]. Doubles as the
/// installed check, which [deepLink] needs even more than the rest do:
/// `open <scheme>://…` fails *silently* when nothing claims the scheme.
final String appName;

/// Other names the same app has shipped under, tried after [appName].
final List<String> alsoNamed;

/// The `CFBundleIdentifier` a bundle found by name must carry, or null to
/// take the name alone. Needed where a name is shared with a different app:
/// `ChatGPT.app` is the Codex app today and was the plain chat app before.
final String? bundleId;

/// Every name to look for, in order.
List<String> get appNames => [appName, ...alsoNamed];

/// Builds the URL for an app that takes the project as a deep link. Null
/// means it accepts the folder as a document — `open -a <bundle> <path>`.
final Uri Function(String projectPath)? deepLink;
Expand Down Expand Up @@ -74,6 +91,14 @@ class _EditorCli {
/// that takes a project directory. A CLI does not qualify — there is no window
/// to open a folder in, and "open in …" has to mean something visible.
///
/// **Codex is `ChatGPT.app`.** OpenAI folded the Codex desktop app into
/// ChatGPT: the bundle is named `ChatGPT.app`, carries the identifier
/// `com.openai.codex` and claims `codex:`. Looking for `Codex.app` found
/// nothing, so the button never appeared. The identifier is checked because
/// an older `ChatGPT.app` is the chat-only app (`com.openai.chat`), which has
/// no `codex:` scheme; `Codex.app` is still tried for a copy from before the
/// rename.
///
/// **Antigravity is `Antigravity IDE.app`, not `Antigravity.app`.** The latter
/// is a thin Electron shell around a Go language server, with no `open-file`
/// handler and no `CFBundleDocumentTypes`, so a folder handed to it is dropped
Expand All @@ -86,7 +111,12 @@ const _editorApps = <IdeIntegration, _EditorApp>{
IdeIntegration.vscode: _EditorApp('Visual Studio Code'),
IdeIntegration.antigravity: _EditorApp('Antigravity IDE'),
IdeIntegration.claude: _EditorApp('Claude', deepLink: _claudeDeepLink),
IdeIntegration.codex: _EditorApp('Codex', deepLink: _codexDeepLink),
IdeIntegration.codex: _EditorApp(
'ChatGPT',
alsoNamed: ['Codex'],
bundleId: 'com.openai.codex',
deepLink: _codexDeepLink,
),
IdeIntegration.opencode: _EditorApp('OpenCode', deepLink: _openCodeDeepLink),
};

Expand Down Expand Up @@ -231,7 +261,7 @@ class ExternalEditorsController extends ChangeNotifier
required this.session,
required this.process,
Future<Set<IdeIntegration>> Function(String projectPath)? readEditors,
String? Function(String appName)? findApp,
String? Function(String appName, String? bundleId)? findApp,
bool Function(String path)? fileExists,
Future<bool> Function(List<String> command)? launch,
HostPlatform? host,
Expand All @@ -255,15 +285,15 @@ class ExternalEditorsController extends ChangeNotifier
final ProjectReadyView process;

final Future<Set<IdeIntegration>> Function(String projectPath) _readEditors;
final String? Function(String appName) _findApp;
final String? Function(String appName, String? bundleId) _findApp;
final bool Function(String path) _fileExists;
final Future<bool> Function(List<String> command) _launch;

final HostPlatform _host;
final WindowsSystem? _windowsSystem;
final Map<String, String>? _environment;
final Future<bool> Function(String exe, List<String> arguments)
_runElectronCli;
_runElectronCli;

WindowsSystem get _windows => _windowsSystem ?? Win32System();

Expand Down Expand Up @@ -301,10 +331,13 @@ class ExternalEditorsController extends ChangeNotifier
final target = _windowsTargets[editor.id];
if (target == null) return;
launched = switch (target) {
_FoundLink(:final link) =>
_windows.shellOpen(link(projectPath).toString()),
_FoundCli(:final exe, :final script) =>
await _runElectronCli(exe, [script, projectPath]),
_FoundLink(:final link) => _windows.shellOpen(
link(projectPath).toString(),
),
_FoundCli(:final exe, :final script) => await _runElectronCli(exe, [
script,
projectPath,
]),
};
} else {
final resolved = _resolved[editor.id];
Expand Down Expand Up @@ -354,7 +387,12 @@ class ExternalEditorsController extends ChangeNotifier
final configured = await _readEditors(projectPath);
for (final entry in _editorApps.entries) {
if (!configured.contains(entry.key)) continue;
final appPath = _findApp(entry.value.appName);
final app = entry.value;
String? appPath;
for (final name in app.appNames) {
appPath = _findApp(name, app.bundleId);
if (appPath != null) break;
}
if (appPath == null) continue;
editors.add(
ExternalEditor(id: entry.key.option, label: entry.key.label),
Expand Down Expand Up @@ -493,14 +531,38 @@ List<String> _applicationDirectories() => [

bool _defaultFileExists(String path) => File(path).existsSync();

String? _defaultFindApp(String appName) {
String? _defaultFindApp(String appName, String? bundleId) {
for (final dir in _applicationDirectories()) {
final path = p.join(dir, '$appName.app');
if (Directory(path).existsSync()) return path;
if (!Directory(path).existsSync()) continue;
if (bundleId == null || _bundleIdentifier(path) == bundleId) return path;
}
return null;
}

final _bundleIdPattern = RegExp(
r'<key>CFBundleIdentifier</key>\s*<string>([^<]*)</string>',
);

/// The bundle's `CFBundleIdentifier`, read out of its `Info.plist`, or null
/// when it cannot be read.
///
/// XML only. Every editor this is asked about ships an XML plist; a binary one
/// reads as null, which only costs that app its button.
String? _bundleIdentifier(String appPath) {
try {
final plist = File(
p.join(appPath, 'Contents', 'Info.plist'),
).readAsStringSync();
return _bundleIdPattern.firstMatch(plist)?.group(1)?.trim();
} on FileSystemException {
return null;
} on FormatException {
// A binary plist is not UTF-8.
return null;
}
}

/// Runs `[executable, ...arguments]` — an editor's own CLI, or `open` with
/// either `-a <bundle> <path>` or a deep-link URL.
///
Expand Down
85 changes: 63 additions & 22 deletions test/session/external_editors_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ void main() {
'Cursor',
'Visual Studio Code',
'Claude',
'Codex',
'ChatGPT',
'OpenCode',
},
required _FakeSession session,
Expand All @@ -56,7 +56,7 @@ void main() {
session: session,
process: process ?? _FakeProcess(projectIsReady: true),
readEditors: (path) async => editorsByProject[path] ?? const {},
findApp: (name) =>
findApp: (name, bundleId) =>
installedApps.contains(name) ? '/Applications/$name.app' : null,
fileExists: (_) => cliIsPresent,
launch: (command) async {
Expand Down Expand Up @@ -189,7 +189,7 @@ void main() {
? {IdeIntegration.cursor}
: {IdeIntegration.vscode};
},
findApp: (name) => '/Applications/$name.app',
findApp: (name, _) => '/Applications/$name.app',
launch: (_) async => true,
host: HostPlatform.macos,
);
Expand Down Expand Up @@ -339,6 +339,44 @@ void main() {
]);
});

test('finds Codex as ChatGPT.app, the name it ships under now', () async {
final session = _FakeSession()..setPath('/p');
final lookups = <(String, String?)>[];
final editors = ExternalEditorsController(
session: session,
process: _FakeProcess(projectIsReady: true),
readEditors: (_) async => {IdeIntegration.codex},
findApp: (name, bundleId) {
lookups.add((name, bundleId));
return name == 'ChatGPT' ? '/Applications/ChatGPT.app' : null;
},
fileExists: (_) => true,
launch: (_) async => true,
host: HostPlatform.macos,
);
addTearDown(editors.dispose);
await pumpEventQueue();

expect(editors.editors.single.label, 'Codex');
// The identifier is what tells the Codex app from the chat-only ChatGPT.
expect(lookups.first, ('ChatGPT', 'com.openai.codex'));
});

test('still finds Codex under its old name', () async {
final session = _FakeSession()..setPath('/p');
final editors = controller(
session: session,
editorsByProject: {
'/p': {IdeIntegration.codex},
},
installedApps: {'Codex'},
);
addTearDown(editors.dispose);
await pumpEventQueue();

expect(editors.editors.single.label, 'Codex');
});

test('a deep-link editor still has to be installed', () async {
// Unlike `open -a`, `open <scheme>://…` exits 0 when nothing claims the
// scheme, so the bundle check is the only thing standing between the user
Expand Down Expand Up @@ -400,7 +438,7 @@ void main() {
process: _FakeProcess(projectIsReady: true),
readEditors: (path) async => path == project ? configured : const {},
// macOS lookups must never be what decides a Windows editor.
findApp: (_) => fail('looked for a macOS bundle'),
findApp: (_, _) => fail('looked for a macOS bundle'),
fileExists: files.contains,
launch: (_) => fail('launched a macOS command'),
host: HostPlatform.windows,
Expand All @@ -416,24 +454,27 @@ void main() {
);
}

test('hands the folder to Cursor through its CLI, as an argument', () async {
final runs = <List<String>>[];
final editors = windowsController(
configured: {IdeIntegration.cursor},
files: {cursorExe, cursorCli},
cliRuns: runs,
);
addTearDown(editors.dispose);
await pumpEventQueue();

expect(editors.editors.map((e) => e.id), ['cursor']);
await editors.open(editors.editors.single);
// The folder is one argument to a real `.exe` — never a `.cmd` line
// that cmd.exe would re-parse, spaces and all.
expect(runs, [
[cursorExe, cursorCli, project],
]);
});
test(
'hands the folder to Cursor through its CLI, as an argument',
() async {
final runs = <List<String>>[];
final editors = windowsController(
configured: {IdeIntegration.cursor},
files: {cursorExe, cursorCli},
cliRuns: runs,
);
addTearDown(editors.dispose);
await pumpEventQueue();

expect(editors.editors.map((e) => e.id), ['cursor']);
await editors.open(editors.editors.single);
// The folder is one argument to a real `.exe` — never a `.cmd` line
// that cmd.exe would re-parse, spaces and all.
expect(runs, [
[cursorExe, cursorCli, project],
]);
},
);

test('finds a machine-wide VS Code under Program Files', () async {
const code = r'C:\Program Files\Microsoft VS Code\Code.exe';
Expand Down
Loading