crewboss 0.0.0-stage → 0.3.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/src/config.js ADDED
@@ -0,0 +1,384 @@
1
+ /** Locate, load and validate crewboss.json. */
2
+ import fs from 'node:fs';
3
+ import path from 'node:path';
4
+
5
+ import { ConfigError } from './errors.js';
6
+ import { isDir, isFile } from './fsutil.js';
7
+ import { TOOLS } from './runners/index.js';
8
+
9
+ export const TIER_SIZES = ['small', 'medium', 'large'];
10
+ export const EFFORTS = ['low', 'medium', 'high', 'xhigh', 'max'];
11
+ export const NAME_RE = /^[a-z][a-z0-9_-]*$/;
12
+ export const CONFIG_ENV = 'CREWBOSS_CONFIG';
13
+ export const DEFAULT_CONFIG = 'crewboss.json';
14
+
15
+ const TOP_LEVEL_KEYS = new Set([
16
+ 'root', 'personas_dir', 'logs_dir', 'preamble', 'write_instructions', 'unit_prefix',
17
+ 'tiers', 'tracker', 'quota', 'routines', 'memory_max_bytes', 'ui', 'mods', 'tasks',
18
+ ]);
19
+ const MAX_MEMORY_BYTES = 1_000_000;
20
+ const CANDIDATE_KEYS = new Set(['tool', 'model', 'effort', 'paid']);
21
+ const MOD_KEYS = new Set(['name', 'description', 'personas', 'routines', 'ui']);
22
+ const MOD_CONFIG_KEYS = new Set(['source', 'commit', 'routines']);
23
+
24
+ const isObject = (v) => v !== null && typeof v === 'object' && !Array.isArray(v);
25
+ const show = (v) => (v === undefined ? 'undefined' : JSON.stringify(v));
26
+
27
+ function unknownKeys(obj, allowed) {
28
+ return Object.keys(obj).filter((k) => !allowed.has(k)).sort();
29
+ }
30
+
31
+ export function validModel(value) {
32
+ return typeof value === 'string' && value.trim() !== '' && !/[\r\n]/.test(value);
33
+ }
34
+
35
+ /** Resolve the config path: --config, then $CREWBOSS_CONFIG, then ./crewboss.json. */
36
+ export function findConfig({ cliPath = null, env = process.env, cwd = process.cwd() } = {}) {
37
+ const file = path.resolve(cwd, cliPath || env[CONFIG_ENV] || DEFAULT_CONFIG);
38
+ if (!isFile(file)) throw new ConfigError(`config file not found: ${file}`);
39
+ return file;
40
+ }
41
+
42
+ export function validateCandidate(candidate, where) {
43
+ if (!isObject(candidate)) throw new ConfigError(`${where}: each candidate must be an object`);
44
+ const unknown = unknownKeys(candidate, CANDIDATE_KEYS);
45
+ if (unknown.length) throw new ConfigError(`${where}: unknown keys in candidate: ${unknown.join(', ')}`);
46
+ if (!TOOLS.has(candidate.tool)) {
47
+ throw new ConfigError(`${where}: invalid tool ${show(candidate.tool)}, expected one of ${[...TOOLS].sort().join(', ')}`);
48
+ }
49
+ if (!validModel(candidate.model)) throw new ConfigError(`${where}: invalid model ${show(candidate.model)}`);
50
+ if ('paid' in candidate && typeof candidate.paid !== 'boolean') {
51
+ throw new ConfigError(`${where}: paid must be a boolean`);
52
+ }
53
+ if ('effort' in candidate && !EFFORTS.includes(candidate.effort)) {
54
+ throw new ConfigError(`${where}: invalid effort ${show(candidate.effort)}`);
55
+ }
56
+ return { ...candidate, paid: candidate.paid ?? false };
57
+ }
58
+
59
+ /** Validate tiers: exactly small, medium and large, each a list of candidates. */
60
+ export function loadTiers(data) {
61
+ if (!isObject(data)) throw new ConfigError('tiers must be an object');
62
+ const keys = Object.keys(data).sort();
63
+ if (keys.join() !== [...TIER_SIZES].sort().join()) {
64
+ throw new ConfigError(`tiers must have exactly: ${TIER_SIZES.join(', ')}`);
65
+ }
66
+ const tiers = {};
67
+ for (const size of TIER_SIZES) {
68
+ if (!Array.isArray(data[size])) throw new ConfigError(`tier '${size}' must be a list of candidates`);
69
+ tiers[size] = data[size].map((c) => validateCandidate(c, `tier '${size}'`));
70
+ }
71
+ return tiers;
72
+ }
73
+
74
+ function optionalString(data, key, fallback) {
75
+ const value = data[key] ?? fallback;
76
+ if (typeof value !== 'string') throw new ConfigError(`${key} must be a string`);
77
+ return value;
78
+ }
79
+
80
+ function relativeDir(data, key, fallback, root) {
81
+ const value = optionalString(data, key, fallback);
82
+ if (!value.trim()) throw new ConfigError(`${key} must not be empty`);
83
+ return path.resolve(root, value);
84
+ }
85
+
86
+ function validateCommand(value, where) {
87
+ if (!Array.isArray(value) || !value.length || !value.every((p) => typeof p === 'string' && p !== '')) {
88
+ throw new ConfigError(`${where}: command must be a nonempty list of strings`);
89
+ }
90
+ return value;
91
+ }
92
+
93
+ function validateTimeout(value, fallback, where) {
94
+ const timeout = value ?? fallback;
95
+ if (!Number.isInteger(timeout) || timeout < 1) {
96
+ throw new ConfigError(`${where}: timeout_seconds must be a positive integer`);
97
+ }
98
+ return timeout;
99
+ }
100
+
101
+ export function loadTracker(data) {
102
+ if (!isObject(data)) throw new ConfigError('tracker must be an object');
103
+ if (data.type === 'local') {
104
+ const unknown = unknownKeys(data, new Set(['type']));
105
+ if (unknown.length) throw new ConfigError(`tracker local: unknown keys: ${unknown.join(', ')}`);
106
+ return { type: 'local' };
107
+ }
108
+ if (data.type === 'file') {
109
+ const unknown = unknownKeys(data, new Set(['type', 'dir']));
110
+ if (unknown.length) throw new ConfigError(`tracker file: unknown keys: ${unknown.join(', ')}`);
111
+ const dir = data.dir ?? 'reports';
112
+ if (typeof dir !== 'string' || !dir.trim()) throw new ConfigError('tracker file: dir must be a nonempty string');
113
+ return { type: 'file', dir };
114
+ }
115
+ if (data.type === 'command') {
116
+ const unknown = unknownKeys(data, new Set(['type', 'command', 'options', 'timeout_seconds']));
117
+ if (unknown.length) throw new ConfigError(`tracker command: unknown keys: ${unknown.join(', ')}`);
118
+ const options = data.options ?? {};
119
+ if (!isObject(options)) throw new ConfigError('tracker command: options must be an object');
120
+ return {
121
+ type: 'command',
122
+ command: validateCommand(data.command, 'tracker command'),
123
+ options,
124
+ timeout_seconds: validateTimeout(data.timeout_seconds, 60, 'tracker command'),
125
+ };
126
+ }
127
+ throw new ConfigError(`tracker type must be 'local', 'file' or 'command', got ${show(data.type)}`);
128
+ }
129
+
130
+ export function loadQuota(data) {
131
+ if (data == null) return null;
132
+ if (!isObject(data)) throw new ConfigError('quota must be null or {"command": [...]}');
133
+ const unknown = unknownKeys(data, new Set(['command', 'timeout_seconds']));
134
+ if (unknown.length) throw new ConfigError(`quota: unknown keys: ${unknown.join(', ')}`);
135
+ return {
136
+ command: validateCommand(data.command, 'quota'),
137
+ timeout_seconds: validateTimeout(data.timeout_seconds, 30, 'quota'),
138
+ };
139
+ }
140
+
141
+ const ROUTINE_KEYS = new Set([
142
+ 'name', 'enabled', 'schedule', 'mode', 'size', 'tool', 'model', 'effort', 'prompt', 'collect',
143
+ 'collect_timeout_minutes', 'timeout_minutes', 'project', 'assignee', 'allowed_tools', 'disallowed_tools', 'options',
144
+ ]);
145
+ export const ROUTINE_MODES = ['read', 'write'];
146
+ const MAX_MINUTES = 1440;
147
+
148
+ const nonEmptyString = (v) => typeof v === 'string' && v.trim() !== '';
149
+ const validMinutes = (v) => Number.isInteger(v) && v >= 1 && v <= MAX_MINUTES;
150
+
151
+ function validateRoutine(routine, seen, root) {
152
+ if (!isObject(routine)) throw new ConfigError('each routine must be an object');
153
+ const { name } = routine;
154
+ if (typeof name !== 'string' || !NAME_RE.test(name) || seen.has(name)) {
155
+ throw new ConfigError(`invalid or duplicate routine name: ${show(name)}`);
156
+ }
157
+ seen.add(name);
158
+ const where = `routine '${name}'`;
159
+ const unknown = unknownKeys(routine, ROUTINE_KEYS);
160
+ if (unknown.length) throw new ConfigError(`${where}: unknown keys: ${unknown.join(', ')}`);
161
+ if (typeof routine.enabled !== 'boolean') throw new ConfigError(`${where}: enabled must be a boolean`);
162
+ if (!validModel(routine.schedule)) throw new ConfigError(`${where}: invalid schedule`);
163
+ const mode = routine.mode ?? 'read';
164
+ if (!ROUTINE_MODES.includes(mode)) throw new ConfigError(`${where}: mode must be read or write`);
165
+
166
+ if ('size' in routine) {
167
+ if ('tool' in routine || 'model' in routine || 'effort' in routine) {
168
+ throw new ConfigError(`${where}: use either size or tool + model, not both`);
169
+ }
170
+ if (!TIER_SIZES.includes(routine.size)) throw new ConfigError(`${where}: invalid size ${show(routine.size)}`);
171
+ } else {
172
+ if (!TOOLS.has(routine.tool)) throw new ConfigError(`${where}: invalid tool ${show(routine.tool)}`);
173
+ if (!validModel(routine.model)) throw new ConfigError(`${where}: invalid model ${show(routine.model)}`);
174
+ if ('effort' in routine && !EFFORTS.includes(routine.effort)) {
175
+ throw new ConfigError(`${where}: invalid effort ${show(routine.effort)}`);
176
+ }
177
+ }
178
+
179
+ if (!nonEmptyString(routine.prompt)) throw new ConfigError(`${where}: missing prompt`);
180
+ const promptPath = path.resolve(root, routine.prompt);
181
+ const inside = path.relative(root, promptPath);
182
+ if (!inside || inside === '..' || inside.startsWith(`..${path.sep}`) || path.isAbsolute(inside) || !isFile(promptPath)) {
183
+ throw new ConfigError(`${where}: prompt must be an existing file inside ${root}`);
184
+ }
185
+ if ('collect' in routine && !nonEmptyString(routine.collect)) throw new ConfigError(`${where}: invalid collect command`);
186
+ if (!validMinutes(routine.timeout_minutes)) throw new ConfigError(`${where}: timeout_minutes must be 1..${MAX_MINUTES}`);
187
+ if ('collect_timeout_minutes' in routine) {
188
+ if (!validMinutes(routine.collect_timeout_minutes)) {
189
+ throw new ConfigError(`${where}: collect_timeout_minutes must be 1..${MAX_MINUTES}`);
190
+ }
191
+ if (routine.collect_timeout_minutes >= routine.timeout_minutes) {
192
+ throw new ConfigError(`${where}: collect_timeout_minutes must be less than timeout_minutes`);
193
+ }
194
+ }
195
+ if (!nonEmptyString(routine.project)) throw new ConfigError(`${where}: project must be a nonempty string`);
196
+ if (!nonEmptyString(routine.assignee)) throw new ConfigError(`${where}: assignee must be a nonempty string`);
197
+ const toolList = (key) => {
198
+ const list = routine[key] ?? [];
199
+ if (!Array.isArray(list) || !list.every(nonEmptyString)) throw new ConfigError(`${where}: ${key} must be a list of names`);
200
+ return list;
201
+ };
202
+ const allowedTools = toolList('allowed_tools');
203
+ const disallowedTools = toolList('disallowed_tools');
204
+ if ('options' in routine && !isObject(routine.options)) throw new ConfigError(`${where}: options must be an object`);
205
+ return { ...routine, mode, allowed_tools: allowedTools, disallowed_tools: disallowedTools };
206
+ }
207
+
208
+ /** Validate the routines list; prompts must be files inside the root. */
209
+ export function loadRoutines(data, root) {
210
+ if (!Array.isArray(data)) throw new ConfigError('routines must be a list');
211
+ const seen = new Set();
212
+ return data.map((routine) => validateRoutine(routine, seen, root));
213
+ }
214
+
215
+ function insideMod(modDir, value, where, { directory = false } = {}) {
216
+ if (!nonEmptyString(value) || path.isAbsolute(value)) throw new ConfigError(`${where} must be a nonempty relative path`);
217
+ const resolved = path.resolve(modDir, value);
218
+ const relative = path.relative(modDir, resolved);
219
+ if ((!relative && !directory) || relative === '..' || relative.startsWith(`..${path.sep}`) || path.isAbsolute(relative)) {
220
+ throw new ConfigError(`${where} must be inside ${modDir}`);
221
+ }
222
+ const valid = directory ? isDir(resolved) : isFile(resolved);
223
+ const realDir = fs.realpathSync(modDir);
224
+ const realPath = valid ? fs.realpathSync(resolved) : null;
225
+ if (!valid || !(directory && realPath === realDir || realPath.startsWith(`${realDir}${path.sep}`))) {
226
+ throw new ConfigError(`${where} must be ${directory ? 'an existing folder' : 'an existing file'} inside ${modDir}`);
227
+ }
228
+ return resolved;
229
+ }
230
+
231
+ /** Load installed mods and activate only the routines named in crewboss.json. */
232
+ export function loadMods(data, root, workspaceRoutines, { skipMods = false } = {}) {
233
+ if (!isObject(data)) throw new ConfigError('mods must be an object');
234
+ const mods = {};
235
+ const routines = [...workspaceRoutines];
236
+ const names = new Set(routines.map((routine) => routine.name));
237
+ for (const [name, settings] of Object.entries(data)) {
238
+ if (!NAME_RE.test(name)) throw new ConfigError(`invalid mod name: ${show(name)}`);
239
+ if (!isObject(settings)) throw new ConfigError(`mod ${name}: settings must be an object`);
240
+ const unknownSettings = unknownKeys(settings, MOD_CONFIG_KEYS);
241
+ if (unknownSettings.length) throw new ConfigError(`mod ${name}: unknown config keys: ${unknownSettings.join(', ')}`);
242
+ for (const key of ['source', 'commit']) {
243
+ if (key in settings && !nonEmptyString(settings[key])) throw new ConfigError(`mod ${name}: ${key} must be a nonempty string`);
244
+ }
245
+ const selected = 'routines' in settings ? settings.routines : [];
246
+ if (!Array.isArray(selected) || !selected.every((item) => typeof item === 'string' && NAME_RE.test(item)) || new Set(selected).size !== selected.length) {
247
+ throw new ConfigError(`mod ${name}: routines must be a list of unique routine names`);
248
+ }
249
+ if (skipMods) continue;
250
+ const dir = path.join(root, '.crewboss', 'mods', name);
251
+ const manifestPath = path.join(dir, 'crewboss-mod.json');
252
+ if (!isDir(dir) || !isFile(manifestPath)) {
253
+ throw new ConfigError(`mod ${name} is not installed at ${dir}; run \`crewboss mod install\``);
254
+ }
255
+ const { manifest, personasDir, uiDir, declared } = validateModManifest(dir, name);
256
+ for (const item of selected) {
257
+ const routine = declared.find((entry) => entry.name === item);
258
+ if (!routine) throw new ConfigError(`mod ${name}: unknown routine ${show(item)}`);
259
+ const qualified = `${name}-${item}`;
260
+ if (!NAME_RE.test(qualified) || names.has(qualified)) throw new ConfigError(`mod ${name}: routine name clash: ${qualified}`);
261
+ names.add(qualified);
262
+ routines.push({ ...routine, name: qualified, mod: name, modDir: dir, promptPath: path.resolve(dir, routine.prompt) });
263
+ }
264
+ mods[name] = { name, dir, description: manifest.description ?? '', personasDir, uiDir, routines: declared, source: settings.source ?? null, commit: settings.commit ?? null };
265
+ }
266
+ return { mods, routines };
267
+ }
268
+
269
+ /** Validate one installed checkout with the same rules used by loadConfig. */
270
+ export function validateModManifest(dir, name) {
271
+ const manifestPath = path.join(dir, 'crewboss-mod.json');
272
+ let manifest;
273
+ try { manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf8')); }
274
+ catch (err) { throw new ConfigError(`mod ${name}: invalid manifest JSON: ${err.message}`); }
275
+ if (!isObject(manifest)) throw new ConfigError(`mod ${name}: manifest must be an object`);
276
+ const unknown = unknownKeys(manifest, MOD_KEYS);
277
+ if (unknown.length) throw new ConfigError(`mod ${name}: unknown manifest keys: ${unknown.join(', ')}`);
278
+ if (typeof manifest.name !== 'string' || !NAME_RE.test(manifest.name)) throw new ConfigError(`mod ${name}: invalid manifest name: ${show(manifest.name)}`);
279
+ if (manifest.name !== name) throw new ConfigError(`mod ${name}: manifest name must match installed name`);
280
+ if ('description' in manifest && typeof manifest.description !== 'string') throw new ConfigError(`mod ${name}: description must be a string`);
281
+ const personasDir = 'personas' in manifest ? insideMod(dir, manifest.personas, `mod ${name}: personas`, { directory: true }) : null;
282
+ const uiDir = 'ui' in manifest ? insideMod(dir, manifest.ui, `mod ${name}: ui`, { directory: true }) : null;
283
+ if (uiDir) {
284
+ const index = path.join(uiDir, 'index.html');
285
+ if (!isFile(index) || !fs.realpathSync(index).startsWith(`${fs.realpathSync(uiDir)}${path.sep}`)) {
286
+ throw new ConfigError(`mod ${name}: ui has no index.html inside its folder: ${uiDir}`);
287
+ }
288
+ }
289
+ const declared = loadRoutines('routines' in manifest ? manifest.routines : [], dir);
290
+ for (const routine of declared) insideMod(dir, routine.prompt, `mod ${name}: routine '${routine.name}' prompt`);
291
+ return { manifest, personasDir, uiDir, declared };
292
+ }
293
+
294
+ /**
295
+ * The workspace root: the `root` key resolved against the config file's folder, or that folder
296
+ * when `root` is absent. Every other relative path in the config resolves against it.
297
+ */
298
+ export function resolveRoot(data, configPath) {
299
+ const configDir = path.dirname(configPath);
300
+ if (!('root' in data)) return configDir;
301
+ const value = data.root;
302
+ if (typeof value !== 'string' || !value.trim()) throw new ConfigError(`root must be a nonempty string, got ${show(value)}`);
303
+ const root = path.resolve(configDir, value);
304
+ if (!fs.existsSync(root)) throw new ConfigError(`root ${show(value)} does not exist: ${root}`);
305
+ if (!isDir(root)) throw new ConfigError(`root ${show(value)} is not a directory: ${root}`);
306
+ return root;
307
+ }
308
+
309
+ /** Resolve an optional static UI path without checking the filesystem. */
310
+ export function resolveUi(value, base, mods = {}) {
311
+ if (value === undefined) return null;
312
+ if (typeof value !== 'string' || !value.trim()) throw new ConfigError(`ui must be a nonempty directory path, got ${show(value)}`);
313
+ if (value.startsWith('mod:')) {
314
+ const name = value.slice(4);
315
+ if (!Object.hasOwn(mods, name)) throw new ConfigError(`ui mod ${show(name)} is not configured`);
316
+ if (!mods[name].uiDir) throw new ConfigError(`ui mod ${show(name)} has no ui folder`);
317
+ return mods[name].uiDir;
318
+ }
319
+ return path.resolve(base, value);
320
+ }
321
+
322
+ /** Check a UI directory when serve starts or reloads its configuration. */
323
+ export function validateUi(value, base, mods = {}) {
324
+ const resolved = resolveUi(value, base, mods);
325
+ if (resolved === null) return null;
326
+ if (!fs.existsSync(resolved)) throw new ConfigError(`ui ${show(value)} does not exist: ${resolved}`);
327
+ if (!isDir(resolved)) throw new ConfigError(`ui ${show(value)} is not a directory: ${resolved}`);
328
+ if (!isFile(path.join(resolved, 'index.html'))) throw new ConfigError(`ui ${show(value)} has no index.html: ${resolved}`);
329
+ return resolved;
330
+ }
331
+
332
+ /** Load and validate a config file; relative paths resolve against the root (see resolveRoot). */
333
+ export function loadConfig(file, { ui = undefined, uiBase = process.cwd(), skipMods = false } = {}) {
334
+ const configPath = path.resolve(file);
335
+ let data;
336
+ try {
337
+ data = JSON.parse(fs.readFileSync(configPath, 'utf8'));
338
+ } catch (err) {
339
+ if (err.code === 'ENOENT') throw new ConfigError(`config file not found: ${configPath}`);
340
+ if (err instanceof SyntaxError) throw new ConfigError(`config ${configPath} is not valid JSON: ${err.message}`);
341
+ throw err;
342
+ }
343
+ if (!isObject(data)) throw new ConfigError('config must be a JSON object');
344
+ const unknown = unknownKeys(data, TOP_LEVEL_KEYS);
345
+ if (unknown.length) throw new ConfigError(`unknown config keys: ${unknown.join(', ')}`);
346
+ if (!('tiers' in data)) throw new ConfigError('config needs tiers');
347
+
348
+ const root = resolveRoot(data, configPath);
349
+ const unitPrefix = optionalString(data, 'unit_prefix', 'crewboss-');
350
+ if (!/^[A-Za-z0-9_.-]+$/.test(unitPrefix)) throw new ConfigError(`unit_prefix has invalid characters: ${show(unitPrefix)}`);
351
+ const { mods, routines } = loadMods(data.mods ?? {}, root, loadRoutines(data.routines ?? [], root), { skipMods });
352
+ const memoryMaxBytes = data.memory_max_bytes ?? 8192;
353
+ if (!Number.isInteger(memoryMaxBytes) || memoryMaxBytes < 0 || memoryMaxBytes > MAX_MEMORY_BYTES) {
354
+ throw new ConfigError(`memory_max_bytes must be an integer between 0 and ${MAX_MEMORY_BYTES}`);
355
+ }
356
+ if (data.tasks !== undefined && (!isObject(data.tasks) || unknownKeys(data.tasks, new Set(['stale_after_days'])).length
357
+ || !Number.isInteger(data.tasks.stale_after_days)
358
+ || data.tasks.stale_after_days < 1 || data.tasks.stale_after_days > 365)) {
359
+ throw new ConfigError('tasks must be an object with stale_after_days integer from 1 to 365');
360
+ }
361
+ if (data.tasks?.stale_after_days !== undefined && routines.some((routine) => routine.name === 'tidy')) {
362
+ throw new ConfigError('routine name tidy is reserved when tasks.stale_after_days is configured');
363
+ }
364
+
365
+ return {
366
+ path: configPath,
367
+ root,
368
+ uiValue: ui === undefined ? data.ui : ui,
369
+ uiPath: skipMods && String(ui === undefined ? data.ui : ui).startsWith('mod:') ? null
370
+ : resolveUi(ui === undefined ? data.ui : ui, ui === undefined ? root : uiBase, mods),
371
+ personasDir: relativeDir(data, 'personas_dir', 'agents', root),
372
+ logsDir: relativeDir(data, 'logs_dir', 'logs/crewboss', root),
373
+ preamble: optionalString(data, 'preamble', ''),
374
+ writeInstructions: optionalString(data, 'write_instructions', ''),
375
+ unitPrefix,
376
+ tiers: loadTiers(data.tiers),
377
+ tracker: loadTracker(data.tracker ?? { type: 'local' }),
378
+ tasks: data.tasks ?? {},
379
+ quota: loadQuota(data.quota),
380
+ routines,
381
+ mods,
382
+ memoryMaxBytes,
383
+ };
384
+ }
package/src/due.js ADDED
@@ -0,0 +1,10 @@
1
+ /** A calendar date in the task protocol's YYYY-MM-DD format. */
2
+ export function isDueDate(value) {
3
+ if (typeof value !== 'string' || !/^\d{4}-\d{2}-\d{2}$/.test(value)) return false;
4
+ const [year, month, day] = value.split('-').map(Number);
5
+ if (year < 1 || month < 1 || month > 12) return false;
6
+ const days = new Date(Date.UTC(year, month, 0)).getUTCDate();
7
+ return day >= 1 && day <= days;
8
+ }
9
+
10
+ export const isDue = (value) => value === null || isDueDate(value);
package/src/errors.js ADDED
@@ -0,0 +1,47 @@
1
+ /** Invalid or missing configuration. */
2
+ export class ConfigError extends Error {
3
+ constructor(message) {
4
+ super(message);
5
+ this.name = 'ConfigError';
6
+ }
7
+ }
8
+
9
+ /** A task tracker failed to read or write tasks or reports. */
10
+ export class TrackerError extends Error {
11
+ constructor(message) {
12
+ super(message);
13
+ this.name = 'TrackerError';
14
+ }
15
+ }
16
+
17
+ /** The tracker does not implement an operation (a plugin answered {"error": "unsupported"}). */
18
+ export class UnsupportedError extends TrackerError {
19
+ constructor(message) {
20
+ super(message);
21
+ this.name = 'UnsupportedError';
22
+ }
23
+ }
24
+
25
+ /** The local store (SQLite) could not be opened, migrated or written. */
26
+ export class StoreError extends Error {
27
+ constructor(message) {
28
+ super(message);
29
+ this.name = 'StoreError';
30
+ }
31
+ }
32
+
33
+ /** An executable plugin failed: non-zero exit, timeout or invalid JSON. */
34
+ export class PluginError extends Error {
35
+ constructor(message) {
36
+ super(message);
37
+ this.name = 'PluginError';
38
+ }
39
+ }
40
+
41
+ /** A child process exceeded its time limit and its process group was killed. */
42
+ export class TimeoutError extends Error {
43
+ constructor(message) {
44
+ super(message);
45
+ this.name = 'TimeoutError';
46
+ }
47
+ }