mirror of
https://github.com/hansjone/dsh-ops-cron.git
synced 2026-10-16 14:53:13 +08:00
Inherit agent presets and auto-bind IM delivery targets (0.1.7).
Cron jobs created from WhatsApp can omit bot/target ids and reuse chat overrides; sidebar/agent preset pins persist on fire. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
2f08136adf
commit
2e690c30c8
15 changed files with 830 additions and 82 deletions
42
lib/tools.js
42
lib/tools.js
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
import { formatInZone, resolveTodayAt } from './scheduler.js'
|
||||
import { deliveryLine, resolveCreateDelivery } from './delivery.js'
|
||||
import { resolveCreateAgentPreset } from './preset.js'
|
||||
|
||||
const JOB_SCHEMA = {
|
||||
type: 'object',
|
||||
|
|
@ -19,6 +20,7 @@ const JOB_SCHEMA = {
|
|||
provider: { type: 'string' },
|
||||
model: { type: 'string' },
|
||||
reasoningEffort: { type: 'string' },
|
||||
agentPreset: { type: 'string' },
|
||||
delivery: { type: 'object', additionalProperties: true },
|
||||
schedule: { type: 'object', additionalProperties: true },
|
||||
createdAt: { type: 'number' },
|
||||
|
|
@ -142,15 +144,16 @@ function requireId(args) {
|
|||
|
||||
export function cronToolDefinitions(service, deps = {}) {
|
||||
const getDshIm = typeof deps.getDshIm === 'function' ? deps.getDshIm : () => undefined
|
||||
const getAgentPresets = typeof deps.getAgentPresets === 'function' ? deps.getAgentPresets : () => undefined
|
||||
return [
|
||||
{
|
||||
name: 'cron_create',
|
||||
description: 'Create a DSH 运维定时 job (sidebar scheduled job). NEVER use crontab. NOT schedule_create. Default timezone Asia/Shanghai. For "in N minutes / 一分钟后" pass only after_minutes. For "today/tonight at HH:MM" pass only hour+minute (24h; hour=0 is midnight). Do not also send at or expr. Extra schedule fields are ignored (after_minutes > hour > at > expr). cwd MUST be the current workspace path when chatting in a workspace; if omitted, uses the current session working directory. Pass provider+model for the job; if omitted, snapshots the current session model. Delivery: omit for auto (WhatsApp/IM session → im if a matching 投递目标 exists; else dsh). Or pass delivery=dsh|im with im_bot_id+im_target_id from IM 投递设置.',
|
||||
description: 'Create a DSH 定时任务 job (sidebar scheduled job). NEVER use crontab. NOT schedule_create. Default timezone Asia/Shanghai. For "in N minutes / 一分钟后" pass only after_minutes. For "today/tonight at HH:MM" pass only hour+minute (24h; hour=0 is midnight). Do not also send at or expr. Extra schedule fields are ignored (after_minutes > hour > at > expr). cwd MUST be the current workspace path when chatting in a workspace; if omitted, uses the current session working directory. Pass provider+model for the job; if omitted, snapshots the current session model. Agent preset: omit to inherit (WhatsApp chat preset → session → Host default); or pass agent_preset. Delivery: omit for auto — on WhatsApp/IM creates/reuses a 投递目标 for the current chat (group→group, DM→DM) and sets delivery=im; on Web/DSH defaults to dsh. Or pass delivery=dsh|im with im_bot_id+im_target_id.',
|
||||
parameters: {
|
||||
type: 'object',
|
||||
additionalProperties: false,
|
||||
properties: {
|
||||
name: { type: 'string', description: 'Short display name in the 运维定时 list.' },
|
||||
name: { type: 'string', description: 'Short display name in the 定时任务 list.' },
|
||||
prompt: { type: 'string', description: 'Self-contained instructions for the new session when the job fires.' },
|
||||
expr: { type: 'string', description: '5-field cron in the given timezone: "minute hour day-of-month month day-of-week". Recurring jobs only. 22:55 every day = "55 22 * * *". Do not send expr together with after_minutes/hour/at — extras are ignored.' },
|
||||
cron: { type: 'string', description: 'Alias of expr.' },
|
||||
|
|
@ -170,6 +173,7 @@ export function cronToolDefinitions(service, deps = {}) {
|
|||
delivery: { type: 'string', description: 'dsh (sidebar session) or im (proactive WhatsApp/IM via botId+targetId). Omit to auto-detect from the current session.' },
|
||||
im_bot_id: { type: 'string', description: 'Opaque botId from IM 投递设置 when delivery=im.' },
|
||||
im_target_id: { type: 'string', description: 'Opaque targetId from IM 投递设置 when delivery=im.' },
|
||||
agent_preset: { type: 'string', description: 'Agent preset id for scheduled runs. Omit to inherit from the current WhatsApp/IM chat or Host default.' },
|
||||
},
|
||||
required: ['name', 'prompt'],
|
||||
},
|
||||
|
|
@ -194,12 +198,16 @@ export function cronToolDefinitions(service, deps = {}) {
|
|||
return text(`Created "${job?.name}" (${job?.id}) ${sched} in ${tz}.${cwd}.${model}.${delivery}. Next run: ${when}. If that local time is wrong, delete this job and recreate with 24h hours (22=10pm).`)
|
||||
},
|
||||
},
|
||||
presentCall: (args) => ({ card: 'generic', title: '创建运维定时', content: String(args?.name || '') }),
|
||||
presentCall: (args) => ({ card: 'generic', title: '创建定时任务', content: String(args?.name || '') }),
|
||||
async execute(args, exec) {
|
||||
aborted(exec)
|
||||
const timeout = Number(args.timeout_minutes)
|
||||
try {
|
||||
const delivery = await resolveCreateDelivery(args, exec, { dshIm: getDshIm() })
|
||||
const agentPreset = await resolveCreateAgentPreset(args, exec, {
|
||||
dshIm: getDshIm(),
|
||||
agentPresets: getAgentPresets(),
|
||||
})
|
||||
const job = await service.createJob({
|
||||
name: args.name,
|
||||
prompt: args.prompt,
|
||||
|
|
@ -209,6 +217,7 @@ export function cronToolDefinitions(service, deps = {}) {
|
|||
timeoutMinutes: Number.isFinite(timeout) && timeout > 0 ? timeout : undefined,
|
||||
enabled: args.enabled !== false,
|
||||
delivery,
|
||||
agentPreset,
|
||||
})
|
||||
return { job }
|
||||
} catch (error) {
|
||||
|
|
@ -225,7 +234,7 @@ export function cronToolDefinitions(service, deps = {}) {
|
|||
},
|
||||
{
|
||||
name: 'cron_list',
|
||||
description: 'List DSH 运维定时 jobs (sidebar scheduled jobs). Use this whenever the user asks what scheduled tasks exist. NEVER use crontab -l or /etc/cron* — those are OS crontabs, not this plugin.',
|
||||
description: 'List DSH 定时任务 jobs (sidebar scheduled jobs). Use this whenever the user asks what scheduled tasks exist. NEVER use crontab -l or /etc/cron* — those are OS crontabs, not this plugin.',
|
||||
parameters: {
|
||||
type: 'object',
|
||||
additionalProperties: false,
|
||||
|
|
@ -248,7 +257,7 @@ export function cronToolDefinitions(service, deps = {}) {
|
|||
return text(rows.length ? `Scheduled tasks (${value.count}):\n${rows.join('\n')}` : 'No scheduled tasks yet.')
|
||||
},
|
||||
},
|
||||
presentCall: () => ({ card: 'generic', title: '列出运维定时' }),
|
||||
presentCall: () => ({ card: 'generic', title: '列出定时任务' }),
|
||||
async execute(args, exec) {
|
||||
aborted(exec)
|
||||
let jobs = await service.listJobs()
|
||||
|
|
@ -258,7 +267,7 @@ export function cronToolDefinitions(service, deps = {}) {
|
|||
},
|
||||
{
|
||||
name: 'cron_pause',
|
||||
description: 'Pause a scheduled task by id from cron_list / cron_create. It stays in 运维定时 but will not fire until resumed.',
|
||||
description: 'Pause a scheduled task by id from cron_list / cron_create. It stays in 定时任务 but will not fire until resumed.',
|
||||
parameters: {
|
||||
type: 'object',
|
||||
additionalProperties: false,
|
||||
|
|
@ -269,7 +278,7 @@ export function cronToolDefinitions(service, deps = {}) {
|
|||
schema: { type: 'object', additionalProperties: true, properties: { job: JOB_SCHEMA } },
|
||||
render: (_args, value) => text(`Paused "${value.job?.name}" (${value.job?.id}).`),
|
||||
},
|
||||
presentCall: (args) => ({ card: 'generic', title: '暂停运维定时', content: String(args?.id || '') }),
|
||||
presentCall: (args) => ({ card: 'generic', title: '暂停定时任务', content: String(args?.id || '') }),
|
||||
async execute(args, exec) {
|
||||
aborted(exec)
|
||||
const job = await service.pauseJob(requireId(args), false)
|
||||
|
|
@ -289,7 +298,7 @@ export function cronToolDefinitions(service, deps = {}) {
|
|||
schema: { type: 'object', additionalProperties: true, properties: { job: JOB_SCHEMA } },
|
||||
render: (_args, value) => text(`Resumed "${value.job?.name}" (${value.job?.id}).`),
|
||||
},
|
||||
presentCall: (args) => ({ card: 'generic', title: '恢复运维定时', content: String(args?.id || '') }),
|
||||
presentCall: (args) => ({ card: 'generic', title: '恢复定时任务', content: String(args?.id || '') }),
|
||||
async execute(args, exec) {
|
||||
aborted(exec)
|
||||
const job = await service.pauseJob(requireId(args), true)
|
||||
|
|
@ -317,7 +326,7 @@ export function cronToolDefinitions(service, deps = {}) {
|
|||
},
|
||||
render: (_args, value) => text(value.deleted ? `Deleted scheduled task ${value.id}.` : `Scheduled task ${value.id} was not found.`),
|
||||
},
|
||||
presentCall: (args) => ({ card: 'generic', title: '删除运维定时', content: String(args?.id || '') }),
|
||||
presentCall: (args) => ({ card: 'generic', title: '删除定时任务', content: String(args?.id || '') }),
|
||||
async execute(args, exec) {
|
||||
aborted(exec)
|
||||
const id = requireId(args)
|
||||
|
|
@ -336,17 +345,18 @@ export function cronToolDefinitions(service, deps = {}) {
|
|||
export function cronGuidanceText(nowMs = Date.now(), timeZone = 'Asia/Shanghai') {
|
||||
const now = formatInZone(nowMs, timeZone)
|
||||
return [
|
||||
'This deployment has a DSH sidebar feature named 运维定时 (ops scheduled tasks / dsh-ops-cron).',
|
||||
'This deployment has a DSH sidebar feature named 定时任务 (scheduled tasks / dsh-ops-cron).',
|
||||
'Jobs live in that list and fire a fresh session (and optionally deliver a summary to WhatsApp/IM). They are NOT OS crontab and NOT in-chat schedule_create reminders.',
|
||||
`Current local time for scheduling: ${now}. Use this calendar date for "today"/"tonight". Never invent another month or day.`,
|
||||
'For "in N minutes / 一分钟后", call cron_create with after_minutes=N only (do not also pass at, hour, or expr).',
|
||||
'For a clock time tonight, pass only hour and minute in 24h (晚上11点34 → hour=23, minute=34; 零点33 → hour=0, minute=33). Extra at/expr fields are ignored.',
|
||||
'Working directory: if the user is chatting in a workspace, pass cwd as that workspace filesystem path (the current session working directory). If they name another workspace, use that path. If cwd is omitted, cron_create uses the current session cwd.',
|
||||
'Model: pass provider+model for the job. If omitted, cron_create stores the current session model. Scheduled runs consume that model\'s quota.',
|
||||
'Delivery: when chatting on WhatsApp/IM, omit delivery so the job defaults to im (requires a matching 投递目标 for this peer). On Web/DSH, default is dsh. Or pass delivery=im with im_bot_id+im_target_id from IM 投递设置 → 复制调用参数.',
|
||||
'When the user asks to look at, create, pause, resume, or delete 运维定时 / 定时任务 / scheduled tasks / cron jobs:',
|
||||
'Delivery: when chatting on WhatsApp/IM, omit delivery so the job defaults to im for the current chat (group→same group, DM→same DM). A 投递目标 is reused or auto-created. On Web/DSH, default is dsh. Or pass delivery=im with im_bot_id+im_target_id.',
|
||||
'Agent preset: omit agent_preset to inherit (WhatsApp chat/group preset → creating session → Host default). Pass agent_preset to pin a preset for every scheduled run.',
|
||||
'When the user asks to look at, create, pause, resume, or delete 定时任务 / scheduled tasks / cron jobs:',
|
||||
'1. If cron_list / cron_create / cron_pause / cron_resume / cron_delete are in your tool list, call them.',
|
||||
'2. If they are not listed, search/unlock tools or skills with query "运维定时" or "cron" (skill_search, skill_load, or dev_tool_search) and then call them.',
|
||||
'2. If they are not listed, search/unlock tools or skills with query "定时任务" or "cron" (skill_search, skill_load, or dev_tool_search) and then call them.',
|
||||
'3. Never run crontab, never read /etc/cron*, and never say there are no tasks until cron_list has returned.',
|
||||
].join('\n')
|
||||
}
|
||||
|
|
@ -356,15 +366,15 @@ export const CRON_GUIDANCE = cronGuidanceText()
|
|||
export function makeCronSkill() {
|
||||
return {
|
||||
name: 'scheduled-tasks',
|
||||
description: '运维定时: 查看、创建、暂停、恢复、删除 DSH 侧栏定时任务(今天晚上几点、一次性执行、scheduled job、cron)。WhatsApp 里创建默认回投 IM;Web 里创建进侧栏会话。不要用系统 crontab,也不是会话内 reminder。',
|
||||
whenToUse: 'User asks to list or create 运维定时 / 定时任务, schedule something for tonight/today, pause a job, or mentions cron / scheduled tasks in DeepSeek Harness.',
|
||||
description: '定时任务: 查看、创建、暂停、恢复、删除 DSH 侧栏定时任务(今天晚上几点、一次性执行、scheduled job、cron)。WhatsApp 里创建默认回投 IM;Web 里创建进侧栏会话。不要用系统 crontab,也不是会话内 reminder。',
|
||||
whenToUse: 'User asks to list or create 定时任务 / scheduled tasks, schedule something for tonight/today, pause a job, or mentions cron in DeepSeek Harness.',
|
||||
source: 'runtime',
|
||||
provider: 'runtime',
|
||||
content: `${cronGuidanceText()}
|
||||
|
||||
Tools:
|
||||
- cron_list — list jobs
|
||||
- cron_create — "一分钟后" → after_minutes=1. Clock time → hour+minute only. Do not send at/expr at the same time. Pass cwd as the current workspace path when creating from a workspace chat. Pass provider+model or inherit the current session model. Delivery auto from session, or delivery=im + im_bot_id + im_target_id.
|
||||
- cron_create — "一分钟后" → after_minutes=1. Clock time → hour+minute only. Do not send at/expr at the same time. Pass cwd as the current workspace path when creating from a workspace chat. Pass provider+model or inherit the current session model. Delivery and agent preset auto from session, or pass delivery=im / agent_preset explicitly.
|
||||
- cron_pause / cron_resume / cron_delete — by id from cron_list
|
||||
`,
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue