Repository navigation
engine: add a native file-open dialog with Lua path grants - #5140
Merged
Merged
Conversation
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
commented
Nov 17, 2026
jakildev
left a comment
Owner
Author
There was a problem hiding this comment.
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 allocateslength - 1bytes and then passeslengthas the destination capacity, so every non-empty selected path writes one byte paststd::string's size. Allocatelength, 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 askszenityto 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/otheris therefore parsed as two paths; if the injected absolute suffix exists,grantFileDialogPathsgrants 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-buildand aggregateall-checkswere still pending when reviewed. - Local macOS
fleet-build --detach --target IrredenEngineTestcompiled 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).
…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>
Owner
Author
|
Addressed feedback (2908a1d):
|
9 tasks done
jakildev
commented
Nov 17, 2026
jakildev
left a comment
Owner
Author
There was a problem hiding this comment.
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 at2908a1daa. - ✅
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 at2908a1daa.
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
7a4f987bthat file selection prints the full separator string between items and one final newline, matching the new parser contract. - Local macOS
IrredenEngineTesttarget 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-buildand aggregateall-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).
16 of 18 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
IREngine::openFileDialogand the opt-in LuaIRDialog.openshow 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.--auto-screenshot/--auto-record), an unattended window mode or a call off the main thread returnsREFUSEDand opens nothing.IRFilereads,IRGuiandIRCanvasimage loads): a picked file alone, a picked folder's subtree, read-only, for the session. Every other path is confined as before.IRFile.listlets a script enumerate a picked folder.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 IRLuaWidgetsDemopasses 37 of 37 assertions with the flag off.Platforms
NSOpenPanelare unverified.file_dialog_win32.cpp(IFileOpenDialog) has never been compiled or run, including thenarrow/widenbounds fix in 2908a1d.file_dialog_linux.cpp(zenity) passesclang++ -fsyntax-onlyon macOS only (re-run at 2908a1d with the build's flags); never built with gcc, never run. Its output parsing is the puredetail::parseZenityOutput, which the suite covers on every host.Test plan
fleet-run --timeout 900 IrredenEngineTest --gtest_brief=1on macOS, rebased on a914699: 4065 passed, 3 skipped,RESULT=CLEANpython3 scripts/gui-verify.py IRLuaWidgetsDemo: 37/37 assertions passedfleet-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=CLEANfleet-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=CLEANfleet-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 atFILEDIALOG before frame=54 tick=29for the whole 150 s; the watchdog ended the run (RESULT=ALIVE-TIMEOUT)fleet-run IrredenEngineTest --gtest_filter='FileDialog*:RunFileDialog*:PathGrants*:ResolveReadablePath*:*Dialog*': 44 passed, includingFileDialogBackendArguments.NewlinesInsideAPathNeverSplitItand.ANewlineBearingPickGrantsOnlyItself(a real<root>/picked/name\n<outside path>file on APFS grants itself only; the outside file stays unresolvable)parseZenityOutputforced back to the newline separator,ParsesZenityOutput,NewlinesInsideAPathNeverSplitItandANewlineBearingPickGrantsOnlyItselffail; restored and rebuilt before the run abovecmake -P cmake/run_header_checks_standalone.cmake,scripts/lint_comment_refs.py,scripts/lint_instruction_refs.py --against origin/master: cleanReviewer notes
Notes for reviewer
IRLuaWidgetsDemoruns were taken before the rebase onto a914699; the fixture and the dialog code did not change afterwards, except thatIRCanvas.loadImage(new on master) now honors the grants too.FILEDIALOG closed frame=54 tick=29 status=ACCEPTED paths=1followed bypath[1]=... bytes=N.scripts/lint_instruction_size.py --against origin/masterannotatesengine/script/CLAUDE.md(18409 bytes, budget 17883, +526, inside the 800-byte band). The file was already 18142 bytes on master; this change adds 267.fileDialogArrayrepeats the dense-Lua-array walk inhand_off.cpp::parseArgv; thezenityspawn repeats part ofengine/process_spawn.cpp, which sits aboveengine/windowin the link order;widenduplicates the file-local one inprocess_spawn.cpp.fleet-pr-overlap --base master:VERDICT: overlap, every shared path a clean trial merge:test/CMakeLists.txtengine/world/include/irreden/world.hppengine/world/src/world.cpp🤖 Generated with Claude Code