sideby 0.28.3 → 0.30.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 (64) hide show
  1. package/dist/build.json +1 -1
  2. package/dist/src/cli/commands.d.ts +12 -0
  3. package/dist/src/cli/commands.js +337 -13
  4. package/dist/src/cli/json-schemas.js +87 -1
  5. package/dist/src/cli/main.js +65 -4
  6. package/dist/src/core/config.d.ts +25 -0
  7. package/dist/src/core/config.js +34 -0
  8. package/dist/src/core/fs-safe.d.ts +22 -1
  9. package/dist/src/core/fs-safe.js +68 -1
  10. package/dist/src/core/handoff-run.d.ts +2 -0
  11. package/dist/src/core/handoff-run.js +12 -6
  12. package/dist/src/core/launch.d.ts +6 -1
  13. package/dist/src/core/live-sessions.d.ts +2 -0
  14. package/dist/src/core/messages.d.ts +2 -0
  15. package/dist/src/core/messages.js +12 -34
  16. package/dist/src/core/network.d.ts +5 -2
  17. package/dist/src/core/network.js +15 -45
  18. package/dist/src/core/run-link.d.ts +6 -1
  19. package/dist/src/core/run-link.js +62 -22
  20. package/dist/src/core/search-catalog.d.ts +1 -1
  21. package/dist/src/core/search-catalog.js +37 -0
  22. package/dist/src/core/session-handoffs.d.ts +22 -0
  23. package/dist/src/core/session-handoffs.js +110 -0
  24. package/dist/src/core/session-hooks.d.ts +33 -0
  25. package/dist/src/core/session-hooks.js +92 -0
  26. package/dist/src/core/session-select.d.ts +18 -3
  27. package/dist/src/core/session-select.js +82 -8
  28. package/dist/src/core/unattended-ended.d.ts +62 -0
  29. package/dist/src/core/unattended-ended.js +275 -0
  30. package/dist/src/core/unattended-pending.d.ts +56 -0
  31. package/dist/src/core/unattended-pending.js +182 -0
  32. package/dist/src/core/unattended-state.d.ts +129 -0
  33. package/dist/src/core/unattended-state.js +373 -0
  34. package/dist/src/core/unattended.d.ts +142 -0
  35. package/dist/src/core/unattended.js +349 -0
  36. package/dist/src/panel/background.js +8 -0
  37. package/dist/src/panel/handler.d.ts +37 -0
  38. package/dist/src/panel/handler.js +156 -2
  39. package/dist/src/panel/i18n.d.ts +97 -0
  40. package/dist/src/panel/i18n.js +194 -0
  41. package/dist/src/panel/page-logic.d.ts +129 -0
  42. package/dist/src/panel/page-logic.js +166 -0
  43. package/dist/src/panel/page-script.js +638 -7
  44. package/dist/src/panel/page-styles.js +69 -0
  45. package/dist/src/panel/page.js +2 -0
  46. package/dist/src/plugins/bus.js +1 -0
  47. package/dist/src/runtime.d.ts +17 -1
  48. package/dist/src/runtime.js +78 -15
  49. package/dist/src/types.d.ts +48 -0
  50. package/dist/src/unattended/hook.d.ts +46 -0
  51. package/dist/src/unattended/hook.js +288 -0
  52. package/package.json +1 -1
  53. package/schemas/config.json +76 -0
  54. package/schemas/messages.json +4 -0
  55. package/schemas/send.json +4 -0
  56. package/schemas/sessions-copy.json +4 -0
  57. package/schemas/sessions-open-run.json +4 -0
  58. package/schemas/sessions.json +7 -0
  59. package/schemas/unattended-defer.json +143 -0
  60. package/schemas/unattended-pending.json +154 -0
  61. package/schemas/unattended.json +291 -0
  62. package/skills/sideby/SKILL.md +3 -2
  63. package/skills/sideby/references/sessions.md +1 -1
  64. package/skills/sideby/references/unattended.md +58 -0
@@ -1721,3 +1721,169 @@ export function enableOutcome(r) {
1721
1721
  const bad = r.results.find((x) => !x.ok);
1722
1722
  return bad ? { kind: 'failed', step: bad, plan: r.plan } : { kind: 'done' };
1723
1723
  }
