Skip to content
Closed
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
21 changes: 19 additions & 2 deletions apps/desktop/src/app/cron/cron-job-model.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,39 @@ describe('cronEditorUpdates', () => {
it('omits prompt when saving a script-only job with an empty prompt', () => {
expect(
cronEditorUpdates(
{ deliver: 'local', name: 'Weekly', prompt: '', schedule: '0 9 * * 1' },
{ deliver: 'local', name: 'Weekly', prompt: '', reasoningEffort: 'inherit', schedule: '0 9 * * 1' },
{ scriptOnlyJob: true }
)
).toEqual({
deliver: 'local',
name: 'Weekly',
reasoning_effort: null,
schedule: '0 9 * * 1'
})
})

it('includes prompt when the user typed one on a script-only job', () => {
expect(
cronEditorUpdates(
{ deliver: 'email', name: 'Weekly', prompt: 'note', schedule: '0 9 * * 1' },
{ deliver: 'email', name: 'Weekly', prompt: 'note', reasoningEffort: 'high', schedule: '0 9 * * 1' },
{ scriptOnlyJob: true }
).prompt
).toBe('note')
})

it('sets and clears a per-job reasoning override explicitly', () => {
expect(
cronEditorUpdates(
{ deliver: 'local', name: 'Daily', prompt: 'run', reasoningEffort: 'xhigh', schedule: '0 9 * * *' },
{ scriptOnlyJob: false }
).reasoning_effort
).toBe('xhigh')

expect(
cronEditorUpdates(
{ deliver: 'local', name: 'Daily', prompt: 'run', reasoningEffort: 'inherit', schedule: '0 9 * * *' },
{ scriptOnlyJob: false }
).reasoning_effort
).toBeNull()
})
})
4 changes: 3 additions & 1 deletion apps/desktop/src/app/cron/cron-job-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export interface CronEditorSaveValues {
deliver: string
name: string
prompt: string
reasoningEffort: string
schedule: string
}

