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.
- package/dist/build.json +1 -1
- package/dist/src/cli/commands.d.ts +12 -0
- package/dist/src/cli/commands.js +337 -13
- package/dist/src/cli/json-schemas.js +87 -1
- package/dist/src/cli/main.js +65 -4
- package/dist/src/core/config.d.ts +25 -0
- package/dist/src/core/config.js +34 -0
- package/dist/src/core/fs-safe.d.ts +22 -1
- package/dist/src/core/fs-safe.js +68 -1
- package/dist/src/core/handoff-run.d.ts +2 -0
- package/dist/src/core/handoff-run.js +12 -6
- package/dist/src/core/launch.d.ts +6 -1
- package/dist/src/core/live-sessions.d.ts +2 -0
- package/dist/src/core/messages.d.ts +2 -0
- package/dist/src/core/messages.js +12 -34
- package/dist/src/core/network.d.ts +5 -2
- package/dist/src/core/network.js +15 -45
- package/dist/src/core/run-link.d.ts +6 -1
- package/dist/src/core/run-link.js +62 -22
- package/dist/src/core/search-catalog.d.ts +1 -1
- package/dist/src/core/search-catalog.js +37 -0
- package/dist/src/core/session-handoffs.d.ts +22 -0
- package/dist/src/core/session-handoffs.js +110 -0
- package/dist/src/core/session-hooks.d.ts +33 -0
- package/dist/src/core/session-hooks.js +92 -0
- package/dist/src/core/session-select.d.ts +18 -3
- package/dist/src/core/session-select.js +82 -8
- package/dist/src/core/unattended-ended.d.ts +62 -0
- package/dist/src/core/unattended-ended.js +275 -0
- package/dist/src/core/unattended-pending.d.ts +56 -0
- package/dist/src/core/unattended-pending.js +182 -0
- package/dist/src/core/unattended-state.d.ts +129 -0
- package/dist/src/core/unattended-state.js +373 -0
- package/dist/src/core/unattended.d.ts +142 -0
- package/dist/src/core/unattended.js +349 -0
- package/dist/src/panel/background.js +8 -0
- package/dist/src/panel/handler.d.ts +37 -0
- package/dist/src/panel/handler.js +156 -2
- package/dist/src/panel/i18n.d.ts +97 -0
- package/dist/src/panel/i18n.js +194 -0
- package/dist/src/panel/page-logic.d.ts +129 -0
- package/dist/src/panel/page-logic.js +166 -0
- package/dist/src/panel/page-script.js +638 -7
- package/dist/src/panel/page-styles.js +69 -0
- package/dist/src/panel/page.js +2 -0
- package/dist/src/plugins/bus.js +1 -0
- package/dist/src/runtime.d.ts +17 -1
- package/dist/src/runtime.js +78 -15
- package/dist/src/types.d.ts +48 -0
- package/dist/src/unattended/hook.d.ts +46 -0
- package/dist/src/unattended/hook.js +288 -0
- package/package.json +1 -1
- package/schemas/config.json +76 -0
- package/schemas/messages.json +4 -0
- package/schemas/send.json +4 -0
- package/schemas/sessions-copy.json +4 -0
- package/schemas/sessions-open-run.json +4 -0
- package/schemas/sessions.json +7 -0
- package/schemas/unattended-defer.json +143 -0
- package/schemas/unattended-pending.json +154 -0
- package/schemas/unattended.json +291 -0
- package/skills/sideby/SKILL.md +3 -2
- package/skills/sideby/references/sessions.md +1 -1
- package/skills/sideby/references/unattended.md +58 -0
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
// Pending Decisions (spec §3.37, ADR-0058): questions the model was not allowed to ask, permission requests nobody was
|
|
2
|
+
// there to answer, and actions it left undone, while Unattended Mode was on. One file each under `<state>/unattended/pending/` (folder 700, files 600), so writes
|
|
3
|
+
// from several sessions never meet. Kept until the user marks one done, deleted 30 days after that. A leaf module
|
|
4
|
+
// (Node built-ins and core/fs-safe.ts only): `unattended-hook` writes here.
|
|
5
|
+
//
|
|
6
|
+
// Both folders must be real folders of the user that nobody else can write to (`ownedFolder`); when one is not, nothing
|
|
7
|
+
// is read from or written there. Files are read without following a link.
|
|
8
|
+
import { randomBytes } from 'node:crypto';
|
|
9
|
+
import { readdir, rm } from 'node:fs/promises';
|
|
10
|
+
import { join } from 'node:path';
|
|
11
|
+
import { ownedFolder, readSmallFile, writeFileAtomic } from './fs-safe.js';
|
|
12
|
+
export const PENDING_KINDS = ['question', 'permission', 'deferred'];
|
|
13
|
+
export const PENDING_TEXT_MAX = 4000;
|
|
14
|
+
const KEEP_DONE_MS = 30 * 24 * 60 * 60 * 1000;
|
|
15
|
+
const ID = /^[a-z0-9]{6,16}-[0-9a-f]{6}$/;
|
|
16
|
+
const FIELD = /^[\x20-\x7e]{1,256}$/;
|
|
17
|
+
export const pendingDir = (stateDir) => join(stateDir, 'unattended', 'pending');
|
|
18
|
+
const PARTS = ['unattended', 'pending'];
|
|
19
|
+
/** The pending folder, made (mode 700) when missing; throws `UnsafeFolderError` when a level is not safe to use. */
|
|
20
|
+
async function ensureDir(stateDir) {
|
|
21
|
+
return (await ownedFolder(stateDir, PARTS, { create: true, private: true }));
|
|
22
|
+
}
|
|
23
|
+
/** The pending folder when it exists and is safe to read; null otherwise. */
|
|
24
|
+
async function existingDir(stateDir) {
|
|
25
|
+
return ownedFolder(stateDir, PARTS, { create: false }).catch(() => null);
|
|
26
|
+
}
|
|
27
|
+
/** At most `PENDING_TEXT_MAX` characters (whole characters, never half of one), ending in `…` when cut. */
|
|
28
|
+
export function clipPendingText(text) {
|
|
29
|
+
const chars = [...text.trim()];
|
|
30
|
+
return chars.length <= PENDING_TEXT_MAX
|
|
31
|
+
? chars.join('')
|
|
32
|
+
: `${chars.slice(0, PENDING_TEXT_MAX - 1).join('')}…`;
|
|
33
|
+
}
|
|
34
|
+
function parse(value) {
|
|
35
|
+
if (!value || typeof value !== 'object')
|
|
36
|
+
return undefined;
|
|
37
|
+
const v = value;
|
|
38
|
+
if (typeof v.id !== 'string' || !ID.test(v.id))
|
|
39
|
+
return undefined;
|
|
40
|
+
if (typeof v.at !== 'string' || !Number.isFinite(Date.parse(v.at)))
|
|
41
|
+
return undefined;
|
|
42
|
+
if (!PENDING_KINDS.includes(v.kind))
|
|
43
|
+
return undefined;
|
|
44
|
+
if (typeof v.family !== 'string' || !FIELD.test(v.family) || typeof v.text !== 'string')
|
|
45
|
+
return undefined;
|
|
46
|
+
const opt = (k) => typeof v[k] === 'string' && v[k] ? { [k]: v[k].slice(0, 4096) } : {};
|
|
47
|
+
const done = typeof v.doneAt === 'string' && Number.isFinite(Date.parse(v.doneAt)) ? { doneAt: v.doneAt } : {};
|
|
48
|
+
return {
|
|
49
|
+
id: v.id,
|
|
50
|
+
at: v.at,
|
|
51
|
+
kind: v.kind,
|
|
52
|
+
family: v.family,
|
|
53
|
+
...opt('account'),
|
|
54
|
+
...opt('sessionId'),
|
|
55
|
+
...opt('cwd'),
|
|
56
|
+
...opt('agentId'),
|
|
57
|
+
...opt('agentType'),
|
|
58
|
+
text: clipPendingText(v.text),
|
|
59
|
+
...done,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
async function readOne(file) {
|
|
63
|
+
const text = await readSmallFile(file, 64 * 1024);
|
|
64
|
+
if (text === undefined)
|
|
65
|
+
return undefined;
|
|
66
|
+
try {
|
|
67
|
+
return parse(JSON.parse(text));
|
|
68
|
+
}
|
|
69
|
+
catch {
|
|
70
|
+
return undefined;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
async function readAll(stateDir) {
|
|
74
|
+
const dir = await existingDir(stateDir);
|
|
75
|
+
if (!dir)
|
|
76
|
+
return [];
|
|
77
|
+
let names;
|
|
78
|
+
try {
|
|
79
|
+
names = await readdir(dir);
|
|
80
|
+
}
|
|
81
|
+
catch {
|
|
82
|
+
return [];
|
|
83
|
+
}
|
|
84
|
+
const ids = names.filter((n) => n.endsWith('.json')).map((n) => n.slice(0, -5));
|
|
85
|
+
const read = await Promise.all(ids.filter((id) => ID.test(id)).map((id) => readOne(join(dir, `${id}.json`))));
|
|
86
|
+
return read
|
|
87
|
+
.filter((d) => d !== undefined)
|
|
88
|
+
.sort((a, b) => Date.parse(a.at) - Date.parse(b.at) || a.id.localeCompare(b.id));
|
|
89
|
+
}
|
|
90
|
+
const fileOf = (stateDir, id) => join(pendingDir(stateDir), `${id}.json`);
|
|
91
|
+
/**
|
|
92
|
+
* Keeps one Pending Decision and returns it. With `dedupe`, an open one of the same kind, session and text is
|
|
93
|
+
* returned instead of a second copy (a model that asks the same question twice leaves one).
|
|
94
|
+
*/
|
|
95
|
+
export async function addPendingDecision(stateDir, input, at = new Date(), opts = {}) {
|
|
96
|
+
const text = clipPendingText(input.text);
|
|
97
|
+
if (opts.dedupe) {
|
|
98
|
+
const same = (await readAll(stateDir)).find((d) => !d.doneAt && d.kind === input.kind && d.sessionId === input.sessionId && d.text === text);
|
|
99
|
+
if (same)
|
|
100
|
+
return same;
|
|
101
|
+
}
|
|
102
|
+
const dir = await ensureDir(stateDir);
|
|
103
|
+
const decision = {
|
|
104
|
+
id: `${at.getTime().toString(36)}-${randomBytes(3).toString('hex')}`,
|
|
105
|
+
at: at.toISOString(),
|
|
106
|
+
kind: input.kind,
|
|
107
|
+
family: input.family,
|
|
108
|
+
...(input.account ? { account: input.account } : {}),
|
|
109
|
+
...(input.sessionId ? { sessionId: input.sessionId } : {}),
|
|
110
|
+
...(input.cwd ? { cwd: input.cwd } : {}),
|
|
111
|
+
...(input.agentId ? { agentId: input.agentId } : {}),
|
|
112
|
+
...(input.agentType ? { agentType: input.agentType } : {}),
|
|
113
|
+
text,
|
|
114
|
+
};
|
|
115
|
+
await writeFileAtomic(join(dir, `${decision.id}.json`), `${JSON.stringify(decision)}\n`, 0o600);
|
|
116
|
+
return decision;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* The Pending Decisions, oldest first: open ones, or with `all` the done ones too. Deletes the files of those done
|
|
120
|
+
* more than 30 days ago.
|
|
121
|
+
*/
|
|
122
|
+
export async function listPendingDecisions(stateDir,
|
|
123
|
+
/** `prune: false` only reads (a read-only Panel): old done ones are left out but not deleted. */
|
|
124
|
+
opts = {}) {
|
|
125
|
+
const now = (opts.now ?? new Date()).getTime();
|
|
126
|
+
const out = [];
|
|
127
|
+
for (const d of await readAll(stateDir)) {
|
|
128
|
+
if (d.doneAt && now - Date.parse(d.doneAt) > KEEP_DONE_MS) {
|
|
129
|
+
if (opts.prune !== false)
|
|
130
|
+
await rm(fileOf(stateDir, d.id), { force: true }).catch(() => { });
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
if (opts.all || !d.doneAt)
|
|
134
|
+
out.push(d);
|
|
135
|
+
}
|
|
136
|
+
return out;
|
|
137
|
+
}
|
|
138
|
+
/** Opens a Pending Decision marked done again (the Panel's Undo after "Done"); throws when there is no such id. */
|
|
139
|
+
export async function reopenPendingDecision(stateDir, id) {
|
|
140
|
+
const d = (await readAll(stateDir)).find((x) => x.id === id);
|
|
141
|
+
if (!d)
|
|
142
|
+
throw new Error(`no Pending Decision has the id "${id}"; \`sideby unattended pending --all\` lists them`);
|
|
143
|
+
if (!d.doneAt)
|
|
144
|
+
return d;
|
|
145
|
+
const { doneAt: _, ...open } = d;
|
|
146
|
+
await ensureDir(stateDir);
|
|
147
|
+
await writeFileAtomic(fileOf(stateDir, d.id), `${JSON.stringify(open)}\n`, 0o600);
|
|
148
|
+
return open;
|
|
149
|
+
}
|
|
150
|
+
/** The open Pending Decision an id names: the whole id, or a start of it that only one has. */
|
|
151
|
+
export async function findPendingDecision(stateDir, id) {
|
|
152
|
+
const all = await readAll(stateDir);
|
|
153
|
+
const exact = all.find((d) => d.id === id);
|
|
154
|
+
if (exact)
|
|
155
|
+
return exact;
|
|
156
|
+
const starts = all.filter((d) => id.length >= 4 && d.id.startsWith(id));
|
|
157
|
+
return starts.length === 1 ? starts[0] : undefined;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Marks Pending Decisions done: one by id (or a unique start of it), or every open one with `'all'`. Returns the ones
|
|
161
|
+
* it marked; an id no Pending Decision has throws an Error whose message says how to list them.
|
|
162
|
+
*/
|
|
163
|
+
export async function markPendingDone(stateDir, id, at = new Date()) {
|
|
164
|
+
const targets = id === 'all'
|
|
165
|
+
? (await readAll(stateDir)).filter((d) => !d.doneAt)
|
|
166
|
+
: [await findPendingDecision(stateDir, id)].filter((d) => d !== undefined);
|
|
167
|
+
if (id !== 'all' && !targets.length)
|
|
168
|
+
throw new Error(`no Pending Decision has the id "${id}"; \`sideby unattended pending --all\` lists them`);
|
|
169
|
+
if (targets.length)
|
|
170
|
+
await ensureDir(stateDir);
|
|
171
|
+
const out = [];
|
|
172
|
+
for (const d of targets) {
|
|
173
|
+
if (d.doneAt) {
|
|
174
|
+
out.push(d);
|
|
175
|
+
continue;
|
|
176
|
+
}
|
|
177
|
+
const done = { ...d, doneAt: at.toISOString() };
|
|
178
|
+
await writeFileAtomic(fileOf(stateDir, d.id), `${JSON.stringify(done)}\n`, 0o600);
|
|
179
|
+
out.push(done);
|
|
180
|
+
}
|
|
181
|
+
return out;
|
|
182
|
+
}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
export declare const DAYS: readonly ['mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun'];
|
|
2
|
+
export type Day = (typeof DAYS)[number];
|
|
3
|
+
/** One entry of the Schedule: local days, start and end (`HH:MM`); an end before the start runs past midnight. */
|
|
4
|
+
export interface UnattendedSlot {
|
|
5
|
+
name?: string;
|
|
6
|
+
days: Day[];
|
|
7
|
+
start: string;
|
|
8
|
+
end: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* The manual state: on until `until`, or paused (during a Slot) until `until`. A pause without `until` was made while
|
|
12
|
+
* the Schedule covers every hour: it lasts until the user turns it on again, or until the Schedule changes so that the
|
|
13
|
+
* stretch it was made in ends. `at` is when the user chose it.
|
|
14
|
+
*/
|
|
15
|
+
export interface UnattendedOverride {
|
|
16
|
+
mode: 'on' | 'pause';
|
|
17
|
+
/** Always set for `on`. */
|
|
18
|
+
until?: string;
|
|
19
|
+
at: string;
|
|
20
|
+
}
|
|
21
|
+
export type UnattendedReason = 'slot' | 'manual' | 'session' | 'paused' | 'off';
|
|
22
|
+
export interface UnattendedState {
|
|
23
|
+
on: boolean;
|
|
24
|
+
/** slot: a Slot turned it on; manual: the user did; session: only this session (`--unattended`); paused: off until the Slot ends. */
|
|
25
|
+
reason: UnattendedReason;
|
|
26
|
+
/**
|
|
27
|
+
* When it turns off (on), or comes back (paused). Absent for a session alone, and when the Schedule covers every hour:
|
|
28
|
+
* then it is on with no end, or paused until the user turns it on.
|
|
29
|
+
*/
|
|
30
|
+
until?: string;
|
|
31
|
+
/** The Slot it is in: its name, or its days and times when it has none. */
|
|
32
|
+
slot?: string;
|
|
33
|
+
/** That Slot's number in the Schedule, from 1 (as `sideby unattended` numbers them). */
|
|
34
|
+
slotNumber?: number;
|
|
35
|
+
/** The next time a Slot turns it on by itself, and which Slot (its label and number). */
|
|
36
|
+
next?: {
|
|
37
|
+
at: string;
|
|
38
|
+
slot: string;
|
|
39
|
+
slotNumber?: number;
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
/** A stretch of time it is on, in milliseconds since epoch. */
|
|
43
|
+
export interface Stretch {
|
|
44
|
+
start: number;
|
|
45
|
+
end: number;
|
|
46
|
+
reason: 'slot' | 'manual';
|
|
47
|
+
slot?: string;
|
|
48
|
+
/** The Slot's number in the Schedule, from 1. */
|
|
49
|
+
slotNumber?: number;
|
|
50
|
+
}
|
|
51
|
+
/** Set in the environment of a session started with `--unattended`: on for that session, whatever the Schedule says. */
|
|
52
|
+
export declare const UNATTENDED_ENV = "SIDEBY_UNATTENDED";
|
|
53
|
+
/** The longest the user can turn it on by hand. */
|
|
54
|
+
export declare const MAX_MANUAL_MS: number;
|
|
55
|
+
export declare const unattendedDir: (stateDir: string) => string;
|
|
56
|
+
/** `8:05` or `08:05` as `08:05`; undefined for anything else. */
|
|
57
|
+
export declare function parseClock(text: string): string | undefined;
|
|
58
|
+
/**
|
|
59
|
+
* Days as the CLI takes them: `mon-fri`, `sat,sun`, `fri-mon` (a range may wrap past Sunday), `weekdays`, `weekends`,
|
|
60
|
+
* `daily`. In week order; undefined when a part is not a day.
|
|
61
|
+
*/
|
|
62
|
+
export declare function parseDays(text: string): Day[] | undefined;
|
|
63
|
+
/** `mon-fri`, `sat,sun`, `fri-mon`: the shortest way to write the days, in week order (a run may wrap past Sunday). */
|
|
64
|
+
export declare function daysText(days: readonly Day[]): string;
|
|
65
|
+
/** What a Slot is called on screen: its name, or its days and times. */
|
|
66
|
+
export declare function slotLabel(slot: UnattendedSlot): string;
|
|
67
|
+
/** A Slot checked by hand, the way `unattended-hook` reads the config: anything malformed is left out. */
|
|
68
|
+
export declare function parseSlot(value: unknown): UnattendedSlot | undefined;
|
|
69
|
+
/** The Schedule from config's `unattended.schedule`; a malformed Slot is left out, a malformed list is empty. */
|
|
70
|
+
export declare function parseSchedule(value: unknown): UnattendedSlot[];
|
|
71
|
+
/** The manual state from its file's content; undefined when it is not one. */
|
|
72
|
+
export declare function parseOverride(value: unknown): UnattendedOverride | undefined;
|
|
73
|
+
/**
|
|
74
|
+
* Every time a Slot is on that overlaps `[from, to)`, in local time: a Slot whose end is before its start runs past
|
|
75
|
+
* midnight and belongs to its start day; one whose end equals its start lasts the whole day (24 hours).
|
|
76
|
+
*/
|
|
77
|
+
export declare function slotOccurrences(schedule: readonly UnattendedSlot[], from: number, to: number): Stretch[];
|
|
78
|
+
/** Joins stretches that overlap or touch; each keeps how its first part began. */
|
|
79
|
+
export declare function mergeStretches(list: readonly Stretch[]): Stretch[];
|
|
80
|
+
/**
|
|
81
|
+
* The Schedule's stretch running at `at` (joined Slots count as one), and whether it never ends: it fills the whole
|
|
82
|
+
* window laid out around `at`, so the Schedule covers every hour.
|
|
83
|
+
*/
|
|
84
|
+
export declare function scheduleStretchAt(schedule: readonly UnattendedSlot[], at: number): {
|
|
85
|
+
stretch: Stretch;
|
|
86
|
+
endless: boolean;
|
|
87
|
+
} | undefined;
|
|
88
|
+
/**
|
|
89
|
+
* When it was or will be on for the whole computer within `[from, to)`: the Slots and the manual "on" joined (the
|
|
90
|
+
* later end wins), the pause taken out. A stretch that runs past the window is cut at its edge.
|
|
91
|
+
*/
|
|
92
|
+
export declare function unattendedTimeline(schedule: readonly UnattendedSlot[], override: UnattendedOverride | undefined, from: number, to: number): Stretch[];
|
|
93
|
+
/**
|
|
94
|
+
* When `on --slot-end` ends: the end of the Slot it is in now, else of the next one (joined Slots count as one).
|
|
95
|
+
* Undefined when there is no Slot, or when the Schedule covers every hour and so never ends.
|
|
96
|
+
*/
|
|
97
|
+
export declare function slotEnd(schedule: readonly UnattendedSlot[], now: Date): number | undefined;
|
|
98
|
+
/** Whether it is on now, why, until when, and when a Slot turns it on next. */
|
|
99
|
+
export declare function unattendedState(input: {
|
|
100
|
+
schedule: readonly UnattendedSlot[];
|
|
101
|
+
override?: UnattendedOverride | undefined;
|
|
102
|
+
now: Date;
|
|
103
|
+
/** The session was started with `--unattended` (`SIDEBY_UNATTENDED=1`). */
|
|
104
|
+
session?: boolean;
|
|
105
|
+
}): UnattendedState;
|
|
106
|
+
/** Reads a small JSON file that must be a plain file (opened without following a link); undefined otherwise. */
|
|
107
|
+
export declare function readSmallJson(file: string, max?: number): Promise<unknown>;
|
|
108
|
+
/** What the config file says about Unattended Mode, read by hand (no schema): whether it has the section, and its Schedule. */
|
|
109
|
+
export declare function readUnattendedConfig(configFile: string): Promise<{
|
|
110
|
+
configured: boolean;
|
|
111
|
+
schedule: UnattendedSlot[];
|
|
112
|
+
}>;
|
|
113
|
+
/**
|
|
114
|
+
* The manual state as the file holds it, expired or not; undefined when there is none, it is not one, or
|
|
115
|
+
* `<state>/unattended` is not a real folder of the user that nobody else can write to.
|
|
116
|
+
*/
|
|
117
|
+
export declare function readUnattendedOverride(stateDir: string): Promise<UnattendedOverride | undefined>;
|
|
118
|
+
/**
|
|
119
|
+
* `<state>/unattended`, made (mode 700) when missing and narrowed to 700 when others can read it. Throws
|
|
120
|
+
* `UnsafeFolderError` (its message says what to do) when it is a link, someone else's, or writable by others: nothing
|
|
121
|
+
* of Unattended Mode is written through such a folder.
|
|
122
|
+
*/
|
|
123
|
+
export declare function ensureUnattendedDir(stateDir: string): Promise<string>;
|
|
124
|
+
/** Writes the manual state (mode 600, atomically). */
|
|
125
|
+
export declare function writeUnattendedOverride(stateDir: string, override: UnattendedOverride): Promise<void>;
|
|
126
|
+
/** Removes the manual state. */
|
|
127
|
+
export declare function clearUnattendedOverride(stateDir: string): Promise<void>;
|
|
128
|
+
/** A time as the user reads it: `08:00` today, `tomorrow 08:00`, else `Mon 08:00` (or in Chinese). */
|
|
129
|
+
export declare function clockText(at: number, now: number, zh?: boolean): string;
|
|
@@ -0,0 +1,373 @@
|
|
|
1
|
+
// Unattended Mode (spec §3.37, ADR-0058): whether it is on now. One pure function decides it for the CLI, the Panel and
|
|
2
|
+
// `unattended-hook`, from the Schedule (config `unattended.schedule`), the manual state kept in
|
|
3
|
+
// `<state>/unattended/override.json` and the session flag. A leaf module (Node built-ins and core/fs-safe.ts only):
|
|
4
|
+
// `unattended-hook` runs it on every tool call.
|
|
5
|
+
import { readFile, rm } from 'node:fs/promises';
|
|
6
|
+
import { join } from 'node:path';
|
|
7
|
+
import { ownedFolder, readSmallFile, writeFileAtomic } from './fs-safe.js';
|
|
8
|
+
export const DAYS = ['mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun'];
|
|
9
|
+
/** Set in the environment of a session started with `--unattended`: on for that session, whatever the Schedule says. */
|
|
10
|
+
export const UNATTENDED_ENV = 'SIDEBY_UNATTENDED';
|
|
11
|
+
/** The longest the user can turn it on by hand. */
|
|
12
|
+
export const MAX_MANUAL_MS = 72 * 60 * 60 * 1000;
|
|
13
|
+
const DAY_MS = 24 * 60 * 60 * 1000;
|
|
14
|
+
/**
|
|
15
|
+
* How far around a moment the Schedule is laid out. A weekly Schedule with any gap has one in every 7 days (8 with a
|
|
16
|
+
* clock change), so a stretch that fills this whole window never ends: the Schedule covers every hour.
|
|
17
|
+
*/
|
|
18
|
+
const BACK_MS = 8 * DAY_MS;
|
|
19
|
+
const AHEAD_MS = 9 * DAY_MS;
|
|
20
|
+
const TIME = /^([01]\d|2[0-3]):([0-5]\d)$/;
|
|
21
|
+
const NAME_MAX = 60;
|
|
22
|
+
export const unattendedDir = (stateDir) => join(stateDir, 'unattended');
|
|
23
|
+
const overrideFile = (stateDir) => join(unattendedDir(stateDir), 'override.json');
|
|
24
|
+
/** `8:05` or `08:05` as `08:05`; undefined for anything else. */
|
|
25
|
+
export function parseClock(text) {
|
|
26
|
+
const m = /^(\d{1,2}):(\d{2})$/.exec(text.trim());
|
|
27
|
+
if (!m)
|
|
28
|
+
return undefined;
|
|
29
|
+
const value = `${m[1].padStart(2, '0')}:${m[2]}`;
|
|
30
|
+
return TIME.test(value) ? value : undefined;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Days as the CLI takes them: `mon-fri`, `sat,sun`, `fri-mon` (a range may wrap past Sunday), `weekdays`, `weekends`,
|
|
34
|
+
* `daily`. In week order; undefined when a part is not a day.
|
|
35
|
+
*/
|
|
36
|
+
export function parseDays(text) {
|
|
37
|
+
const words = {
|
|
38
|
+
weekdays: DAYS.slice(0, 5),
|
|
39
|
+
weekends: DAYS.slice(5),
|
|
40
|
+
weekend: DAYS.slice(5),
|
|
41
|
+
daily: DAYS,
|
|
42
|
+
everyday: DAYS,
|
|
43
|
+
all: DAYS,
|
|
44
|
+
};
|
|
45
|
+
const out = new Set();
|
|
46
|
+
const parts = text
|
|
47
|
+
.toLowerCase()
|
|
48
|
+
.split(',')
|
|
49
|
+
.map((p) => p.trim());
|
|
50
|
+
if (parts.some((p) => !p))
|
|
51
|
+
return undefined;
|
|
52
|
+
for (const part of parts) {
|
|
53
|
+
if (words[part]) {
|
|
54
|
+
for (const d of words[part])
|
|
55
|
+
out.add(d);
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
const range = part.split('-').map((p) => p.trim());
|
|
59
|
+
if (range.length > 2)
|
|
60
|
+
return undefined;
|
|
61
|
+
const from = dayOf(range[0]);
|
|
62
|
+
const to = range.length === 2 ? dayOf(range[1]) : from;
|
|
63
|
+
if (!from || !to)
|
|
64
|
+
return undefined;
|
|
65
|
+
for (let i = DAYS.indexOf(from);; i = (i + 1) % 7) {
|
|
66
|
+
out.add(DAYS[i]);
|
|
67
|
+
if (DAYS[i] === to)
|
|
68
|
+
break;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return DAYS.filter((d) => out.has(d));
|
|
72
|
+
}
|
|
73
|
+
const LONG_DAYS = ['monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday'];
|
|
74
|
+
/** `mon`, `mond` and `monday` are Monday; `mo` and `monx` are not a day. */
|
|
75
|
+
function dayOf(s) {
|
|
76
|
+
const i = s.length >= 3 ? LONG_DAYS.findIndex((d) => d.startsWith(s)) : -1;
|
|
77
|
+
return i < 0 ? undefined : DAYS[i];
|
|
78
|
+
}
|
|
79
|
+
/** `mon-fri`, `sat,sun`, `fri-mon`: the shortest way to write the days, in week order (a run may wrap past Sunday). */
|
|
80
|
+
export function daysText(days) {
|
|
81
|
+
const on = DAYS.map((d) => days.includes(d));
|
|
82
|
+
if (on.every(Boolean))
|
|
83
|
+
return 'daily';
|
|
84
|
+
// Start right after a day that is off, so a run past Sunday (fri-mon) stays one run.
|
|
85
|
+
const first = on.indexOf(false);
|
|
86
|
+
const runs = [];
|
|
87
|
+
for (let k = 1; k <= 7; k++) {
|
|
88
|
+
const i = (first + k) % 7;
|
|
89
|
+
if (!on[i])
|
|
90
|
+
continue;
|
|
91
|
+
const prev = (i + 6) % 7;
|
|
92
|
+
if (k > 1 && on[prev] && runs.length)
|
|
93
|
+
runs.at(-1).push(DAYS[i]);
|
|
94
|
+
else
|
|
95
|
+
runs.push([DAYS[i]]);
|
|
96
|
+
}
|
|
97
|
+
runs.sort((a, b) => DAYS.indexOf(a[0]) - DAYS.indexOf(b[0]));
|
|
98
|
+
return runs
|
|
99
|
+
.map((r) => (r.length === 1 ? r[0] : r.length === 2 ? `${r[0]},${r[1]}` : `${r[0]}-${r.at(-1)}`))
|
|
100
|
+
.join(',');
|
|
101
|
+
}
|
|
102
|
+
/** What a Slot is called on screen: its name, or its days and times. */
|
|
103
|
+
export function slotLabel(slot) {
|
|
104
|
+
return slot.name || `${daysText(slot.days)} ${slot.start}-${slot.end}`;
|
|
105
|
+
}
|
|
106
|
+
/** A Slot checked by hand, the way `unattended-hook` reads the config: anything malformed is left out. */
|
|
107
|
+
export function parseSlot(value) {
|
|
108
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
109
|
+
return undefined;
|
|
110
|
+
const v = value;
|
|
111
|
+
if (typeof v.start !== 'string' || typeof v.end !== 'string' || !TIME.test(v.start) || !TIME.test(v.end))
|
|
112
|
+
return undefined;
|
|
113
|
+
if (!Array.isArray(v.days))
|
|
114
|
+
return undefined;
|
|
115
|
+
const days = DAYS.filter((d) => v.days.includes(d));
|
|
116
|
+
// Every entry a day, none twice.
|
|
117
|
+
if (!days.length || days.length !== v.days.length)
|
|
118
|
+
return undefined;
|
|
119
|
+
const name = typeof v.name === 'string' && v.name.trim() ? v.name.trim().slice(0, NAME_MAX) : undefined;
|
|
120
|
+
return { ...(name ? { name } : {}), days, start: v.start, end: v.end };
|
|
121
|
+
}
|
|
122
|
+
/** The Schedule from config's `unattended.schedule`; a malformed Slot is left out, a malformed list is empty. */
|
|
123
|
+
export function parseSchedule(value) {
|
|
124
|
+
if (!Array.isArray(value))
|
|
125
|
+
return [];
|
|
126
|
+
return value.map(parseSlot).filter((s) => s !== undefined);
|
|
127
|
+
}
|
|
128
|
+
/** The manual state from its file's content; undefined when it is not one. */
|
|
129
|
+
export function parseOverride(value) {
|
|
130
|
+
if (!value || typeof value !== 'object')
|
|
131
|
+
return undefined;
|
|
132
|
+
const v = value;
|
|
133
|
+
if (v.mode !== 'on' && v.mode !== 'pause')
|
|
134
|
+
return undefined;
|
|
135
|
+
if (typeof v.at !== 'string')
|
|
136
|
+
return undefined;
|
|
137
|
+
const at = Date.parse(v.at);
|
|
138
|
+
if (!Number.isFinite(at))
|
|
139
|
+
return undefined;
|
|
140
|
+
if (v.until === undefined && v.mode === 'pause')
|
|
141
|
+
return { mode: 'pause', at: new Date(at).toISOString() };
|
|
142
|
+
if (typeof v.until !== 'string')
|
|
143
|
+
return undefined;
|
|
144
|
+
const until = Date.parse(v.until);
|
|
145
|
+
if (!Number.isFinite(until) || until <= at)
|
|
146
|
+
return undefined;
|
|
147
|
+
return { mode: v.mode, until: new Date(until).toISOString(), at: new Date(at).toISOString() };
|
|
148
|
+
}
|
|
149
|
+
const clockMinutes = (hhmm) => Number(hhmm.slice(0, 2)) * 60 + Number(hhmm.slice(3));
|
|
150
|
+
/**
|
|
151
|
+
* Every time a Slot is on that overlaps `[from, to)`, in local time: a Slot whose end is before its start runs past
|
|
152
|
+
* midnight and belongs to its start day; one whose end equals its start lasts the whole day (24 hours).
|
|
153
|
+
*/
|
|
154
|
+
export function slotOccurrences(schedule, from, to) {
|
|
155
|
+
const out = [];
|
|
156
|
+
if (!schedule.length || to <= from)
|
|
157
|
+
return out;
|
|
158
|
+
const base = new Date(from);
|
|
159
|
+
const [y, m, d] = [base.getFullYear(), base.getMonth(), base.getDate() - 1];
|
|
160
|
+
for (let i = 0;; i++) {
|
|
161
|
+
const day = new Date(y, m, d + i);
|
|
162
|
+
if (day.getTime() >= to)
|
|
163
|
+
break;
|
|
164
|
+
const name = DAYS[(day.getDay() + 6) % 7];
|
|
165
|
+
for (const [n, slot] of schedule.entries()) {
|
|
166
|
+
if (!slot.days.includes(name))
|
|
167
|
+
continue;
|
|
168
|
+
const s = clockMinutes(slot.start);
|
|
169
|
+
const e = clockMinutes(slot.end);
|
|
170
|
+
const start = new Date(y, m, d + i, Math.floor(s / 60), s % 60).getTime();
|
|
171
|
+
const end = new Date(y, m, d + i + (e <= s ? 1 : 0), Math.floor(e / 60), e % 60).getTime();
|
|
172
|
+
if (end > from && start < to)
|
|
173
|
+
out.push({ start, end, reason: 'slot', slot: slotLabel(slot), slotNumber: n + 1 });
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
return out;
|
|
177
|
+
}
|
|
178
|
+
/** Joins stretches that overlap or touch; each keeps how its first part began. */
|
|
179
|
+
export function mergeStretches(list) {
|
|
180
|
+
const out = [];
|
|
181
|
+
for (const s of [...list].sort((a, b) => a.start - b.start || b.end - a.end)) {
|
|
182
|
+
const last = out.at(-1);
|
|
183
|
+
if (last && s.start <= last.end)
|
|
184
|
+
last.end = Math.max(last.end, s.end);
|
|
185
|
+
else
|
|
186
|
+
out.push({ ...s });
|
|
187
|
+
}
|
|
188
|
+
return out;
|
|
189
|
+
}
|
|
190
|
+
function withoutPause(list, pause) {
|
|
191
|
+
if (!pause)
|
|
192
|
+
return [...list];
|
|
193
|
+
return list.flatMap((s) => {
|
|
194
|
+
if (s.end <= pause.start || s.start >= pause.end)
|
|
195
|
+
return [s];
|
|
196
|
+
const parts = [];
|
|
197
|
+
if (s.start < pause.start)
|
|
198
|
+
parts.push({ ...s, end: pause.start });
|
|
199
|
+
if (s.end > pause.end)
|
|
200
|
+
parts.push({ ...s, start: pause.end });
|
|
201
|
+
return parts;
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
/** The manual "on" as a stretch, at most 72 hours long whatever the file says. */
|
|
205
|
+
function manualStretch(o) {
|
|
206
|
+
if (o?.mode !== 'on' || !o.until)
|
|
207
|
+
return undefined;
|
|
208
|
+
const start = Date.parse(o.at);
|
|
209
|
+
return { start, end: Math.min(Date.parse(o.until), start + MAX_MANUAL_MS), reason: 'manual' };
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* The Schedule's stretch running at `at` (joined Slots count as one), and whether it never ends: it fills the whole
|
|
213
|
+
* window laid out around `at`, so the Schedule covers every hour.
|
|
214
|
+
*/
|
|
215
|
+
export function scheduleStretchAt(schedule, at) {
|
|
216
|
+
const [from, to] = [at - BACK_MS, at + AHEAD_MS];
|
|
217
|
+
const stretch = mergeStretches(slotOccurrences(schedule, from, to)).find((s) => s.start <= at && at < s.end);
|
|
218
|
+
return stretch ? { stretch, endless: stretch.start <= from && stretch.end >= to } : undefined;
|
|
219
|
+
}
|
|
220
|
+
/** The pause as a span; an open pause (no `until`) ends with the Schedule's stretch it was made in, which may be never. */
|
|
221
|
+
function pauseSpan(o, schedule) {
|
|
222
|
+
if (o?.mode !== 'pause')
|
|
223
|
+
return undefined;
|
|
224
|
+
const start = Date.parse(o.at);
|
|
225
|
+
if (o.until)
|
|
226
|
+
return { start, end: Date.parse(o.until) };
|
|
227
|
+
const s = scheduleStretchAt(schedule, start);
|
|
228
|
+
return { start, end: !s ? start : s.endless ? Number.POSITIVE_INFINITY : s.stretch.end };
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* When it was or will be on for the whole computer within `[from, to)`: the Slots and the manual "on" joined (the
|
|
232
|
+
* later end wins), the pause taken out. A stretch that runs past the window is cut at its edge.
|
|
233
|
+
*/
|
|
234
|
+
export function unattendedTimeline(schedule, override, from, to) {
|
|
235
|
+
const manual = manualStretch(override);
|
|
236
|
+
const pieces = [...slotOccurrences(schedule, from, to), ...(manual ? [manual] : [])];
|
|
237
|
+
return withoutPause(mergeStretches(pieces), pauseSpan(override, schedule)).filter((s) => s.end > from && s.start < to);
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* When `on --slot-end` ends: the end of the Slot it is in now, else of the next one (joined Slots count as one).
|
|
241
|
+
* Undefined when there is no Slot, or when the Schedule covers every hour and so never ends.
|
|
242
|
+
*/
|
|
243
|
+
export function slotEnd(schedule, now) {
|
|
244
|
+
const t = now.getTime();
|
|
245
|
+
const [from, to] = [t - BACK_MS, t + AHEAD_MS];
|
|
246
|
+
const s = mergeStretches(slotOccurrences(schedule, from, to)).find((x) => x.end > t);
|
|
247
|
+
return !s || (s.start <= from && s.end >= to) ? undefined : s.end;
|
|
248
|
+
}
|
|
249
|
+
/** Whether it is on now, why, until when, and when a Slot turns it on next. */
|
|
250
|
+
export function unattendedState(input) {
|
|
251
|
+
const t = input.now.getTime();
|
|
252
|
+
const [from, to] = [t - BACK_MS, t + AHEAD_MS];
|
|
253
|
+
const override = input.override;
|
|
254
|
+
const pieces = slotOccurrences(input.schedule, from, to);
|
|
255
|
+
const pause = pauseSpan(override, input.schedule);
|
|
256
|
+
const current = unattendedTimeline(input.schedule, override, from, to).find((s) => s.start <= t && t < s.end);
|
|
257
|
+
const inSlot = pieces.find((s) => s.start <= t && t < s.end);
|
|
258
|
+
const slotNow = inSlot?.slot;
|
|
259
|
+
const slotHere = inSlot ? { slot: inSlot.slot, slotNumber: inSlot.slotNumber } : {};
|
|
260
|
+
const after = current ? current.end : t;
|
|
261
|
+
const upcoming = withoutPause(mergeStretches(pieces), pause).find((s) => s.start > t && s.start >= after);
|
|
262
|
+
const next = upcoming
|
|
263
|
+
? {
|
|
264
|
+
next: {
|
|
265
|
+
at: iso(upcoming.start),
|
|
266
|
+
slot: upcoming.slot ?? '',
|
|
267
|
+
...(upcoming.slotNumber ? { slotNumber: upcoming.slotNumber } : {}),
|
|
268
|
+
},
|
|
269
|
+
}
|
|
270
|
+
: {};
|
|
271
|
+
if (current) {
|
|
272
|
+
const manual = manualStretch(override);
|
|
273
|
+
const byHand = manual !== undefined && manual.start <= t && t < manual.end;
|
|
274
|
+
// A stretch that reaches the end of the window is the Schedule covering every hour: it has no end.
|
|
275
|
+
return {
|
|
276
|
+
on: true,
|
|
277
|
+
reason: byHand ? 'manual' : 'slot',
|
|
278
|
+
...(current.end < to ? { until: iso(current.end) } : {}),
|
|
279
|
+
...(slotNow ? slotHere : {}),
|
|
280
|
+
...next,
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
if (input.session)
|
|
284
|
+
return { on: true, reason: 'session', ...next };
|
|
285
|
+
if (pause && pause.start <= t && t < pause.end)
|
|
286
|
+
return {
|
|
287
|
+
on: false,
|
|
288
|
+
reason: 'paused',
|
|
289
|
+
...(Number.isFinite(pause.end) ? { until: iso(pause.end) } : {}),
|
|
290
|
+
...(slotNow ? slotHere : {}),
|
|
291
|
+
...next,
|
|
292
|
+
};
|
|
293
|
+
return { on: false, reason: 'off', ...next };
|
|
294
|
+
}
|
|
295
|
+
function iso(ms) {
|
|
296
|
+
return new Date(ms).toISOString();
|
|
297
|
+
}
|
|
298
|
+
/** Reads a small JSON file that must be a plain file (opened without following a link); undefined otherwise. */
|
|
299
|
+
export async function readSmallJson(file, max = 1024 * 1024) {
|
|
300
|
+
const text = await readSmallFile(file, max);
|
|
301
|
+
if (text === undefined)
|
|
302
|
+
return undefined;
|
|
303
|
+
try {
|
|
304
|
+
return JSON.parse(text);
|
|
305
|
+
}
|
|
306
|
+
catch {
|
|
307
|
+
return undefined;
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
/** What the config file says about Unattended Mode, read by hand (no schema): whether it has the section, and its Schedule. */
|
|
311
|
+
export async function readUnattendedConfig(configFile) {
|
|
312
|
+
// The config may be a link a dotfiles manager keeps; reading through it is fine.
|
|
313
|
+
try {
|
|
314
|
+
const text = await readFile(configFile, 'utf8');
|
|
315
|
+
if (text.length > 4 * 1024 * 1024)
|
|
316
|
+
return { configured: false, schedule: [] };
|
|
317
|
+
const config = JSON.parse(text);
|
|
318
|
+
const section = config && typeof config === 'object' ? config.unattended : undefined;
|
|
319
|
+
if (!section || typeof section !== 'object')
|
|
320
|
+
return { configured: false, schedule: [] };
|
|
321
|
+
return { configured: true, schedule: parseSchedule(section.schedule) };
|
|
322
|
+
}
|
|
323
|
+
catch {
|
|
324
|
+
return { configured: false, schedule: [] };
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
/**
|
|
328
|
+
* The manual state as the file holds it, expired or not; undefined when there is none, it is not one, or
|
|
329
|
+
* `<state>/unattended` is not a real folder of the user that nobody else can write to.
|
|
330
|
+
*/
|
|
331
|
+
export async function readUnattendedOverride(stateDir) {
|
|
332
|
+
const dir = await ownedFolder(stateDir, ['unattended'], { create: false }).catch(() => null);
|
|
333
|
+
return dir ? parseOverride(await readSmallJson(overrideFile(stateDir), 4096)) : undefined;
|
|
334
|
+
}
|
|
335
|
+
/**
|
|
336
|
+
* `<state>/unattended`, made (mode 700) when missing and narrowed to 700 when others can read it. Throws
|
|
337
|
+
* `UnsafeFolderError` (its message says what to do) when it is a link, someone else's, or writable by others: nothing
|
|
338
|
+
* of Unattended Mode is written through such a folder.
|
|
339
|
+
*/
|
|
340
|
+
export async function ensureUnattendedDir(stateDir) {
|
|
341
|
+
return (await ownedFolder(stateDir, ['unattended'], { create: true, private: true }));
|
|
342
|
+
}
|
|
343
|
+
/** Writes the manual state (mode 600, atomically). */
|
|
344
|
+
export async function writeUnattendedOverride(stateDir, override) {
|
|
345
|
+
await ensureUnattendedDir(stateDir);
|
|
346
|
+
await writeFileAtomic(overrideFile(stateDir), `${JSON.stringify(override)}\n`, 0o600);
|
|
347
|
+
}
|
|
348
|
+
/** Removes the manual state. */
|
|
349
|
+
export async function clearUnattendedOverride(stateDir) {
|
|
350
|
+
if (!(await ownedFolder(stateDir, ['unattended'], { create: false })))
|
|
351
|
+
return;
|
|
352
|
+
await rm(overrideFile(stateDir), { force: true });
|
|
353
|
+
}
|
|
354
|
+
/** A time as the user reads it: `08:00` today, `tomorrow 08:00`, else `Mon 08:00` (or in Chinese). */
|
|
355
|
+
export function clockText(at, now, zh = false) {
|
|
356
|
+
const d = new Date(at);
|
|
357
|
+
const hhmm = `${String(d.getHours()).padStart(2, '0')}:${String(d.getMinutes()).padStart(2, '0')}`;
|
|
358
|
+
const day = (x) => new Date(x.getFullYear(), x.getMonth(), x.getDate()).getTime();
|
|
359
|
+
const diff = Math.round((day(d) - day(new Date(now))) / DAY_MS);
|
|
360
|
+
if (diff === 0)
|
|
361
|
+
return hhmm;
|
|
362
|
+
if (diff === 1)
|
|
363
|
+
return zh ? `明天 ${hhmm}` : `tomorrow ${hhmm}`;
|
|
364
|
+
const names = zh
|
|
365
|
+
? ['周日', '周一', '周二', '周三', '周四', '周五', '周六']
|
|
366
|
+
: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
|
|
367
|
+
const date = diff > 6 || diff < 0
|
|
368
|
+
? zh
|
|
369
|
+
? ` ${d.getMonth() + 1}月${d.getDate()}日`
|
|
370
|
+
: ` ${d.getMonth() + 1}/${d.getDate()}`
|
|
371
|
+
: '';
|
|
372
|
+
return `${names[d.getDay()]}${date} ${hhmm}`;
|
|
373
|
+
}
|