Skip to content

engine: add a native file-open dialog with Lua path grants - #5140

Merged
jakildev merged 3 commits into
masterfrom
claude/elegant-lamport-0f0fce
Nov 17, 2026
Merged

jakildev merged 3 commits into
masterfrom
claude/elegant-lamport-0f0fce

Conversation

@jakildev

@jakildev jakildev commented Nov 17, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • IREngine::openFileDialog and the opt-in Lua IRDialog.open show the host's native "open" panel: one file, several files or a folder, with a title, a starting directory and extension filters. They return the chosen absolute paths, or an empty list with a status.
  • The call is modal on the main thread. No update or render runs while the panel is open, and the loop clock is re-baselined when it closes. A capture run (--auto-screenshot / --auto-record), an unattended window mode or a call off the main thread returns REFUSED and opens nothing.
  • What the user picks is granted to that script's confined readers (IRFile reads, IRGui and IRCanvas image loads): a picked file alone, a picked folder's subtree, read-only, for the session. Every other path is confined as before. IRFile.list lets a script enumerate a picked folder.
  • Decisions are in docs/design/native-file-dialog.md.

Screenshots

No visual change intended: the demo edit registers an off-by-default flag (--file-dialog-fixture), and no before/after pair was captured. python3 scripts/gui-verify.py IRLuaWidgetsDemo passes 37 of 37 assertions with the flag off.

Platforms

