From 1757b5cdc078bdf5b2f73760db317795965d3430 Mon Sep 17 00:00:00 2001 From: Vinh Lam Phuoc Date: Thu, 5 Nov 2026 21:05:18 +0700 Subject: [PATCH 1/3] Fix: allow folders with quotes, $ or ! in the name cwd only reaches Tern as the `tern new --cwd` argv element (no shell text), so only control characters are refused now. --- lib/mgr_form.luau | 6 +++--- lib/validate.luau | 4 ++-- test/golden/runner_cwd_quotes.txt | 3 +++ test/runner_cwd_quotes.luau | 25 +++++++++++++++++++++++++ 4 files changed, 33 insertions(+), 5 deletions(-) create mode 100644 test/golden/runner_cwd_quotes.txt create mode 100644 test/runner_cwd_quotes.luau diff --git a/lib/mgr_form.luau b/lib/mgr_form.luau index 96785bf..cb293ac 100644 --- a/lib/mgr_form.luau +++ b/lib/mgr_form.luau @@ -337,7 +337,7 @@ function F.refresh_roles(state: State) return end local cwd = expand(form.folder.text) - if cwd == "" or string.sub(cwd, 1, 1) ~= "/" or validate.unsafe_path(cwd) then + if cwd == "" or string.sub(cwd, 1, 1) ~= "/" or cwd:find("%c") ~= nil then form.roles_for = nil form.roles = nil form.roles_err = nil @@ -371,7 +371,7 @@ function F.refresh_branches(state: State) return end local cwd = expand(form.folder.text) - if cwd == "" or string.sub(cwd, 1, 1) ~= "/" or validate.unsafe_path(cwd) then + if cwd == "" or string.sub(cwd, 1, 1) ~= "/" or cwd:find("%c") ~= nil then form.branches_for = nil form.branches = nil form.branches_err = nil @@ -405,7 +405,7 @@ local function check_folder(state: State, cb: ((boolean) -> ())?) return end local path = expand(form.folder.text) - if path == "" or string.sub(path, 1, 1) ~= "/" or validate.unsafe_path(path) then + if path == "" or string.sub(path, 1, 1) ~= "/" or path:find("%c") ~= nil then return end if form.folder_ok ~= nil and form.folder_ok.path == path then diff --git a/lib/validate.luau b/lib/validate.luau index 6002c92..6de3782 100644 --- a/lib/validate.luau +++ b/lib/validate.luau @@ -38,7 +38,7 @@ export type Ctx = { local MIN_INTERVAL_COPY = "Agent runs shorter than 5 minutes apart tend to overlap. Use every 5m or more." local HOME_COPY = "omp may work in a temporary folder instead of your home folder. Pick a project folder for predictable results." -local UNSAFE_COPY = "Folders with quotes, $ or ! in the name aren't supported yet." +local UNSAFE_COPY = "Folder names can't contain control characters (like a newline)." local RUNTIME_COPY = "Use a time like 45m or 2h (up to 8h)." local function trim(s: string): string @@ -298,7 +298,7 @@ function validate.job(fields: JobInput, ctx: Ctx): (boolean, { [string]: string errs.cwd = "Use a full folder path starting with / or ~." elseif #p > 1024 then errs.cwd = "That folder path is too long." - elseif validate.unsafe_path(p) then + elseif p:find("%c") ~= nil then -- cwd only travels as an argv element (`tern new --cwd`), never shell text errs.cwd = UNSAFE_COPY else local allow = fields.allow_home diff --git a/test/golden/runner_cwd_quotes.txt b/test/golden/runner_cwd_quotes.txt new file mode 100644 index 0000000..1f44ed2 --- /dev/null +++ b/test/golden/runner_cwd_quotes.txt @@ -0,0 +1,3 @@ +PASS quoted folder saves +PASS control characters refused +PASS launch argv carries the folder diff --git a/test/runner_cwd_quotes.luau b/test/runner_cwd_quotes.luau new file mode 100644 index 0000000..002e17b --- /dev/null +++ b/test/runner_cwd_quotes.luau @@ -0,0 +1,25 @@ +-- A folder with ' $ ! and spaces saves and launches: cwd reaches `tern new --cwd` as one verbatim argv element. +local jobs, runner = __mods.jobs, __mods.runner + +local CWD = "/Volumes/VINH MAC/VINH's WORKS/2026/T11-2026/084 MAPPING - TPHCM $NOV! 22-24" +fake.dirs[CWD] = true +fake.set_wall(fake.chicago(2026, 10, 12, 8, 59, 30)) + +runner.load() +fake.advance(1000) +local job, errs = jobs.create({ name = "mapping", prompt = "x", when = "0 9 * * *", cwd = CWD }, "x", "user", os.time()) +assert(job ~= nil, "quoted folder saves: " .. tostring(errs and errs.cwd)) +assert(job.cwd == CWD, "cwd stored verbatim") +print("PASS quoted folder saves") + +local _, nl = jobs.create({ name = "nl", prompt = "x", when = "0 9 * * *", cwd = "/tmp/a\nb" }, "x", "user", os.time()) +assert(nl ~= nil and nl.cwd ~= nil, "control characters still refused") +print("PASS control characters refused") + +assert(fake.run_until(function() + return #fake.calls_of("new") >= 1 +end, 120000, 1000), "job launched") +local argv = fake.calls_of("new")[1] +local at = table.find(argv, "--cwd") +assert(at ~= nil and argv[at + 1] == CWD, "cwd is one verbatim argv element") +print("PASS launch argv carries the folder") From 712b1f0450d35178d871dbd9cbca0ea76acd1c4b Mon Sep 17 00:00:00 2001 From: Vinh Lam Phuoc Date: Thu, 5 Nov 2026 21:05:40 +0700 Subject: [PATCH 2/3] Fix: Stop after menu offers 6 and 8 hours (validator allows up to 8h) --- lib/mgr_common.luau | 2 ++ test/golden/runner_form.txt | 1 + test/runner_form.luau | 9 +++++++++ 3 files changed, 12 insertions(+) diff --git a/lib/mgr_common.luau b/lib/mgr_common.luau index 008fa21..742b1f7 100644 --- a/lib/mgr_common.luau +++ b/lib/mgr_common.luau @@ -177,6 +177,8 @@ C.STOPS = { { s = 3600, label = "1 hour" }, { s = 7200, label = "2 hours" }, { s = 14400, label = "4 hours" }, + { s = 21600, label = "6 hours" }, + { s = 28800, label = "8 hours" }, } function C.trim(s: string): string diff --git a/test/golden/runner_form.txt b/test/golden/runner_form.txt index 4285422..f59d8d6 100644 --- a/test/golden/runner_form.txt +++ b/test/golden/runner_form.txt @@ -2,3 +2,4 @@ PASS all-off conditions collapse; Check now absent and inert PASS every toggle reveals dependents, preserves drafts and keyboard order PASS collapsing clears stale Check now results PASS compact missed-run labels preserve threshold and policy +PASS stop menu covers 5 min to 8 hours diff --git a/test/runner_form.luau b/test/runner_form.luau index d896035..58517a0 100644 --- a/test/runner_form.luau +++ b/test/runner_form.luau @@ -60,3 +60,12 @@ assert(row.control.options[1].label == "Run once if under 90m late") assert(row.control.options[2].label == "Run once, however late") assert(row.control.options[3].label == "Skip missed runs") print("PASS compact missed-run labels preserve threshold and policy") + +-- Stop after menu reaches the validator's limit, and every choice validates. +local STOPS, const = __mods.mgr_common.STOPS, __mods.const +assert(STOPS[#STOPS].s == const.MAXRUN_MAX_S, "longest stop is the 8h limit") +for _, o in STOPS do + local ok, errs = __mods.validate.job({ max_runtime_s = o.s }, { jobs = {}, now = 0, home = "/home/u" }) + assert(ok, o.label .. " validates: " .. tostring(errs and errs.max_runtime_s)) +end +print("PASS stop menu covers 5 min to 8 hours") From 59cf5c74dd8ca78aa8f2edddc7abd296a8fcc54a Mon Sep 17 00:00:00 2001 From: Vinh Lam Phuoc Date: Thu, 5 Nov 2026 21:10:20 +0700 Subject: [PATCH 3/3] Fix: job form fields stay reachable after a validation error Tab/shift+tab leave the prompt editor keeping its text (it swallowed Tab), and a click on another row finishes an open text edit instead of being ignored. --- lib/mgr_form.luau | 11 ++++++++--- test/golden/runner_form.txt | 1 + test/runner_form.luau | 21 +++++++++++++++++++++ 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/lib/mgr_form.luau b/lib/mgr_form.luau index cb293ac..37ea528 100644 --- a/lib/mgr_form.luau +++ b/lib/mgr_form.luau @@ -1871,7 +1871,7 @@ end local function base_hints(cols: number, editing: string?): string if editing == "prompt" then - return if cols < 56 then "^⏎ done · esc revert" else "⏎ newline · ^⏎ done · esc revert" + return if cols < 56 then "^⏎ done · esc revert" else "⏎ newline · ^⏎ done · ⇥ next · esc revert" elseif editing ~= nil then return if cols < 56 then "⏎ done · ^⏎ save" else "⏎ done · ^⏎ save · esc revert" elseif cols < 56 then @@ -1940,7 +1940,7 @@ function F.view(state: State): (Node, Node) maxLines = 14, placeholder = "What should the agent do? Say what to do if something is unclear.", }), - C.text({ ui.span("⏎ newline · ^⏎ done · esc revert", "muted") }, "keys"), + C.text({ ui.span("⏎ newline · ^⏎ done · ⇥ next · esc revert", "muted") }, "keys"), } table.insert(children, C.with(ui.col(ed), { key = "pe", role = "omp.prefs.editor" })) end @@ -2017,7 +2017,7 @@ local function key_text(state: State, k: Key): boolean F.save(state, k.shift) end return true - elseif name == "tab" and not multi then + elseif name == "tab" then stop_edit(state, false) set_focus(state, P.move(F.sections(state), e.row, if k.shift then -1 else 1) or e.row) return true @@ -2327,6 +2327,11 @@ function F.event(state: State, ev: UiEvent) end activate(state, item) elseif kind == "select" and type(item) == "string" and string.find(item, "=", 1, true) == nil then + -- A click on another row finishes the open edit (keeping it), so no field traps focus. + local e = form.editing + if e ~= nil and e.row ~= item and P.find(F.sections(state), item) ~= nil then + stop_edit(state, false) + end if form.editing == nil and form.menu == nil then form.focus = item end diff --git a/test/golden/runner_form.txt b/test/golden/runner_form.txt index f59d8d6..c2c1742 100644 --- a/test/golden/runner_form.txt +++ b/test/golden/runner_form.txt @@ -3,3 +3,4 @@ PASS every toggle reveals dependents, preserves drafts and keyboard order PASS collapsing clears stale Check now results PASS compact missed-run labels preserve threshold and policy PASS stop menu covers 5 min to 8 hours +PASS no focus trap after a validation error diff --git a/test/runner_form.luau b/test/runner_form.luau index 58517a0..a79224d 100644 --- a/test/runner_form.luau +++ b/test/runner_form.luau @@ -69,3 +69,24 @@ for _, o in STOPS do assert(ok, o.label .. " validates: " .. tostring(errs and errs.max_runtime_s)) end print("PASS stop menu covers 5 min to 8 hours") + +-- After a validation error, the prompt editor and text fields never trap focus. +do + local f2 = F.new({ name = "Trap", prompt = "", cwd = "/home/u/proj" }, nil, "New job") + local s2 = { form = f2, cx = { render = function() end, focus = function() end, cols = 100 } } + F.save(s2, false) + assert(f2.focus == "prompt" and f2.submitted, "error sends focus to Prompt") + F.key(s2, { name = "enter" }) + assert(f2.editing ~= nil and f2.editing.row == "prompt", "enter opens the prompt editor") + F.key(s2, { name = "h", text = "h" }) + F.key(s2, { name = "tab" }) + assert(f2.editing == nil and f2.focus == "when" and f2.prompt.text == "h", "tab leaves the prompt editor, keeping text") + F.key(s2, { name = "tab", shift = true }) + assert(f2.focus == "prompt", "shift+tab moves back") + F.key(s2, { name = "down" }) + F.key(s2, { name = "enter" }) + assert(f2.editing ~= nil and f2.editing.row == "when", "When is editable") + F.event(s2, { ev = "select", id = "main.prefs", item = "folder" }) + assert(f2.editing == nil and f2.focus == "folder", "a click on Folder leaves the When edit") +end +print("PASS no focus trap after a validation error")