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
2 changes: 2 additions & 0 deletions lib/mgr_common.luau
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 11 additions & 6 deletions lib/mgr_form.luau
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/validate.luau
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions test/golden/runner_cwd_quotes.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
PASS quoted folder saves
PASS control characters refused
PASS launch argv carries the folder
2 changes: 2 additions & 0 deletions test/golden/runner_form.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ 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
PASS no focus trap after a validation error
25 changes: 25 additions & 0 deletions test/runner_cwd_quotes.luau
Original file line number Diff line number Diff line change
@@ -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")
30 changes: 30 additions & 0 deletions test/runner_form.luau
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,33 @@ 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")

-- 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")