1724
+ // ---------- Unattended Mode (spec §3.37) ----------
1725
+ /**
1726
+ * A moment as the Unattended page says it, relative to now in this computer's time zone: today (`08:00`), tomorrow,
1727
+ * a weekday within the coming week (0 = Sunday, as `Date.getDay`), else a date. The page words it in its language.
1728
+ */
1729
+ export function uaWhen(atMs, nowMs) {
1730
+ const d = new Date(atMs);
1731
+ const hhmm = `${String(d.getHours()).padStart(2, '0')}:${String(d.getMinutes()).padStart(2, '0')}`;
1732
+ const midnight = (x) => new Date(x.getFullYear(), x.getMonth(), x.getDate()).getTime();
1733
+ const days = Math.round((midnight(d) - midnight(new Date(nowMs))) / 86400000);
1734
+ const day = days === 0 ? 'today' : days === 1 ? 'tomorrow' : days > 1 && days < 7 ? 'week' : 'date';
1735
+ return { hhmm, day, weekday: d.getDay(), month: d.getMonth() + 1, date: d.getDate() };
1736
+ }
1737
+ /**
1738
+ * The status card's sentence (like Android's Do Not Disturb): on (by a Slot or by hand), paused, or off; with the
1739
+ * Slot, when it ends or comes back, and when a Slot turns it on next. `noEnd`: the Schedule covers every hour.
1740
+ */
1741
+ export function uaStatusParts(s) {
1742
+ const until = s.until ? Date.parse(s.until) : null;
1743
+ const state = s.on && s.reason !== 'session' ? 'on' : s.reason === 'paused' ? 'paused' : 'off';
1744
+ return {
1745
+ state,
1746
+ byHand: state === 'on' && s.reason === 'manual',
1747
+ slot: s.slotNumber ? s.slotNumber - 1 : null,
1748
+ until,
1749
+ noEnd: state !== 'off' && until === null,
1750
+ next: s.next
1751
+ ? { at: Date.parse(s.next.at), slot: s.next.slotNumber ? s.next.slotNumber - 1 : null }
1752
+ : null,
1753
+ };
1754
+ }
1755
+ /**
1756
+ * What "Turn on now" offers (spec §3.37): until the current or next Slot ends (only when there is one within 72
1757
+ * hours), 4 hours, 12 hours, or a time the user picks. The first is chosen; without a Slot, 12 hours.
1758
+ */
1759
+ export function uaOnChoices(slotEnd, nowMs) {
1760
+ const hour = 3600000;
1761
+ const options = [];
1762
+ if (slotEnd)
1763
+ options.push({ id: 'slot', until: Date.parse(slotEnd) });
1764
+ options.push({ id: '4h', until: nowMs + 4 * hour }, { id: '12h', until: nowMs + 12 * hour }, { id: 'time', until: null });
1765
+ return { options, chosen: slotEnd ? 'slot' : '12h' };
1766
+ }
1767
+ /**
1768
+ * When a picked clock time (`HH:MM`) is: today when that is still ahead, else tomorrow, built from the day so a clock
1769
+ * change in between does not move the hour (the server reads `until` the same way). Null for anything else.
1770
+ */
1771
+ export function uaPickTime(hhmm, nowMs) {
1772
+ const m = /^([01]\d|2[0-3]):([0-5]\d)$/.exec(hhmm);
1773
+ if (!m)
1774
+ return null;
1775
+ const now = new Date(nowMs);
1776
+ const [y, mo, d] = [now.getFullYear(), now.getMonth(), now.getDate()];
1777
+ const today = new Date(y, mo, d, Number(m[1]), Number(m[2])).getTime();
1778
+ return today > nowMs
1779
+ ? { until: today, tomorrow: false }
1780
+ : { until: new Date(y, mo, d + 1, Number(m[1]), Number(m[2])).getTime(), tomorrow: true };
1781
+ }
1782
+ /** What follows a Slot's end time: `next` (it ends the next day) or `whole` (start equals end: 24 hours). */
1783
+ export function uaSlotNight(slot) {
1784
+ return slot.end === slot.start ? 'whole' : slot.end < slot.start ? 'next' : '';
1785
+ }
1786
+ /**
1787
+ * A Slot's days as runs of days in a row, Monday first (0 = Monday): `[[0, 4]]` for Monday to Friday, `[[4, 0]]` for
1788
+ * Friday to Monday; `all` when every day is in it.
1789
+ */
1790
+ export function uaDayRuns(days) {
1791
+ const days7 = ['mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun'];
1792
+ const on = days7.map((d) => days.includes(d));
1793
+ if (on.every(Boolean))
1794
+ return { all: true, runs: [] };
1795
+ const first = on.indexOf(false);
1796
+ const runs = [];
1797
+ for (let k = 1; k <= 7; k++) {
1798
+ const i = (first + k) % 7;
1799
+ if (!on[i])
1800
+ continue;
1801
+ const last = runs[runs.length - 1];
1802
+ if (k > 1 && on[(i + 6) % 7] && last)
1803
+ last[1] = i;
1804
+ else
1805
+ runs.push([i, i]);
1806
+ }
1807
+ return { all: false, runs: runs.sort((a, b) => a[0] - b[0]) };
1808
+ }
1809
+ /** A day chip pressed: the days with it added or taken away, in week order; null when it would leave none. */
1810
+ export function uaToggleDay(days, day) {
1811
+ const days7 = ['mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun'];
1812
+ const next = days.includes(day) ? days.filter((d) => d !== day) : [...days, day];
1813
+ return next.length ? days7.filter((d) => next.includes(d)) : null;
1814
+ }
1815
+ /** Whether two Slots cover the same days and times (names aside). */
1816
+ export function uaSameSlot(a, b) {
1817
+ return (a.start === b.start &&
1818
+ a.end === b.end &&
1819
+ a.days.length === b.days.length &&
1820
+ a.days.every((d) => b.days.includes(d)));
1821
+ }
1822
+ /**
1823
+ * Pending Decisions grouped by the Session that left them, the group with the newest one first and each group oldest
1824
+ * first; those kept outside a Session (`sideby unattended defer` in a terminal) form one group without a session.
1825
+ */
1826
+ export function uaGroupPending(list) {
1827
+ const groups = new Map();
1828
+ for (const d of [...list].sort((a, b) => Date.parse(a.at) - Date.parse(b.at) || a.id.localeCompare(b.id))) {
1829
+ const key = d.sessionId ? `s:${d.sessionId}` : 'none';
1830
+ groups.set(key, [...(groups.get(key) ?? []), d]);
1831
+ }
1832
+ const newest = (items) => Date.parse(items[items.length - 1].at);
1833
+ return [...groups]
1834
+ .sort(([, a], [, b]) => newest(b) - newest(a))
1835
+ .map(([key, items]) => ({ key, first: items[0], items }));
1836
+ }
1837
+ /**
1838
+ * A time typed into the Unattended page's 24-hour fields as `HH:MM`, or null when it is not one. Takes `7:30`,
1839
+ * `07:30`, `730`, `0730`, `7` (07:00), and the full-width colon a Chinese input method types; the field's `pattern`
1840
+ * accepts the same.
1841
+ */
1842
+ export function uaParseClock(text) {
1843
+ const m = /^ *([01]?[0-9]|2[0-3])(?:[::.]?([0-5][0-9]))? *$/.exec(text);
1844
+ if (!m)
1845
+ return null;
1846
+ return `${m[1].padStart(2, '0')}:${m[2] ?? '00'}`;
1847
+ }
1848
+ /** An arrow key in a time field: the hour or the minute one up or down, wrapping like the browser's own time field. */
1849
+ export function uaStepClock(text, part, delta) {
1850
+ const clock = /^ *([01]?[0-9]|2[0-3])(?:[::.]?([0-5][0-9]))? *$/.exec(text);
1851
+ if (!clock)
1852
+ return null;
1853
+ let h = Number(clock[1]);
1854
+ let m = Number(clock[2] ?? 0);
1855
+ if (part === 'h')
1856
+ h = (((h + delta) % 24) + 24) % 24;
1857
+ else
1858
+ m = (((m + delta) % 60) + 60) % 60;
1859
+ return `${String(h).padStart(2, '0')}:${String(m).padStart(2, '0')}`;
1860
+ }
1861
+ /**
1862
+ * Whether the Unattended page reads its Pending Decisions now: at once the first time; otherwise not before `nextAt`
1863
+ * (a failed read puts it a full refresh round away, so a count that changed meanwhile cannot make it try again at
1864
+ * once), then when the last read is `everyMs` old, failed, or the status counts a different number than the list.
1865
+ */
1866
+ export function uaShouldRead(o) {
1867
+ if (o.loading)
1868
+ return false;
1869
+ if (!o.hasData && !o.failed)
1870
+ return true;
1871
+ if (o.now < o.nextAt)
1872
+ return false;
1873
+ return (o.now - o.at >= o.everyMs ||
1874
+ o.failed ||
1875
+ (o.hasData && o.statusCount !== undefined && o.statusCount !== o.listCount));
1876
+ }
1877
+ /**
1878
+ * How many Pending Decisions wait, as the Unattended tab counts them: the ones the latest status lists, less those
1879
+ * being marked done right now (`inflight`, each with the status it was made on). A status that lists its ids
1880
+ * subtracts only the ids it still has, so a status read after the server took a mark does not count it twice; one
1881
+ * without ids subtracts only the marks made on that same status.
1882
+ */
1883
+ export function uaWaitingCount(status, inflight) {
1884
+ if (!status)
1885
+ return 0;
1886
+ if (Array.isArray(status.pendingIds))
1887
+ return status.pendingIds.filter((id) => !inflight.some((x) => x.id === id)).length;
1888
+ return Math.max(0, status.pending - inflight.filter((x) => x.on === status).length);
1889
+ }