包文件→ .shtukbase/packages/schedule/lib/host.ts
lib/host.ts
28 行, 1.3 KB.
文件按包中的原样显示:代码及其注释不做翻译。
- // What the system scheduler needs to call the tick of one project: bun, the tick script, a PATH that finds the
- // harness CLIs, and a log file. Used by the actions cron and launchd; neither turns anything on.
- import { basename, dirname, join } from 'node:path';
- import { which } from '../../harness/lib/harness.ts';
- export function host(root: string, every: number) {
- const tick = join(root, '.shtukbase', 'packages', 'schedule', 'actions', 'tick.ts');
- const dirs = [dirname(process.execPath)];
- for (const b of ['claude', 'codex', 'opencode', 'dsh', 'hermes', 'node', 'git']) {
- const f = which(b);
- if (f) dirs.push(dirname(f));
- }
- dirs.push('/opt/homebrew/bin', '/usr/local/bin', '/usr/bin', '/bin', '/usr/sbin', '/sbin');
- const path = [...new Set(dirs)].join(':');
- const log = join(root, '.shtukbase', 'schedule', 'tick.log');
- const label = `com.shtukbase.tick.${basename(root).toLowerCase().replace(/[^a-z0-9.-]+/g, '-')}`;
- return { bun: process.execPath, tick, path, log, label, every };
- }
- /** `--every N` minutes (default 5), 1…59. */
- export function everyArg(v: unknown): number {
- const n = typeof v === 'string' && /^\d+$/.test(v) ? Number(v) : 5;
- if (n < 1 || n > 59) {
- console.error('--every: minutes from 1 to 59');
- process.exit(2);
- }
- return n;
- }