@aidenhq/sdk 0.5.19 → 0.5.20

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.
@@ -349,20 +349,28 @@ function editableEnglish(lines, fmt) {
349
349
  const fields = lines.map((l) => (isRefusal(parseSchedule(l, fmt)) ? null : parseSchedule(l, fmt).crons)).flatMap((cs) => (cs?.length === 1 ? [cs[0].split(/\s+/)] : []));
350
350
  if (fields.length !== lines.length)
351
351
  return null;
352
- const day = (f) => [f[2], f[3], f[4] === "*" ? "*" : expandCronDay(f[4])?.join(",")].join(" ");
352
+ // A day field by the dates it expands to, not its text: "01-07" is "1-7", and the order the caller wrote is not the parser's.
353
+ const dd = (f, i) => f === "*" ? "*" : (expand(f, i) ?? []).map(String).join(",");
354
+ const day = (f) => `${dd(f[2], 2)} ${dd(f[3], 3)} ${f[4] === "*" ? "*" : expandCronDay(f[4])?.join(",")}`;
353
355
  if (fields.some((f) => day(f) !== day(fields[0])))
354
356
  return null;
355
357
  const times = [...new Set(lines.flatMap((l) => timesOf([l]) ?? []))].sort((a, b) => a - b);
356
- const [, , dom, mon, dow] = fields[0];
358
+ const [, , dom = "*", mon = "*", dow = "*"] = fields[0];
357
359
  const days = dow === "*" ? [0, 1, 2, 3, 4, 5, 6] : (expandCronDay(dow) ?? []);
360
+ // The first Monday is "the first Monday of every month", never "the 1st": a week of dates (1-7, 8-14, 15-21, 22-28) on one weekday
361
+ // is a weekday rule, by the dates the field expands to however it is spelled ("1-7", "1,2,3,4,5,6,7", "01-07").
362
+ const doms = expand(dom, 2) ?? [];
363
+ const week = doms.length === 7 && doms[0] <= 22 && (doms[0] - 1) % 7 === 0 && doms.every((d, i) => d === doms[0] + i) ? doms[0] : null;
364
+ const nthDay = week !== null && dow !== "*" && days.length === 1 ? `the ${NTH[(week - 1) / 7]} ${LONG[days[0]]} of every month` : null;
358
365
  // A date ("every month on the 1st at 9:00 and 16:30") and a weekday set each read back; a no-day schedule is "every day".
359
- const when = dom !== "*" ? `every month on the ${ordinal(Number(dom))}` : mon !== "*" ? null : days.length === 7 ? "every day" : `on ${englishDays(days)}`;
366
+ const when = nthDay ?? (doms.length === 1 ? `every month on the ${ordinal(doms[0])}` : dom !== "*" ? null : mon !== "*" ? null : days.length === 7 ? "every day" : `on ${englishDays(days)}`);
360
367
  if (!when)
361
368
  return null;
362
369
  const english = `${when} at ${times.map(h24).join(", ")}`;
363
370
  const back = parseSchedule(english, fmt);
364
- // The phrase must mean the same moments, whichever equivalent spelling the caller used.
365
- const signature = (cs) => cs.flatMap((c) => { const f = c.split(/\s+/); const d = f[4] === "*" ? ["*"] : (expandCronDay(f[4]) ?? []); return (timesOf([c]) ?? []).map((t) => `${f[2]} ${f[3]} ${d.join(",")}@${t}`); }).sort().join("|");
371
+ // The phrase must mean the same moments, whichever equivalent spelling the caller used: the day fields by the dates and days they
372
+ // expand to ("01-07" is "1-7"), never their text, so a leading zero doesn't make a schedule read back differently.
373
+ const signature = (cs) => cs.flatMap((c) => { const f = c.split(/\s+/); const d = f[4] === "*" ? ["*"] : (expandCronDay(f[4]) ?? []); return (timesOf([c]) ?? []).map((t) => `${dd(f[2], 2)} ${dd(f[3], 3)} ${d.join(",")}@${t}`); }).sort().join("|");
366
374
  return !isRefusal(back) && signature(back.crons) === signature(lines) ? english : null;
367
375
  }
368
376
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aidenhq/sdk",
3
- "version": "0.5.19",
3
+ "version": "0.5.20",
4
4
  "description": "The shared code of AidenHQ modules: contract types, engine IO, the caller check and fence, write executors, the reviewer side, the judges' models and call, the source writer and the vendor MCP pass-through.",
5
5
  "license": "MIT",
6
6
  "repository": {