Skip to content

The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.

fix(desktop): a New Harness with files reaches a Codex 0.154 harness (#1406)

Jacob Phamf4b391679e03
diff --git a/desktop/lib/state/attached_task_delivery.dart b/desktop/lib/state/attached_task_delivery.dart
index a11873465..09187e459 100644
--- a/desktop/lib/state/attached_task_delivery.dart
+++ b/desktop/lib/state/attached_task_delivery.dart
@@ -17,36 +17,55 @@ const kAttachedTaskSettle = Duration(milliseconds: 800);
/// Codex can be alive in its updater before it opens a conversation. An empty
/// chat may not have a session ID yet either. Read only the visible terminal,
-/// looking for its composer and footer together, not a menu's selected row or
-/// an old prompt in scrollback.
+/// looking for its composer as the last thing drawn, not a menu's selected row
+/// or an old prompt in scrollback.
enum _CodexStartup { waiting, updating, ready }
+/// Codex's composer row (CLI engines/codex/composer.ts), never a numbered row
+/// of a menu: a trust, hooks or update question selects its first row with `›`.
+final _codexComposer = RegExp(r'^\s*›(?:\s|$)');
+final _codexMenuRow = RegExp(r'^\s*[›>]?\s*\d+\.\s');
+
+/// Under the composer Codex draws only its footer, at most a few rows. More
+/// is some other screen below a prompt left in the conversation.
+const _codexFooterRows = 3;
+
+/// Codex updating itself: its update question, or the updater running. Not
+/// the "✨ Update available!" box a ready Codex 0.154 draws above its chat —
+/// read as an update, it cancelled the open timeout and the files waited
+/// forever.
+final _codexUpdating = RegExp(
+ r'^\s*[›>]?\s*1\. Update now|Updating Codex via|Update ran successfully! Please restart Codex\.',
+ multiLine: true,
+);
+
_CodexStartup _codexStartup(Terminal terminal) {
final buffer = terminal.buffer;
final lines = [
for (var row = buffer.scrollBack; row < buffer.height; row++)
buffer.lines[row].getText(),
];
- final prompt = lines.lastIndexWhere(
- (line) => RegExp(r'^\s*›').hasMatch(line),
- );
- if (prompt >= 0 &&
- lines
- .skip(prompt + 1)
- .any(
- (line) =>
- RegExp(r'\? for shortcuts|\d+% context left').hasMatch(line),
- )) {
- return _CodexStartup.ready;
- }
- if (RegExp(
- r'Update available!|Updating Codex via|Update ran successfully! Please restart Codex\.',
- ).hasMatch(lines.join('\n'))) {
- return _CodexStartup.updating;
- }
+ if (_codexComposerIsLast(lines)) return _CodexStartup.ready;
+ if (_codexUpdating.hasMatch(lines.join('\n'))) return _CodexStartup.updating;
return _CodexStartup.waiting;
}
+/// The composer with only a footer under it. Its footer's words are not
+/// relied on: Codex 0.154 replaced `? for shortcuts` and `% context left`
+/// with a status line (`gpt-5.5 default · ~/project`), and a harness given a
+/// picture never received it or its task (2026-10-18).
+bool _codexComposerIsLast(List<String> lines) {
+ final composer = lines.lastIndexWhere(
+ (line) => _codexComposer.hasMatch(line) && !_codexMenuRow.hasMatch(line),
+ );
+ if (composer < 0) return false;
+ final footer = lines
+ .skip(composer + 1)
+ .where((line) => line.trim().isNotEmpty);
+ return footer.length <= _codexFooterRows &&
+ !footer.any(_codexMenuRow.hasMatch);
+}
+
/// Can [machineId] take files into a harness's prompt? Both halves are the
/// daemon's: a file written there and its path pasted, then a space pasted.
bool canAttachFiles(AppNotifier app, String machineId) {
diff --git a/desktop/test/harness_attachments_test.dart b/desktop/test/harness_attachments_test.dart
index e0ce6c5d0..72882ad55 100644
--- a/desktop/test/harness_attachments_test.dart
+++ b/desktop/test/harness_attachments_test.dart
@@ -18,6 +18,28 @@ const _codexComposer =
'\u001b[1m›\u001b[0m \u001b[2mAsk Codex to do anything\u001b[0m\r\n'
'\r\n GPT-6-Astra · /tmp/work\r\n ? for shortcuts';
+/// A ready Codex 0.154 as captured in its pane (2026-10-18): the update box
+/// is only news, and the footer is a status line with no shortcut hint.
+const _codex154Ready =
+ '╭─────────────────────────────────────────╮\r\n'
+ '│ ✨ Update available! 0.154.0 -> 0.163.0 │\r\n'
+ '╰─────────────────────────────────────────╯\r\n'
+ '╭─────────────────────────────────────╮\r\n'
+ '│ >_ OpenAI Codex (v0.154.0) │\r\n'
+ '╰─────────────────────────────────────╯\r\n'
+ '\r\n⚠ 1 MCP startup issue · ctrl + t for details\r\n'
+ '\r\n\u001b[1m›\u001b[0m \u001b[2mAsk Codex to do anything\u001b[0m\r\n'
+ '\r\n gpt-5.5 default · ~/harnesses/worktrees/autonomous-harness/fix';
+
+/// Codex 0.154's question about hooks it has not seen, before any chat.
+const _codexHooksReview =
+ ' Hooks need review\r\n'
+ ' 3 hooks are new or changed.\r\n'
+ '\r\n› 1. Review hooks\r\n'
+ ' 2. Trust all and continue\r\n'
+ ' 3. Continue without trusting (hooks won\'t run)\r\n'
+ '\r\n Press enter to confirm or esc to go back';
+
/// Records what a harness's terminal was handed, in order.
class _RecordingSession extends TerminalSession {
_RecordingSession()
@@ -224,6 +246,54 @@ void main() {
},
);
+ testWidgets('hands a ready Codex 0.154 its picture and task', (
+ tester,
+ ) async {
+ final app = _app(engine: 'codex');
+ addTearDown(app.dispose);
+ final session = _RecordingSession();
+ session.terminal.write(_codex154Ready);
+ app.adoptSessionForTest(session);
+ String? problem = 'pending';
+ unawaited(
+ deliverAttachedTask(
+ app,
+ machineId: 'box',
+ agentId: 'a1',
+ files: [_file('pasted-image.png')],
+ task: 'hi',
+ ).then((value) => problem = value),
+ );
+ await tester.pump(kAttachedTaskSettle + const Duration(milliseconds: 10));
+ await tester.pump();
+ expect(problem, isNull);
+ expect(session.calls, ['file:pasted-image.png', 'paste: ', 'send:hi']);
+ });
+
+ testWidgets('pastes nothing into a Codex question and gives up in time', (
+ tester,
+ ) async {
+ final app = _app(engine: 'codex');
+ addTearDown(app.dispose);
+ final session = _RecordingSession();
+ session.terminal.write(_codexHooksReview);
+ app.adoptSessionForTest(session);
+ String? problem = 'pending';
+ unawaited(
+ deliverAttachedTask(
+ app,
+ machineId: 'box',
+ agentId: 'a1',
+ files: [_file('pasted-image.png')],
+ task: 'hi',
+ ).then((value) => problem = value),
+ );
+ await tester.pump(kAttachedTaskOpenTimeout + const Duration(seconds: 1));
+ await tester.pump();
+ expect(session.calls, isEmpty);
+ expect(problem, contains('did not open in time'));
+ });
+
test('files first, each followed by a space, then the task', () async {
final app = _app();
addTearDown(app.dispose);