Repository navigation
refactor(studio): describe cron schedules with cronstrue - #2285
Conversation
50604f7 to
3cfda80
Compare
3cfda80 to
23d5806
Compare
There was a problem hiding this comment.
Thanks Daniel. Using a library here is the right call, but swapping the describer changed more than the wording, because the form preview, the Schedule sort and the search all run on its output. Reviewed at 23d58066b.
Before merge
-
Invalid crons now preview as valid (
lib/formatters.ts:112). The daemon parses with robfigParseStandard(engine/adapter/cronparse/cronparse.go:41): weekdays are 0–6, and there's noL,Wor#. cronstrue accepts all of those, so0 9 * * 7previews as "At 09:00 AM, only on Sunday",0 9 L * *as "on the last day of the month", and0 12 * * 1#1as "first Monday", and then Save fails. Thedescribed === outcome.croncheck inschedule-form.tsx:79, which showed the "Cron expression" hint, now almost never matches. The0 9 * * 7fallback test was the only thing tying the describer to the daemon's range, and it was removed. Keep a guard for the daemon's grammar before calling cronstrue, and restore that test. -
Sort and search now run on English prose (
schedule-inventory.ts:61,:100).- Sort: Schedule sort is
localeCompareon the label, so it now orders "At 01:00 PM" before "At 09:00 AM", and midnight after 11 PM. The test changed0 9to0 5to keep its expected order. - Search: searching "daily", "weekly", "monthly" or "weekdays" no longer matches anything, although
scheduled-tasks.mdsays you can search by cadence. The test moved from "weekdays" to "Monday through Friday".
Sort on a structured key (the next fire time, or the cadence plus minutes since midnight), and add stable cadence words to the search text. Computing the labels once per list also removes the cronstrue parse from inside the comparator.
- Sort: Schedule sort is
Small, can go in now
- Tabs (
formatters.ts:110). The guard splits on/\s+/but passes the original string to cronstrue, which only splits on spaces. A tab-separated cron, which robfig accepts (strings.Fields), shows as raw. Passparts.join(" "). - Long labels (
schedules-workspace.tsx:391). The cell iswhitespace-nowrap, and15 9,13,17 * * 1-5now reads "At 09:15 AM, 01:15 PM and 05:15 PM, only on Monday, Tuesday, Wednesday, Thursday, and Friday", which pushes the Actions column out of view. Truncate, and put the raw cron intitle. That also makes the docstring's "shown in a tooltip alongside" (formatters.ts:104) true, which it isn't today in the inventory. - Tests (
formatters.test.ts:126). Cover the shapes the builder emits:0 0 * * 0,*/15 * * * *and0 */1 * * *. - Bundle (
formatters.ts:3). cronstrue comes in through the sharedlib/formatters, so chat and knowledge load it too. MovedescribeCronintofeatures/schedules, or import cronstrue lazily there. - Stale comment (
schedule-phrase.ts:23-27). It still points at thedescribeCronWeekly/Sunday shape, which is gone. The real reason for Sunday being 0 is the daemon's 0–6 range.
Can be a follow-up
- Steps wider than the field read wrong, as they did before the swap.
*/90 * * * *reads "Every 90 minutes", but robfig only sets minute 0, so it runs hourly;0 */25 * * *runs once a day.
Replace the hand-rolled describeCron regex matcher with cronstrue. The wrapper keeps the existing contract: anything that is not a five-field expression, or that cronstrue cannot parse, falls back to the raw string. Wording changes (e.g. "At 09:00 AM, only on Friday"), and shapes the old matcher passed through raw (day lists, pinned months) are now described. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
cronstrue accepts weekday 7 and the L, W and # forms that the daemon's parser rejects, so an invalid cron previewed as a valid one and the "Cron expression" hint no longer showed. Guard each field against the daemon's grammar before calling cronstrue, and return the raw expression for what the daemon would reject, for steps wider than the field, and for anything that is not five fields. Tab-separated fields now describe too. The Schedule column now sorts on the cadence and time of day rather than the English label, and search matches cadence words (daily, weekly, weekdays, monthly) again. Long labels truncate with the raw cron in the title. describeCron moves to features/schedules so cronstrue stays out of the shared formatters bundle. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
|
Thanks @peppescg, these were real regressions. Pushed Before merge
Small items
Follow-up item (steps wider than the field): I folded it in, since it was one rule in the guard. A step larger than the span it steps over ( Fully or partially written by an AI agent. |
23d5806 to
e83c619
Compare
peppescg
left a comment
There was a problem hiding this comment.
Thanks Daniel, this is all addressed. The grammar guard and the cadence sort key are exactly what I had in mind, and thanks for folding in the wide-step case too. LGTM.
Follow-up to #2194, which has merged.
Summary
Replace the hand-rolled regex
describeCroninlib/formatters.tswith cronstrue (3.32.0, MIT). The wrapper keeps the existing contract: anything that is not a five-field expression, or that cronstrue cannot parse, falls back to the raw string (schedule-form.tsxrelies on this).User-facing change
Wording changes, e.g.
Daily at 9:00 AMbecomesAt 09:00 AM, and weekdays readAt 05:30 PM, Monday through Friday. Shapes the old matcher printed raw (day lists, pinned months,* * * * *) are now described.Test plan
formatters.test.tsupdated for the new wording and the raw-string fallbacksschedule-inventory.test.tsadjusted (search text and sort data depended on the old wording)biome checkpassThe lockfile change adds only cronstrue.
Fully or partially written by an AI agent.
🤖 Generated with Claude Code