ShtukbaseStandard
包文件→ .shtukbase/packages/schedule/lib/host.ts

lib/host.ts

28 行, 1.3 KB.

文件按包中的原样显示:代码及其注释不做翻译。

  1. // What the system scheduler needs to call the tick of one project: bun, the tick script, a PATH that finds the
  2. // harness CLIs, and a log file. Used by the actions cron and launchd; neither turns anything on.
  3. import { basename, dirname, join } from 'node:path';
  4. import { which } from '../../harness/lib/harness.ts';
  5. export function host(root: string, every: number) {
  6. const tick = join(root, '.shtukbase', 'packages', 'schedule', 'actions', 'tick.ts');
  7. const dirs = [dirname(process.execPath)];
  8. for (const b of ['claude', 'codex', 'opencode', 'dsh', 'hermes', 'node', 'git']) {
  9. const f = which(b);
  10. if (f) dirs.push(dirname(f));
  11. }
  12. dirs.push('/opt/homebrew/bin', '/usr/local/bin', '/usr/bin', '/bin', '/usr/sbin', '/sbin');
  13. const path = [...new Set(dirs)].join(':');
  14. const log = join(root, '.shtukbase', 'schedule', 'tick.log');
  15. const label = `com.shtukbase.tick.${basename(root).toLowerCase().replace(/[^a-z0-9.-]+/g, '-')}`;
  16. return { bun: process.execPath, tick, path, log, label, every };
  17. }
  18. /** `--every N` minutes (default 5), 1…59. */
  19. export function everyArg(v: unknown): number {
  20. const n = typeof v === 'string' && /^\d+$/.test(v) ? Number(v) : 5;
  21. if (n < 1 || n > 59) {
  22. console.error('--every: minutes from 1 to 59');
  23. process.exit(2);
  24. }
  25. return n;
  26. }