The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
feat(desktop): recurrence-to-cron suggestion provider
Brooklyn Nicholsone7032bb26743
diff --git a/apps/desktop/src/app/chat/composer/hooks/use-composer-draft.ts b/apps/desktop/src/app/chat/composer/hooks/use-composer-draft.tsindex ecfefb93b44..e92afa82f2f 100644--- a/apps/desktop/src/app/chat/composer/hooks/use-composer-draft.ts+++ b/apps/desktop/src/app/chat/composer/hooks/use-composer-draft.ts@@ -1,6 +1,7 @@// Register the built-in draft providers with the suggestion bus (side-effect// import — the bus itself is provider-agnostic). The repair provider is// event-driven and registers through the gateway stream instead.+import '@/store/suggestion-providers/cron'import '@/store/suggestion-providers/mcp'import '@/store/suggestion-providers/skill'diff --git a/apps/desktop/src/i18n/en.ts b/apps/desktop/src/i18n/en.tsindex 713f75ab329..3160533d69d 100644--- a/apps/desktop/src/i18n/en.ts+++ b/apps/desktop/src/i18n/en.ts@@ -2157,6 +2157,13 @@ export const en: Translations = {doneTip: 'Fresh credentials are live in this chat',failed: server => `Could not reconnect ${server}`},+ cronSuggestions: {+ label: 'Schedule this',+ tip: phrase => `“${phrase}” sounds recurring — run it on a schedule instead`,+ prefix: 'Set this up as a scheduled job:',+ done: 'Marked for scheduling',+ doneTip: 'Send it and the agent creates the job'+ },snippets: {codeReview: {label: 'Code review',diff --git a/apps/desktop/src/i18n/types.ts b/apps/desktop/src/i18n/types.tsindex dbc82d1418c..4b34a851b03 100644--- a/apps/desktop/src/i18n/types.ts+++ b/apps/desktop/src/i18n/types.ts@@ -1814,6 +1814,13 @@ export interface Translations {doneTip: stringfailed: (server: string) => string}+ cronSuggestions: {+ label: string+ tip: (phrase: string) => string+ prefix: string+ done: string+ doneTip: string+ }}statusStack: {diff --git a/apps/desktop/src/i18n/zh.ts b/apps/desktop/src/i18n/zh.tsindex 687901141dc..b6063d1cb45 100644--- a/apps/desktop/src/i18n/zh.ts+++ b/apps/desktop/src/i18n/zh.ts@@ -2347,6 +2347,13 @@ export const zh: Translations = {doneTip: '新凭据已在此对话中生效',failed: server => `无法重新连接 ${server}`},+ cronSuggestions: {+ label: '定时执行',+ tip: phrase => `“${phrase}”听起来是周期性任务 — 可以按计划运行`,+ prefix: '将此设置为定时任务:',+ done: '已标记为定时任务',+ doneTip: '发送后由智能体创建任务'+ },snippets: {codeReview: {label: '代码审查',diff --git a/apps/desktop/src/store/suggestion-providers/cron.test.ts b/apps/desktop/src/store/suggestion-providers/cron.test.tsnew file mode 100644index 00000000000..e83292b68c5--- /dev/null+++ b/apps/desktop/src/store/suggestion-providers/cron.test.ts@@ -0,0 +1,26 @@+import { describe, expect, it } from 'vitest'++import { matchRecurrence } from './cron'++describe('matchRecurrence', () => {+ it.each([+ ['remind me every morning to check the board', 'every morning'],+ ['run this daily please', 'daily'],+ ['every 2 hours, poll the feed', 'every 2 hours'],+ ['each week send a summary', 'each week'],+ ['do it every friday', 'every friday'],+ ['nightly build report', 'nightly']+ ])('matches recurring phrasing: %s', (draft, phrase) => {+ expect(matchRecurrence(draft)?.toLowerCase()).toBe(phrase)+ })++ it.each([+ 'remind me to call mom tomorrow',+ 'this happens to everyone',+ 'the everyday struggle',+ 'weekly-report.pdf is attached',+ 'i read the Daily Prophet'+ ])('stays quiet on one-shots and lookalikes: %s', draft => {+ expect(matchRecurrence(draft)).toBeNull()+ })+})diff --git a/apps/desktop/src/store/suggestion-providers/cron.ts b/apps/desktop/src/store/suggestion-providers/cron.tsnew file mode 100644index 00000000000..17b420e23e3--- /dev/null+++ b/apps/desktop/src/store/suggestion-providers/cron.ts@@ -0,0 +1,83 @@+import { requestComposerFocus, requestComposerInsert } from '@/app/chat/composer/focus'+import { translateNow } from '@/i18n'+import { registerDraftProvider } from '@/store/composer-suggestions'++/**+ * Recurrence draft provider: the draft reads like a recurring task+ * ("remind me every morning…", "check this daily"), so offer to schedule it+ * as a cron job instead of a one-off message.+ *+ * Invoke prefixes the draft with an explicit scheduling instruction — the+ * agent owns parsing the schedule and creating the job (cronjob tool); the+ * pill only makes the intent unambiguous. Same reversible-edit contract as+ * the skill pill: it touches the draft, nothing else, and stands down once+ * the draft leads with the instruction it inserted.+ */++// Recurrence phrasing, deliberately narrow (VS Code lesson: high-precision+// triggers over statistical ones). Whole-word, unicode boundaries; hyphen+// counts as a word character so "weekly-report.pdf" stays quiet.+// - "every <hour|morning|day|week|weekday|month|monday…>" (+ "every 2 hours")+// - "daily" / "weekly" / "monthly" / "nightly" / "hourly"+// - "each morning/day/week/…"+// - a bare "remind me" is NOT a trigger — one-shot reminders are fine as+// normal messages.+const RECURRENCE_RE =+ /(?<![\p{L}\p{N}-])(?:(?:every|each)\s+(?:\d+\s+)?(?:second|minute|hour|morning|afternoon|evening|night|day|weekday|week|month|monday|tuesday|wednesday|thursday|friday|saturday|sunday)s?|daily|weekly|monthly|nightly|hourly)(?![\p{L}\p{N}-])/giu++// A bare frequency adverb immediately followed by a Capitalized word is a+// proper noun ("the Daily Prophet", "Weekly Standup notes"), not a schedule.+// Checked in code because the regex's `i` flag case-folds \p{Lu} inside the+// pattern (making "please" read as capitalized).+const ADVERB_RE = /^(daily|weekly|monthly|nightly|hourly)$/i++/** Pure matcher, exported for tests: the recurrence phrase that fired, or+ * null. The pill tooltip shows it, same attribution rule as every source. */+export function matchRecurrence(text: string): string | null {+ for (const match of text.matchAll(RECURRENCE_RE)) {+ const phrase = match[0]++ if (ADVERB_RE.test(phrase) && /^\s+\p{Lu}/u.test(text.slice(match.index + phrase.length))) {+ continue+ }++ return phrase+ }++ return null+}++registerDraftProvider('cron', async ({ text }) => {+ const copy = (key: string, ...args: unknown[]) => translateNow(`composer.cronSuggestions.${key}`, ...args)+ const trimmed = text.trimStart()++ // Already a slash command, or already carrying the instruction we insert —+ // stand down.+ if (trimmed.startsWith('/') || trimmed.toLowerCase().startsWith(copy('prefix').toLowerCase())) {+ return []+ }++ const phrase = matchRecurrence(text)++ if (!phrase) {+ return []+ }++ return [+ {+ doneLabel: copy('done'),+ doneTip: copy('doneTip'),+ icon: 'calendar',+ id: 'schedule',+ invoke: async () => {+ requestComposerInsert(copy('prefix'), { mode: 'prefix' })+ requestComposerFocus()+ },+ label: copy('label'),+ provider: 'cron',+ tip: copy('tip', phrase),+ workingLabel: copy('label'),+ workingTip: copy('tip', phrase)+ }+ ]+})diff --git a/apps/desktop/src/store/suggestion-providers/repair.test.ts b/apps/desktop/src/store/suggestion-providers/repair.test.tsindex e83f94dcf02..23408798532 100644--- a/apps/desktop/src/store/suggestion-providers/repair.test.ts+++ b/apps/desktop/src/store/suggestion-providers/repair.test.ts@@ -1,6 +1,6 @@import { describe, expect, it } from 'vitest'-import { mcpServerFromToolName } from './repair'+import { mcpServerFromToolName, REPAIR_RE } from './repair'describe('mcpServerFromToolName', () => {it('extracts the server from a namespaced MCP tool', () => {@@ -18,3 +18,27 @@ describe('mcpServerFromToolName', () => {expect(mcpServerFromToolName('mcp_not_namespaced')).toBeNull()})})++describe('REPAIR_RE', () => {+ it.each([+ 'HTTP 401 Unauthorized',+ 'token has expired, please re-authenticate',+ 'OAuth flow required',+ 'authentication failed for server',+ 'connection refused by remote host',+ 'ECONNREFUSED 127.0.0.1:3845',+ 'server disconnected before response'+ ])('flags auth/connection failures: %s', text => {+ expect(REPAIR_RE.test(text)).toBe(true)+ })++ it.each([+ 'issue PROJ-123 not found',+ 'no design nodes matched the query',+ 'rate limit exceeded, retry after 60s',+ 'invalid argument: node_id is required',+ 'permission denied editing this file'+ ])('ignores tool-semantics failures: %s', text => {+ expect(REPAIR_RE.test(text)).toBe(false)+ })+})diff --git a/apps/desktop/src/store/suggestion-providers/repair.ts b/apps/desktop/src/store/suggestion-providers/repair.tsindex 6a8d9478d98..e8e58c8ec0c 100644--- a/apps/desktop/src/store/suggestion-providers/repair.ts+++ b/apps/desktop/src/store/suggestion-providers/repair.ts@@ -20,8 +20,9 @@ import { notifyError } from '@/store/notifications'// Auth/connection shaped failure text from an MCP tool result. Deliberately// narrow: a tool erroring on its own semantics ("issue not found") must not-// pill a reconnect. Matched against the error/result string.-const REPAIR_RE = /\b(401|403|unauthorized|forbidden|token .*(expired|invalid)|oauth|authenticat\w+ (failed|required|expired)|connection (refused|closed|reset|failed)|server (unavailable|disconnected|not connected)|ECONNREFUSED)\b/i+// pill a reconnect. Matched against the error/result string. Exported for+// tests.+export const REPAIR_RE = /\b(401|403|unauthorized|forbidden|token .*(expired|invalid)|oauth|authenticat\w+ (failed|required|expired)|connection (refused|closed|reset|failed)|server (unavailable|disconnected|not connected)|ECONNREFUSED)\b/i/** `mcp__figma__get_design_context` → `figma`; null for non-MCP tools. */export const mcpServerFromToolName = (toolName: string): string | null => {diff --git a/apps/desktop/src/store/suggestion-providers/skill.test.ts b/apps/desktop/src/store/suggestion-providers/skill.test.tsnew file mode 100644index 00000000000..67eef945d31--- /dev/null+++ b/apps/desktop/src/store/suggestion-providers/skill.test.ts@@ -0,0 +1,28 @@+import { describe, expect, it } from 'vitest'++import { skillPattern } from './skill'++describe('skillPattern', () => {+ it('matches the exact name as a whole word', () => {+ expect(skillPattern('perf').test('run the perf loop')).toBe(true)+ expect(skillPattern('perf').test('performance is bad')).toBe(false)+ })++ it('hyphenated names also match spaced phrasing', () => {+ expect(skillPattern('pr-ready').test('make this pr ready')).toBe(true)+ expect(skillPattern('pr-ready').test('run pr-ready on it')).toBe(true)+ expect(skillPattern('pr_ready').test('pr ready please')).toBe(true)+ })++ it('never matches inside other words', () => {+ expect(skillPattern('read').test('i already did')).toBe(false)+ expect(skillPattern('work').test('reworked the layout')).toBe(false)+ // Suffix boundary includes hyphen: "clean" must not fire inside "clean-up"+ // (a different skill may own that name).+ expect(skillPattern('clean').test('do a clean-up pass')).toBe(false)+ })++ it('is case-insensitive via lowercased input', () => {+ expect(skillPattern('Clean').test('please clean this diff')).toBe(true)+ })+})diff --git a/apps/desktop/src/store/suggestion-providers/skill.ts b/apps/desktop/src/store/suggestion-providers/skill.tsindex f5a30278e28..0cee93dbd74 100644--- a/apps/desktop/src/store/suggestion-providers/skill.ts+++ b/apps/desktop/src/store/suggestion-providers/skill.ts@@ -35,6 +35,19 @@ export function invalidateSkillSuggestionIndex(): void {const escape = (value: string) => value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')+/** Whole-word pattern for a skill name, exported for tests. Hyphens and+ * underscores in the name also match spaces — people type "pr ready", the+ * skill is `pr-ready` — while "already" can never match a skill `read`. */+export function skillPattern(name: string): RegExp {+ const flexible = name+ .toLowerCase()+ .split(/[-_]/)+ .map(escape)+ .join('[-_ ]')++ return new RegExp(`(?<![\\p{L}\\p{N}])${flexible}(?![\\p{L}\\p{N}-])`, 'u')+}+async function loadIndex(): Promise<SkillIndexEntry[]> {if (index && Date.now() - indexAt < SKILLS_TTL_MS) {return index@@ -46,10 +59,7 @@ async function loadIndex(): Promise<SkillIndexEntry[]> {.filter(skill => skill.enabled && skill.name.length >= MIN_NAME_LENGTH).map(skill => ({name: skill.name,- // Whole-word on unicode boundaries; hyphens/underscores inside a skill- // name ("pr-ready") are literal, so "pr-ready" matches but "already"- // never matches "read".- pattern: new RegExp(`(?<![\\p{L}\\p{N}])${escape(skill.name.toLowerCase())}(?![\\p{L}\\p{N}-])`, 'u')+ pattern: skillPattern(skill.name)}))indexAt = Date.now()