Expand All @@ -46,7 +47,8 @@ export function cronEditorUpdates(values: CronEditorSaveValues, options: { scrip
const updates: CronJobUpdates = {
deliver: values.deliver,
name: values.name,
schedule: values.schedule.trim()
schedule: values.schedule.trim(),
reasoning_effort: values.reasoningEffort === 'inherit' ? null : values.reasoningEffort
}

const trimmedPrompt = values.prompt.trim()
Expand Down
48 changes: 46 additions & 2 deletions apps/desktop/src/app/cron/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,18 @@ const DEFAULT_DELIVER = 'local'

const DELIVERY_VALUES: readonly string[] = ['local', 'telegram', 'discord', 'slack', 'email']

const REASONING_VALUES: readonly string[] = [
'inherit',
'none',
'minimal',
'low',
'medium',
'high',
'xhigh',
'max',
'ultra'
]

const SCHEDULE_OPTIONS: ReadonlyArray<ScheduleOption> = [
{ expr: '0 9 * * *', value: 'daily' },
{ expr: '0 9 * * 1-5', value: 'weekdays' },
Expand Down Expand Up @@ -103,6 +115,14 @@ function jobDeliver(job: CronJob): string {
return asText(job.deliver) || DEFAULT_DELIVER
}

function jobReasoningEffort(job: CronJob): string {
if (job.reasoning_effort === false) {
return 'none'
}

return asText(job.reasoning_effort).trim()
}

function cronParts(expr: string): null | string[] {
const parts = expr.trim().replace(/\s+/g, ' ').split(' ')

Expand Down Expand Up @@ -391,7 +411,8 @@ export function CronView({ onClose, onOpenSession, setStatusbarItemGroup: _setSt
prompt: values.prompt,
schedule: values.schedule,
name: values.name || undefined,
deliver: values.deliver || DEFAULT_DELIVER
deliver: values.deliver || DEFAULT_DELIVER,
reasoning_effort: values.reasoningEffort === 'inherit' ? null : values.reasoningEffort
})

updateCronJobs(rows => [...rows, created])
Expand Down Expand Up @@ -550,6 +571,7 @@ function CronJobDetail({
const isPaused = state === 'paused'
const deliver = jobDeliver(job)
const prompt = jobPrompt(job)
const reasoningEffort = jobReasoningEffort(job)

return (
<PanelDetail>
Expand All @@ -574,7 +596,10 @@ function CronJobDetail({
{ label: c.frequencyLabel, value: jobScheduleDisplay(job) },
{ label: c.last.replace(/:$/, ''), value: formatTime(job.last_run_at) },
{ label: c.next.replace(/:$/, ''), value: formatTime(job.next_run_at) },
{ label: c.deliverLabel, value: c.deliveryLabels[deliver] ?? deliver }
{ label: c.deliverLabel, value: c.deliveryLabels[deliver] ?? deliver },
...(reasoningEffort
? [{ label: c.reasoningLabel, value: c.reasoningLabels[reasoningEffort] ?? reasoningEffort }]
: [])
]}
/>

Expand Down Expand Up @@ -717,6 +742,7 @@ function CronEditorDialog({
const [schedule, setSchedule] = useState('')
const [schedulePreset, setSchedulePreset] = useState('daily')
const [deliver, setDeliver] = useState(DEFAULT_DELIVER)
const [reasoningEffort, setReasoningEffort] = useState('inherit')
const [saving, setSaving] = useState(false)
const [error, setError] = useState<null | string>(null)

Expand All @@ -730,6 +756,7 @@ function CronEditorDialog({
setSchedule(initial ? jobScheduleExpr(initial) : (SCHEDULE_OPTIONS[0].expr ?? ''))
setSchedulePreset(initial ? scheduleOptionForExpr(jobScheduleExpr(initial)).value : 'daily')
setDeliver(initial ? jobDeliver(initial) : DEFAULT_DELIVER)
setReasoningEffort(initial ? jobReasoningEffort(initial) || 'inherit' : 'inherit')
setError(null)
setSaving(false)
}, [initial, open])
Expand Down Expand Up @@ -781,6 +808,7 @@ function CronEditorDialog({
deliver,
name: name.trim(),
prompt: prompt.trim(),
reasoningEffort,
schedule: schedule.trim()
})
} catch (err) {
Expand Down Expand Up @@ -857,6 +885,21 @@ function CronEditorDialog({
</Field>
</div>

<Field htmlFor="cron-reasoning" label={c.reasoningLabel}>
<Select onValueChange={setReasoningEffort} value={reasoningEffort}>
<SelectTrigger className="h-9 rounded-md" id="cron-reasoning">
<SelectValue />
</SelectTrigger>
<SelectContent>
{REASONING_VALUES.map(value => (
<SelectItem key={value} value={value}>
{c.reasoningLabels[value] ?? value}
</SelectItem>
))}
</SelectContent>
</Select>
</Field>

{schedulePreset === 'custom' ? (
<Field htmlFor="cron-schedule" label={c.customScheduleLabel}>
<Input
Expand Down Expand Up @@ -932,6 +975,7 @@ interface EditorValues {
deliver: string
name: string
prompt: string
reasoningEffort: string
schedule: string
}

Expand Down
12 changes: 12 additions & 0 deletions apps/desktop/src/i18n/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1495,6 +1495,18 @@ export const en: Translations = {
promptPlaceholder: 'Summarize my unread Slack threads and email me the top 5...',
frequencyLabel: 'Frequency',
deliverLabel: 'Deliver to',
reasoningLabel: 'Reasoning effort',
reasoningLabels: {
inherit: 'Inherit model/global setting',
none: 'Off',
minimal: 'Minimal',
low: 'Low',
medium: 'Medium',
high: 'High',
xhigh: 'Extra High',
max: 'Max',
ultra: 'Ultra'
},
customScheduleLabel: 'Custom schedule',
customPlaceholder: '0 9 * * * or weekdays at 9am',
customHint: 'Cron expression, or phrases like "every hour" or "weekdays at 9am".',
Expand Down
12 changes: 12 additions & 0 deletions apps/desktop/src/i18n/ja.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1418,6 +1418,18 @@ export const ja = defineLocale({
promptPlaceholder: '実行ごとにエージェントが行う内容は?',
frequencyLabel: '頻度',
deliverLabel: '配信先',
reasoningLabel: '推論強度',
reasoningLabels: {
inherit: 'モデルまたはグローバル設定を継承',
none: 'オフ',
minimal: '最小',
low: '低',
medium: '中',
high: '高',
xhigh: '特高',
max: '最大',
ultra: 'ウルトラ'
},
customScheduleLabel: 'カスタムスケジュール',
customPlaceholder: '0 9 * * * または weekdays at 9am',
customHint: 'Cron 式、または「every hour」「weekdays at 9am」のようなフレーズ。',
Expand Down
2 changes: 2 additions & 0 deletions apps/desktop/src/i18n/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1226,6 +1226,8 @@ export interface Translations {
promptPlaceholder: string
frequencyLabel: string
deliverLabel: string
reasoningLabel: string
reasoningLabels: Record<string, string>
customScheduleLabel: string
customPlaceholder: string
customHint: string
Expand Down
12 changes: 12 additions & 0 deletions apps/desktop/src/i18n/zh-hant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1371,6 +1371,18 @@ export const zhHant = defineLocale({
promptPlaceholder: '代理每次執行時應做什麼?',
frequencyLabel: '頻率',
deliverLabel: '傳遞至',
reasoningLabel: '推理強度',
reasoningLabels: {
inherit: '繼承模型或全域設定',
none: '關閉',
minimal: '最少',
low: '低',
medium: '中',
high: '高',
xhigh: '特高',
max: '最大',
ultra: '超強'
},
customScheduleLabel: '自訂排程',
customPlaceholder: '0 9 * * * 或 weekdays at 9am',
customHint: 'Cron 表達式,或類似「每小時」「工作日上午 9 點」的短語。',
Expand Down
12 changes: 12 additions & 0 deletions apps/desktop/src/i18n/zh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1673,6 +1673,18 @@ export const zh: Translations = {
promptPlaceholder: '总结我未读的 Slack 话题,并把前 5 条邮件发给我…',
frequencyLabel: '频率',
deliverLabel: '投递至',
reasoningLabel: '推理强度',
reasoningLabels: {
inherit: '继承模型或全局设置',
none: '关闭',
minimal: '最少',
low: '低',
medium: '中',
high: '高',
xhigh: '特高',
max: '最大',
ultra: '超强'
},
customScheduleLabel: '自定义排程',
customPlaceholder: '0 9 * * * 或 weekdays at 9am',
customHint: 'Cron 表达式,或类似"每小时""工作日上午 9 点"的短语。',
Expand Down
3 changes: 3 additions & 0 deletions apps/desktop/src/types/hermes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,7 @@ export interface CronJob {
next_run_at?: null | string
no_agent?: boolean
prompt?: null | string
reasoning_effort?: boolean | null | string
schedule?: CronJobSchedule
schedule_display?: null | string
script?: null | string
Expand All @@ -570,6 +571,7 @@ export interface CronJobCreatePayload {
deliver?: string
name?: string
prompt: string
reasoning_effort?: boolean | null | string
schedule: string
}

Expand All @@ -584,6 +586,7 @@ export interface CronJobUpdates {
enabled?: boolean
name?: string
prompt?: string
reasoning_effort?: boolean | null | string
schedule?: string
}

Expand Down
40 changes: 39 additions & 1 deletion cron/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -981,6 +981,31 @@ def _normalize_job_optional_text(value: Any, *, strip_trailing_slash: bool = Fal
return text or None


def normalize_job_reasoning_effort(value: Any) -> Union[str, bool, None]:
"""Validate and canonicalize a per-job reasoning override.

``None`` means inherit the global/per-model reasoning configuration.
Disabled aliases accepted by the shared parser are persisted as ``False``;
enabled levels are persisted using the parser's canonical lower-case form.
"""
if value is None:
return None

from hermes_constants import VALID_REASONING_EFFORTS, parse_reasoning_effort

parsed = parse_reasoning_effort(value)
if parsed is None:
accepted = ", ".join(("none", *VALID_REASONING_EFFORTS))
raise ValueError(
f"Invalid cron reasoning_effort {value!r}. Expected one of: "
f"{accepted}; false also disables reasoning, and null inherits "
"the global setting."
)
if not parsed.get("enabled"):
return False
return str(parsed["effort"])


def _compute_provider_model_snapshots(
*,
provider: Any,
Expand Down Expand Up @@ -1048,6 +1073,7 @@ def create_job(
model: Optional[str] = None,
provider: Optional[str] = None,
base_url: Optional[str] = None,
reasoning_effort: Any = None,
script: Optional[str] = None,
context_from: Optional[Union[str, List[str]]] = None,
enabled_toolsets: Optional[List[str]] = None,
Expand All @@ -1071,6 +1097,9 @@ def create_job(
model: Optional per-job model override
provider: Optional per-job provider override
base_url: Optional per-job base URL override
reasoning_effort: Optional per-job reasoning override. ``None`` inherits
the global/per-model setting; ``False`` or ``none``
explicitly disables reasoning for this job.
script: Optional path to a script whose stdout feeds the job. With
``no_agent=True`` the script IS the job — its stdout is
delivered verbatim. Without ``no_agent``, its stdout is
Expand Down Expand Up @@ -1123,6 +1152,7 @@ def create_job(
normalized_model = _normalize_job_optional_text(model)
normalized_provider = _normalize_job_optional_text(provider)
normalized_base_url = _normalize_job_optional_text(base_url, strip_trailing_slash=True)
normalized_reasoning_effort = normalize_job_reasoning_effort(reasoning_effort)
normalized_script = str(script).strip() if isinstance(script, str) else None
normalized_script = normalized_script or None
normalized_toolsets = [str(t).strip() for t in enabled_toolsets if str(t).strip()] if enabled_toolsets else None
Expand Down Expand Up @@ -1220,6 +1250,8 @@ def create_job(
"enabled_toolsets": normalized_toolsets,
"workdir": normalized_workdir,
}
if normalized_reasoning_effort is not None:
job["reasoning_effort"] = normalized_reasoning_effort
# Only persist attach_to_session when explicitly set, so existing jobs and
# the common case stay byte-identical (absent key => fall back to the
# global cron.mirror_delivery config, default off).
Expand Down Expand Up @@ -1294,7 +1326,8 @@ def update_job(job_id: str, updates: Dict[str, Any]) -> Optional[Dict[str, Any]]
# Block mutation of immutable fields. ``id`` in particular is a filesystem
# path component under OUTPUT_DIR — letting an update change it leaks
# path-escape values into output writes/deletes.
bad_fields = _IMMUTABLE_JOB_FIELDS.intersection(updates or {})
updates = dict(updates or {})
bad_fields = _IMMUTABLE_JOB_FIELDS.intersection(updates)
if bad_fields:
raise ValueError(
f"Cron job field(s) cannot be updated: {', '.join(sorted(bad_fields))}"
Expand All @@ -1315,6 +1348,11 @@ def update_job(job_id: str, updates: Dict[str, Any]) -> Optional[Dict[str, Any]]
else:
updates["workdir"] = _normalize_workdir(_wd)

if "reasoning_effort" in updates:
updates["reasoning_effort"] = normalize_job_reasoning_effort(
updates["reasoning_effort"]
)

previous_inference_axes = _normalized_inference_axes(job)
updated = _apply_skill_fields({**job, **updates})
schedule_changed = "schedule" in updates
Expand Down
Loading