// Force strict mode and setup for ESM
"use strict";
import {
  parseCron
} from "./chunk-O4PICXES.js";
import {
  humanReadableCron
} from "./chunk-TW522KN6.js";
import {
  BaseDeclarativeTool,
  BaseToolInvocation,
  ToolDisplayNames,
  ToolNames
} from "./chunk-G763GDO6.js";
import "./chunk-R5PDRHEF.js";
import "./chunk-WFVXF3OM.js";
import {
  init_esbuild_shims
} from "./chunk-A4BMJM77.js";
import {
  __name
} from "./chunk-J2S4EL5Y.js";

// packages/core/src/tools/cron-create.ts
init_esbuild_shims();
var CronCreateInvocation = class extends BaseToolInvocation {
  constructor(config, params) {
    super(params);
    this.config = config;
  }
  static {
    __name(this, "CronCreateInvocation");
  }
  getDescription() {
    return `${this.params.cron}: ${this.params.prompt}`;
  }
  /**
   * The scheduled prompt fires against the agent at cron-trigger time
   * and executes with full tool access. The CronCreateTool's L3 default
   * must NOT be 'allow', because AUTO mode short-circuits at L4 when
   * `finalPermission === 'allow'` — the classifier never runs and an
   * arbitrary scheduled prompt is silently approved. `'ask'` routes
   * the call through the classifier (or manual approval in DEFAULT).
   */
  async getDefaultPermission() {
    return "ask";
  }
  async execute() {
    const scheduler = this.config.getCronScheduler();
    const recurring = this.params.recurring !== false;
    try {
      parseCron(this.params.cron);
      const job = scheduler.create(
        this.params.cron,
        this.params.prompt,
        recurring
      );
      const display = humanReadableCron(job.cronExpr);
      const returnDisplay = `Scheduled ${job.id} (${display})`;
      let llmContent;
      if (recurring) {
        llmContent = `Scheduled recurring job ${job.id} (${job.cronExpr}). Session-only (not written to disk, dies when Qwen Code exits). Auto-expires after 3 days. Use CronDelete to cancel sooner.`;
      } else {
        llmContent = `Scheduled one-shot task ${job.id} (${job.cronExpr}). Session-only (not written to disk, dies when Qwen Code exits). It will fire once then auto-delete.`;
      }
      return { llmContent, returnDisplay };
    } catch (error) {
      const message = error instanceof Error ? error.message : String(error);
      return {
        llmContent: `Error creating cron job: ${message}`,
        returnDisplay: message,
        error: { message }
      };
    }
  }
};
var CronCreateTool = class _CronCreateTool extends BaseDeclarativeTool {
  constructor(config) {
    super(
      _CronCreateTool.Name,
      ToolDisplayNames.CRON_CREATE,
      'Schedule a prompt to be enqueued at a future time. Use for both recurring schedules and one-shot reminders.\n\nUses standard 5-field cron in the user\'s local timezone: minute hour day-of-month month day-of-week. "0 9 * * *" means 9am local \u2014 no timezone conversion needed.\n\n## One-shot tasks (recurring: false)\n\nFor "remind me at X" or "at <time>, do Y" requests \u2014 fire once then auto-delete.\nPin minute/hour/day-of-month/month to specific values:\n  "remind me at 2:30pm today to check the deploy" \u2192 cron: "30 14 <today_dom> <today_month> *", recurring: false\n  "tomorrow morning, run the smoke test" \u2192 cron: "57 8 <tomorrow_dom> <tomorrow_month> *", recurring: false\n\n## Recurring jobs (recurring: true, the default)\n\nFor "every N minutes" / "every hour" / "weekdays at 9am" requests:\n  "*/5 * * * *" (every 5 min), "0 * * * *" (hourly), "0 9 * * 1-5" (weekdays at 9am local)\n\n## Avoid the :00 and :30 minute marks when the task allows it\n\nEvery user who asks for "9am" gets `0 9`, and every user who asks for "hourly" gets `0 *` \u2014 which means requests from across the planet land on the API at the same instant. When the user\'s request is approximate, pick a minute that is NOT 0 or 30:\n  "every morning around 9" \u2192 "57 8 * * *" or "3 9 * * *" (not "0 9 * * *")\n  "hourly" \u2192 "7 * * * *" (not "0 * * * *")\n  "in an hour or so, remind me to..." \u2192 pick whatever minute you land on, don\'t round\n\nOnly use minute 0 or 30 when the user names that exact time and clearly means it ("at 9:00 sharp", "at half past", coordinating with a meeting). When in doubt, nudge a few minutes early or late \u2014 the user will not notice, and the fleet will.\n\n## Session-only\n\nJobs live only in this Qwen Code session \u2014 nothing is written to disk, and the job is gone when Qwen Code exits.\n\n## Runtime behavior\n\nJobs only fire while the REPL is idle (not mid-query). The scheduler adds a small deterministic jitter on top of whatever you pick: recurring tasks fire up to 10% of their period late (max 15 min); one-shot tasks landing on :00 or :30 fire up to 90 s early. Picking an off-minute is still the bigger lever.\n\nRecurring tasks auto-expire after 3 days \u2014 they fire one final time, then are deleted. This bounds session lifetime. Tell the user about the 3-day limit when scheduling recurring jobs.\n\nReturns a job ID you can pass to CronDelete.',
      "other" /* Other */,
      {
        type: "object",
        properties: {
          cron: {
            type: "string",
            description: 'Standard 5-field cron expression in local time: "M H DoM Mon DoW" (e.g. "*/5 * * * *" = every 5 minutes, "30 14 28 2 *" = Feb 28 at 2:30pm local once).'
          },
          prompt: {
            type: "string",
            description: "The prompt to enqueue at each fire time."
          },
          recurring: {
            type: "boolean",
            description: 'true (default) = fire on every cron match until deleted or auto-expired after 3 days. false = fire once at the next match, then auto-delete. Use false for "remind me at X" one-shot requests with pinned minute/hour/dom/month.'
          }
        },
        required: ["cron", "prompt"],
        additionalProperties: false
      },
      true,
      // isOutputMarkdown
      false,
      // canUpdateOutput
      true,
      // shouldDefer — scheduling is infrequent
      false,
      // alwaysLoad
      "cron schedule reminder recurring timer"
    );
    this.config = config;
  }
  static {
    __name(this, "CronCreateTool");
  }
  static Name = ToolNames.CRON_CREATE;
  createInvocation(params) {
    return new CronCreateInvocation(this.config, params);
  }
  /**
   * Forward the prompt and cadence to the classifier. The scheduled
   * prompt will be enqueued and executed against the agent at fire-time,
   * so it must go through the same scrutiny as a direct command. Without
   * this override the default projection returns `''` and the classifier
   * sees `cron_create({})` — blind to what the agent will be asked to
   * do in 8 hours.
   */
  toAutoClassifierInput(params) {
    return {
      cron: params.cron,
      prompt: params.prompt,
      recurring: params.recurring ?? true
    };
  }
};
export {
  CronCreateTool
};
