@soffits/dsh-cron-jobs 0.10.0 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +3 -1
  2. package/package.json +1 -1
  3. package/tools.js +53 -2
package/README.md CHANGED
@@ -301,7 +301,7 @@ The `cron-jobs-tools` row registers five tools. Their names start with `cron_job
301
301
  | Tool | What it does |
302
302
  |---|---|
303
303
  | `cron_job_create` | Create a job: a title, a prompt and/or a command, one of `cron`, `rrule` and `at` (with `timeZone` where needed) and/or `on` (event channels), where the prompt goes, and optionally `once`, where the result is delivered and which model its sessions use. |
304
- | `cron_job_edit` | `update` the given fields, `pause`, `resume` (continues from now), or `delete` a job by id. An empty `cron`, `rrule` or `at` removes the schedule of a job with `on`; an empty `on` removes its subscriptions. |
304
+ | `cron_job_edit` | `update` the given fields, `pause`, `resume` (continues from now), or `delete` a job by id. An empty `cron`, `rrule` or `at` removes the schedule of a job with `on`; an empty `on` removes its subscriptions. `prompt_replace` and `command_replace` change the text in place; see below. |
305
305
  | `cron_job_list` | Every job, from the config and from tools, with its id, state, schedule, next run, target and last run. |
306
306
  | `cron_job_view` | One job's full definition and its five latest runs. |
307
307
  | `cron_job_watch` | `create`, `delete` or `list` [watchers](#watchers). |
@@ -316,6 +316,8 @@ Where the prompt goes (`target`):
316
316
 
317
317
  `deliver` takes `<service>:<address>` (such as `telegramTopics:notify`) or `none`; the service must be running when the job is created. Left out, the job uses the row's default target, or delivers nothing when its prompt goes to an existing session. On `cron_job_edit`, an empty `deliver` goes back to the default.
318
318
 
319
+ `prompt_replace` and `command_replace` on `cron_job_edit` change a long prompt or command without resending it: a list of literal `{ "old": "...", "new": "...", "replace_all": false }` replacements, applied in order, each to the result of the one before. Every `old` must match exactly once unless that item sets `replace_all`; otherwise the call fails naming the item (`prompt_replace[1] (old "..."): no match` or `matches 3 times`) and changes nothing. They cannot be combined with `prompt` or `command`.
320
+
319
321
  `answerCheck` sets the job's [answer check](#answer-checks) command; on `cron_job_edit`, an empty string removes it.
320
322
 
321
323
  `model` is an object, `{ "provider": "anthropic", "model": "claude-sonnet-4-5", "reasoningEffort": "high" }`, with the same ids the model picker uses; `provider` and `model` are required together and `reasoningEffort` is optional. The sessions the job opens start on that model, like `agent.model` on a config job; left out, the preset's or host default applies. `cron_job_edit` with `model` sets it on an existing job, and an empty object (`{}`) clears it. `cron_job_list` and `cron_job_view` show the model when one is set. A job that posts into an existing session (`this_session`, `sessionId`) does not open a session, so its model has no effect.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@soffits/dsh-cron-jobs",
3
- "version": "0.10.0",
3
+ "version": "0.11.0",
4
4
  "description": "Scheduled jobs for DeepSeek Harness: shell commands and agent prompts on cron, RRULE or one-time schedules, a gate that wakes an agent only when there is something to do, result delivery through any plugin that can send messages, tools to manage jobs from a conversation, and a Cron tasks page in the Web GUI.",
5
5
  "type": "module",
6
6
  "main": "./index.js",
package/tools.js CHANGED
@@ -64,6 +64,20 @@ export function toolSchemas(prefix) {
64
64
  required: [],
65
65
  additionalProperties: false,
66
66
  }
67
+ const replacements = field => ({
68
+ type: 'array',
69
+ description: `Change the ${field} in place instead of resending it: literal {old, new} replacements applied in order. Each old must match exactly once, or set replace_all. Not with ${field}.`,
70
+ items: {
71
+ type: 'object',
72
+ properties: {
73
+ old: { type: 'string', description: 'Exact text to find.' },
74
+ new: { type: 'string', description: 'Replacement text; empty deletes the match.' },
75
+ replace_all: { type: 'boolean', description: 'Replace every match, not only a single one.' },
76
+ },
77
+ required: ['old', 'new'],
78
+ additionalProperties: false,
79
+ },
80
+ })
67
81
  return {
68
82
  create: object({
69
83
  title: { type: 'string', description: 'Job name in the user\'s language, at most 200 characters: action plus object, without timing or status.' },
@@ -90,6 +104,8 @@ export function toolSchemas(prefix) {
90
104
  title: { type: 'string', description: 'New job name.' },
91
105
  prompt: { ...fields.prompt, description: 'New prompt; an empty string removes it.' },
92
106
  command: { ...fields.command, description: 'New command; an empty string removes it.' },
107
+ prompt_replace: replacements('prompt'),
108
+ command_replace: replacements('command'),
93
109
  answerCheck: { ...fields.answerCheck, description: 'New answer check command; an empty string removes it.' },
94
110
  cron: { ...schedule.cron, description: `${schedule.cron.description} An empty cron, rrule or at removes the schedule of a job with on.` },
95
111
  rrule: schedule.rrule,
@@ -161,7 +177,7 @@ export function createTools({ prefix = 'cron_job', getJobs, ctx }) {
161
177
  `Update, pause, resume or delete one job created with ${prefix}_create, by id. Jobs from the plugin config are read-only.`,
162
178
  async (args, jobs, agent) => {
163
179
  const { id, action } = args
164
- const changes = ['title', 'prompt', 'command', 'answerCheck', 'cron', 'rrule', 'at', 'timeZone', 'target', 'sessionId', 'cwd', 'deliver', 'model', 'on', 'once'].filter(key => args[key] !== undefined)
180
+ const changes = ['title', 'prompt', 'command', 'prompt_replace', 'command_replace', 'answerCheck', 'cron', 'rrule', 'at', 'timeZone', 'target', 'sessionId', 'cwd', 'deliver', 'model', 'on', 'once'].filter(key => args[key] !== undefined)
165
181
  if (action !== 'update' && changes.length > 0) return failure('invalid_arguments', `${action} takes only id and action.`)
166
182
  if (action === 'delete') return await jobs.remove(id)
167
183
  if (action === 'pause' || action === 'resume') {
@@ -171,6 +187,16 @@ export function createTools({ prefix = 'cron_job', getJobs, ctx }) {
171
187
  return modelJob(result.job)
172
188
  }
173
189
  if (changes.length === 0) return failure('invalid_arguments', 'update needs at least one field to change.')
190
+ for (const [field, list] of [['prompt', args.prompt_replace], ['command', args.command_replace]]) {
191
+ if (list === undefined) continue
192
+ if (list.length === 0) return failure('invalid_arguments', `${field}_replace needs at least one replacement.`)
193
+ if (args[field] !== undefined) return failure('invalid_arguments', `give either ${field} or ${field}_replace, not both.`)
194
+ const current = jobs.storedEntry(id).record[field]
195
+ if (current === undefined) return failure('invalid_arguments', `The job has no ${field} to change.`)
196
+ const replaced = applyReplacements(current, list, `${field}_replace`)
197
+ if (replaced.error) return failure('invalid_arguments', replaced.error)
198
+ args = { ...args, [field]: replaced.text }
199
+ }
174
200
  const scheduleGiven = ['cron', 'rrule', 'at', 'timeZone'].some(key => args[key] !== undefined)
175
201
  const targetGiven = args.target !== undefined || args.sessionId !== undefined
176
202
  return modelJob(await jobs.update(id, {
@@ -249,6 +275,25 @@ function parseDeliver(ctx, value) {
249
275
  return { via, to }
250
276
  }
251
277
 
278
+ /**
279
+ * Apply literal {old, new, replace_all} replacements in order, each to the
280
+ * result of the one before. Without replace_all an `old` must match exactly
281
+ * once. All or nothing: returns `{ text }`, or `{ error }` naming the item.
282
+ */
283
+ export function applyReplacements(source, list, label) {
284
+ let text = source
285
+ for (const [index, { old, new: replacement, replace_all: all }] of list.entries()) {
286
+ const where = `${label}[${index}] (old ${JSON.stringify(old.length > 50 ? `${old.slice(0, 50)}…` : old)})`
287
+ if (old === '') return { error: `${where}: old must not be empty. Nothing was changed.` }
288
+ const parts = text.split(old)
289
+ const count = parts.length - 1
290
+ if (count === 0) return { error: `${where}: no match${index > 0 ? ' in the text after the earlier replacements' : ''}. Nothing was changed.` }
291
+ if (count > 1 && all !== true) return { error: `${where}: matches ${count} times; add surrounding text to make it unique or set replace_all. Nothing was changed.` }
292
+ text = parts.join(replacement)
293
+ }
294
+ return { text }
295
+ }
296
+
252
297
  /** The model argument for the controller: undefined or null when it names no model (clears it on edit). */
253
298
  function toModel(value) {
254
299
  if (value === undefined || value === null) return undefined
@@ -354,7 +399,13 @@ export function checkArgs(schema, args) {
354
399
  if (value === undefined) continue
355
400
  if (property.type === 'array') {
356
401
  if (!Array.isArray(value)) return `${key} must be an array`
357
- if (value.some(item => typeof item !== property.items.type)) return `${key} must hold only ${property.items.type}s`
402
+ if (value.some(item => typeof item !== property.items.type || (property.items.type === 'object' && (item === null || Array.isArray(item))))) return `${key} must hold only ${property.items.type}s`
403
+ if (property.items.type === 'object') {
404
+ for (const [index, item] of value.entries()) {
405
+ const inner = checkArgs(property.items, item)
406
+ if (inner) return `${key}[${index}]: ${inner}`
407
+ }
408
+ }
358
409
  continue
359
410
  }
360
411
  if (property.type === 'object') {