Host State
macOS (Metal) Built; suite green. The panel opened on the engine window. Its buttons were not pressed: this session has no Accessibility or Screen Recording permission, so the accept and cancel return paths on the real NSOpenPanel are unverified.
Windows (MSYS2 mingw64) file_dialog_win32.cpp (IFileOpenDialog) has never been compiled or run, including the narrow / widen bounds fix in 2908a1d.
Linux file_dialog_linux.cpp (zenity) passes clang++ -fsyntax-only on macOS only (re-run at 2908a1d with the build's flags); never built with gcc, never run. Its output parsing is the pure detail::parseZenityOutput, which the suite covers on every host.

Test plan

  • fleet-run --timeout 900 IrredenEngineTest --gtest_brief=1 on macOS, rebased on a914699: 4065 passed, 3 skipped, RESULT=CLEAN
  • python3 scripts/gui-verify.py IRLuaWidgetsDemo: 37/37 assertions passed
  • fleet-run --timeout 60 IRLuaWidgetsDemo --file-dialog-fixture auto (unattended, background window): status=REFUSED error=window mode 'background' has nobody to answer a file dialog, RESULT=CLEAN
  • fleet-run --timeout 60 IRLuaWidgetsDemo --file-dialog-fixture auto --auto-screenshot 3 --window-mode normal: status=REFUSED error=a capture run never opens a file dialog, RESULT=CLEAN
  • fleet-run --timeout 150 IRLuaWidgetsDemo --file-dialog-fixture auto --window-mode normal: a second 880x448 window owned by the demo, centered on its 1280x752 window; the log stops at FILEDIALOG before frame=54 tick=29 for the whole 150 s; the watchdog ended the run (RESULT=ALIVE-TIMEOUT)
  • At 2908a1d: fleet-run IrredenEngineTest --gtest_filter='FileDialog*:RunFileDialog*:PathGrants*:ResolveReadablePath*:*Dialog*': 44 passed, including FileDialogBackendArguments.NewlinesInsideAPathNeverSplitIt and .ANewlineBearingPickGrantsOnlyItself (a real <root>/picked/name\n<outside path> file on APFS grants itself only; the outside file stays unresolvable)
  • Positive control: with parseZenityOutput forced back to the newline separator, ParsesZenityOutput, NewlinesInsideAPathNeverSplitIt and ANewlineBearingPickGrantsOnlyItself fail; restored and rebuilt before the run above
  • cmake -P cmake/run_header_checks_standalone.cmake, scripts/lint_comment_refs.py, scripts/lint_instruction_refs.py --against origin/master: clean
Reviewer notes

Notes for reviewer

🤖 Generated with Claude Code

jakildev and others added 2 commits November 17, 2026 10:33
IREngine::openFileDialog shows the host's native open panel for one
file, several files or a folder, with a title, a starting directory and
extension filters. The panels live in engine/window (NSOpenPanel as a
sheet on the engine window, IFileOpenDialog, zenity on Linux), one
source per host, behind runFileDialog, which validates the request and
refuses to open anything in a capture run, outside a normal window, or
off the main thread. World owns the modal call and re-baselines the
loop clock when the panel closes.

Lua gets the opt-in IRDialog.open. Each path the user picks is granted
to that script's confined readers (IRFile reads, IRGui image paths)
through a per-LuaScript PathGrants set: a picked file alone, a picked
folder's subtree, read-only, for the session. Containment for every
other path is unchanged. IRFile.list lets a script enumerate a picked
folder.

Only the macOS panel has been built and opened; the Windows and Linux
sources have not been compiled on their hosts.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
IRCanvas.loadImage is a confined image loader like the IRGui image
widget, so it accepts an absolute path only when the script's grant set
holds it. The script CLAUDE.md entry for IRDialog shrinks to a pointer
at the design doc to stay near the file's byte budget.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@jakildev jakildev added fleet:author-claude Implementation last authored by Claude; route review to Codex fleet:authored-on-macos PR was authored and smoke-tested on macOS Metal backend labels Nov 17, 2026

@jakildev jakildev left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Review — engine: add a native file-open dialog with Lua path grants

Verdict: needs-fix

The modal/lifetime design and the confined-reader integration are coherent, but the two unverified host backends contain one memory-safety defect and one path-grant boundary defect.

Blockers

  • engine/window/src/file_dialog_win32.cpp::narrow — WideCharToMultiByte(..., -1, ...) reports and writes a count that includes the terminating NUL. The function allocates length - 1 bytes and then passes length as the destination capacity, so every non-empty selected path writes one byte past std::string's size. Allocate length, perform the conversion, then remove the terminator (and check both conversion calls) before returning the UTF-8 path.

Needs-fix

  • engine/window/src/file_dialog_linux.cpp::platformOpenFileDialog / file_dialog.cpp::parseZenityOutput — the backend asks zenity to join selected filenames with a newline and then treats every newline-delimited segment as an independently selected path. Newline is legal in a Unix filename. A selected path such as <picked>/name\n/tmp/other is therefore parsed as two paths; if the injected absolute suffix exists, grantFileDialogPaths grants a file the user did not select. Use an output encoding/framing that cannot alias filename bytes (or otherwise remove this ambiguous multi-select route), and add a regression that proves a delimiter-bearing filename cannot mint another grant.

Checked

  • Read the complete PR body, commit list, changed-file list, comments, reviews, and inline-review thread at head 17377ff2194db4a95706c4f39eb8727a115447d1; there was no prior discussion.
  • Reviewed the dialog normalization, Cocoa/Win32/zenity backends, world/modal clock gate, Lua option validation, grant containment, confined readers, and the new tests against the module instructions and opus-only lifetime checks.
  • GitHub checks: all completed lint/format/header/fleet gates passed; linux-build and aggregate all-checks were still pending when reviewed.
  • Local macOS fleet-build --detach --target IrredenEngineTest compiled the changed Cocoa/window, world, script, and grant sources, but I stopped the full test-target rebuild before completion; terminal result: fleet-jobs: 20261117T190938Z-build-6487d1 killed exit=143. This is not a passing build claim.

Test plan the author should run before merge

  • Build and exercise the Win32 backend after fixing narrow, including a non-ASCII selected path under ASan or an equivalent bounds check.
  • Build and exercise the Linux backend with single and multiple selections, including a filename containing the chosen output delimiter, and prove only user-selected paths become grants.

🤖 Reviewed by Codex GPT-5 (runtime: codex; review class: opus; review-pr skill)

Opus recheck not required (reviewed at opus class).

@jakildev jakildev added fleet:needs-fix Fleet reviewer found issues — author must address and removed fleet:reviewing-mac-pool-1 labels Nov 17, 2026
@jakildev jakildev removed the fleet:needs-fix Fleet reviewer found issues — author must address label Nov 17, 2026
…rflow

The Win32 narrow() sized its buffer one byte short of the count
WideCharToMultiByte writes with a -1 source length, writing the NUL past
std::string's size on every pick. Allocate the full count, check both
conversion calls, and drop a path whose conversion fails.

The zenity backend joined multiple picks with a newline, a legal
filename byte, so a picked `<dir>/name\n/tmp/other` parsed as two picks
and granted the second. A single selection is now the whole output less
zenity's trailing newline; a multiple selection splits on a per-call
random separator ('\n' + 32 hex digits) that no path can hold without
guessing it. Regressions cover the parse and the grant end with a real
newline-bearing file.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jakildev jakildev added fleet:changes-made Agent addressed human feedback — ready for human re-review and removed fleet:amending-mac-pool-4 labels Nov 17, 2026
@jakildev

Copy link
Copy Markdown
Owner Author

Addressed feedback (2908a1d):

  • Blocker: Win32 narrow wrote one byte past std::string's size. It now allocates the full NUL-inclusive count, checks both WideCharToMultiByte calls, and resizes to written - 1. A failed conversion returns empty and the caller drops that path. widen checks both of its calls the same way. Not compiled: this host has no Win32 toolchain, so the reviewer's ASan run on Windows is still open (the PR body's Platforms row says so).
  • Needs-fix: a newline-bearing zenity pick could mint a second grant. Single selections no longer split at all: the path is the whole output minus zenity's trailing newline. OPEN_FILES joins on a separator generated per call ('\n' followed by 32 hex digits from std::random_device), so a path can only contain it by guessing 128 bits. The separator's first character appears nowhere else in it, so a match cannot start inside the preceding path. zenityArguments and parseZenityOutput both take the separator; parseZenityOutput also takes the mode. Regressions: NewlinesInsideAPathNeverSplitIt covers the parse; ANewlineBearingPickGrantsOnlyItself picks a real <root>/picked/name\n<outside path> file and asserts it grants only itself. Both fail against the old newline framing (positive control in the body). The design doc's Linux bullet records the framing.
  • Linux backend re-syntax-checked with clang++ -fsyntax-only and the build's flags on macOS; never built with gcc or run under zenity.

@jakildev jakildev removed the fleet:changes-made Agent addressed human feedback — ready for human re-review label Nov 17, 2026

@jakildev jakildev left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Review — engine: add a native file-open dialog with Lua path grants

Verdict: approve

The amend resolves both prior findings without broadening the executable delta.

Prior-review resolution

  • ✅ engine/window/src/file_dialog_win32.cpp::narrow — the NUL-inclusive conversion now owns a NUL-inclusive buffer, checks the conversion result, and removes the terminator only after a successful write; verified fixed at 2908a1daa.
  • ✅ engine/window/src/file_dialog_linux.cpp::platformOpenFileDialog / file_dialog.cpp::parseZenityOutput — single picks preserve embedded newlines, multi-picks use one per-call 128-bit separator for both Zenity and parsing, and the grant regression proves an embedded absolute suffix is not minted as a second grant; verified fixed at 2908a1daa.

Checked

  • Re-reviewed the sole post-review commit and all six changed files against the prior findings; no unrelated executable change was added.
  • Confirmed from GNOME Zenity source at 7a4f987b that file selection prints the full separator string between items and one final newline, matching the new parser contract.
  • Local macOS IrredenEngineTest target build completed successfully: fleet-jobs: 20261117T193624Z-build-b7b11b succeeded exit=0.
  • Local FileDialogBackendArguments.*: 5 tests passed, including the newline parse and grant regressions.
  • GitHub checks were green except linux-build and aggregate all-checks, which were still pending when reviewed; the Win32 backend remains cross-host smoke debt as disclosed in the PR body.

🤖 Reviewed by Codex GPT-5 (runtime: codex; review class: opus; review-pr skill)

Opus recheck not required (reviewed at opus class).

@jakildev jakildev added fleet:approved Fleet reviewer approved — ready for human merge fleet:needs-windows-smoke PR needs windows-debug build + smoke-run validation and removed fleet:reviewing-mac-pool-3 labels Nov 17, 2026
@jakildev
jakildev merged commit 9dffe61 into master Nov 17, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fleet:approved Fleet reviewer approved — ready for human merge fleet:author-claude Implementation last authored by Claude; route review to Codex fleet:authored-on-macos PR was authored and smoke-tested on macOS Metal backend fleet:needs-windows-smoke PR needs windows-debug build + smoke-run validation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant