@phnx-labs/agents-cli 1.23.28 → 1.23.29

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 (164) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/README.md +33 -82
  3. package/dist/bootstrap.js +0 -17
  4. package/dist/cli/command-registry.js +0 -2
  5. package/dist/commands/cloud.js +0 -58
  6. package/dist/commands/config.js +0 -4
  7. package/dist/commands/daemon-index.js +1 -1
  8. package/dist/commands/daemon.js +14 -63
  9. package/dist/commands/doctor.js +0 -12
  10. package/dist/commands/events.js +1 -1
  11. package/dist/commands/feed.d.ts +1 -3
  12. package/dist/commands/feed.js +1 -6
  13. package/dist/commands/fleet-capture.js +2 -4
  14. package/dist/commands/focus.d.ts +0 -1
  15. package/dist/commands/focus.js +2 -4
  16. package/dist/commands/inspect.d.ts +1 -19
  17. package/dist/commands/inspect.js +8 -474
  18. package/dist/commands/mine.js +1 -1
  19. package/dist/commands/prune.js +2 -64
  20. package/dist/commands/ps-roster.d.ts +0 -4
  21. package/dist/commands/ps-roster.js +2 -30
  22. package/dist/commands/ps.js +1 -4
  23. package/dist/commands/repo.d.ts +1 -1
  24. package/dist/commands/repo.js +4 -4
  25. package/dist/commands/sessions-browser.d.ts +0 -2
  26. package/dist/commands/sessions-browser.js +2 -32
  27. package/dist/commands/sessions-optimize.js +3 -4
  28. package/dist/commands/setup-mine.js +0 -1
  29. package/dist/commands/ssh.js +8 -9
  30. package/dist/commands/sync.js +1 -1
  31. package/dist/commands/update.js +2 -2
  32. package/dist/commands/watchdog.js +3 -4
  33. package/dist/lib/accounting/rotate.d.ts +0 -2
  34. package/dist/lib/accounting/rotate.js +1 -4
  35. package/dist/lib/agent-spec/agents.d.ts +0 -1
  36. package/dist/lib/agent-spec/agents.js +0 -8
  37. package/dist/lib/auth-health.d.ts +0 -1
  38. package/dist/lib/auth-health.js +0 -3
  39. package/dist/lib/cli-entry.d.ts +0 -1
  40. package/dist/lib/cli-entry.js +0 -36
  41. package/dist/lib/cloud/types.d.ts +0 -2
  42. package/dist/lib/config-keys.d.ts +1 -1
  43. package/dist/lib/config-keys.js +1 -4
  44. package/dist/lib/daemon/daemon.d.ts +0 -4
  45. package/dist/lib/daemon/daemon.js +6 -202
  46. package/dist/lib/daemon/heartbeat-service.d.ts +1 -1
  47. package/dist/lib/daemon/heartbeat-service.js +1 -8
  48. package/dist/lib/daemon-services.d.ts +1 -1
  49. package/dist/lib/daemon-services.js +1 -11
  50. package/dist/lib/device-config.d.ts +0 -2
  51. package/dist/lib/device-config.js +4 -22
  52. package/dist/lib/devices/config-migration.js +1 -3
  53. package/dist/lib/exec.d.ts +2 -5
  54. package/dist/lib/exec.js +18 -18
  55. package/dist/lib/factory/snapshot.d.ts +0 -5
  56. package/dist/lib/factory/snapshot.js +1 -28
  57. package/dist/lib/feed/events.d.ts +1 -11
  58. package/dist/lib/feed/events.js +0 -20
  59. package/dist/lib/feed/feed.d.ts +0 -2
  60. package/dist/lib/feed-outcome.d.ts +0 -2
  61. package/dist/lib/feed-outcome.js +0 -5
  62. package/dist/lib/fleet/capture.d.ts +0 -1
  63. package/dist/lib/fleet/capture.js +0 -3
  64. package/dist/lib/fleet/manifest.js +0 -6
  65. package/dist/lib/fleet/types.d.ts +0 -1
  66. package/dist/lib/harness/adapter.d.ts +0 -7
  67. package/dist/lib/harness/adapters/claude.js +0 -18
  68. package/dist/lib/harness/adapters/codex.js +0 -10
  69. package/dist/lib/harness/adapters/cursor.js +0 -11
  70. package/dist/lib/harness/adapters/kimi.js +0 -3
  71. package/dist/lib/harness/adapters/muse.js +0 -11
  72. package/dist/lib/harness/index.d.ts +1 -1
  73. package/dist/lib/harness/index.js +0 -2
  74. package/dist/lib/hosts/passthrough.js +2 -10
  75. package/dist/lib/hosts/ready.d.ts +0 -4
  76. package/dist/lib/hosts/ready.js +0 -9
  77. package/dist/lib/hosts/reconcile.d.ts +0 -1
  78. package/dist/lib/hosts/reconcile.js +0 -8
  79. package/dist/lib/installations/migrate.d.ts +0 -2
  80. package/dist/lib/installations/migrate.js +0 -145
  81. package/dist/lib/loop.js +1 -2
  82. package/dist/lib/menubar/snapshot.d.ts +0 -1
  83. package/dist/lib/menubar/snapshot.js +1 -4
  84. package/dist/lib/placement.d.ts +1 -2
  85. package/dist/lib/placement.js +4 -24
  86. package/dist/lib/profiles.d.ts +0 -1
  87. package/dist/lib/profiles.js +0 -6
  88. package/dist/lib/session/active.d.ts +1 -3
  89. package/dist/lib/session/active.js +0 -4
  90. package/dist/lib/session/db.d.ts +0 -1
  91. package/dist/lib/session/db.js +4 -8
  92. package/dist/lib/session/discover.d.ts +0 -1
  93. package/dist/lib/session/discover.js +3 -128
  94. package/dist/lib/session/live-metadata.js +0 -2
  95. package/dist/lib/session/presentation.d.ts +0 -1
  96. package/dist/lib/session/presentation.js +3 -8
  97. package/dist/lib/session/selection.d.ts +0 -2
  98. package/dist/lib/session/selection.js +2 -12
  99. package/dist/lib/staleness/detectors/commands.d.ts +1 -1
  100. package/dist/lib/staleness/detectors/hooks.d.ts +1 -1
  101. package/dist/lib/staleness/detectors/mcp.d.ts +1 -1
  102. package/dist/lib/staleness/detectors/permissions.d.ts +1 -1
  103. package/dist/lib/staleness/detectors/plugins.d.ts +1 -1
  104. package/dist/lib/staleness/detectors/rules.d.ts +1 -1
  105. package/dist/lib/staleness/detectors/skills.d.ts +1 -1
  106. package/dist/lib/staleness/detectors/subagents.d.ts +1 -1
  107. package/dist/lib/staleness/detectors/workflows.d.ts +1 -1
  108. package/dist/lib/staleness/writers/commands.d.ts +1 -1
  109. package/dist/lib/staleness/writers/hooks.d.ts +1 -1
  110. package/dist/lib/staleness/writers/mcp.d.ts +1 -1
  111. package/dist/lib/staleness/writers/permissions.d.ts +1 -1
  112. package/dist/lib/staleness/writers/plugins.d.ts +1 -1
  113. package/dist/lib/staleness/writers/rules.d.ts +1 -1
  114. package/dist/lib/staleness/writers/skills.d.ts +1 -1
  115. package/dist/lib/staleness/writers/subagents.d.ts +1 -1
  116. package/dist/lib/staleness/writers/workflows.d.ts +1 -1
  117. package/dist/lib/startup/command-registry.js +5 -2
  118. package/dist/lib/state.d.ts +0 -3
  119. package/dist/lib/state.js +2 -25
  120. package/dist/lib/types.d.ts +0 -1
  121. package/dist/lib/watchdog/runner.d.ts +0 -2
  122. package/dist/lib/watchdog/runner.js +0 -2
  123. package/package.json +1 -1
  124. package/scripts/postinstall.js +2 -2
  125. package/dist/commands/routines.d.ts +0 -14
  126. package/dist/commands/routines.js +0 -2149
  127. package/dist/commands/routines.test-fixture.d.ts +0 -52
  128. package/dist/commands/routines.test-fixture.js +0 -254
  129. package/dist/lib/catchup.d.ts +0 -19
  130. package/dist/lib/catchup.js +0 -83
  131. package/dist/lib/daemon/catchup-service.d.ts +0 -18
  132. package/dist/lib/daemon/catchup-service.js +0 -21
  133. package/dist/lib/daemon/runner.d.ts +0 -91
  134. package/dist/lib/daemon/runner.js +0 -1927
  135. package/dist/lib/harness/adapters/droid.d.ts +0 -2
  136. package/dist/lib/harness/adapters/droid.js +0 -14
  137. package/dist/lib/overdue.d.ts +0 -9
  138. package/dist/lib/overdue.js +0 -74
  139. package/dist/lib/routine-activation.d.ts +0 -13
  140. package/dist/lib/routine-activation.js +0 -117
  141. package/dist/lib/routine-context.d.ts +0 -59
  142. package/dist/lib/routine-context.js +0 -181
  143. package/dist/lib/routine-notify-owner.d.ts +0 -4
  144. package/dist/lib/routine-notify-owner.js +0 -49
  145. package/dist/lib/routine-notify.d.ts +0 -17
  146. package/dist/lib/routine-notify.js +0 -138
  147. package/dist/lib/routine-process-cleanup.d.ts +0 -9
  148. package/dist/lib/routine-process-cleanup.js +0 -81
  149. package/dist/lib/routine-readiness.d.ts +0 -31
  150. package/dist/lib/routine-readiness.js +0 -256
  151. package/dist/lib/routines-format.d.ts +0 -7
  152. package/dist/lib/routines-format.js +0 -127
  153. package/dist/lib/routines-placement.d.ts +0 -16
  154. package/dist/lib/routines-placement.js +0 -60
  155. package/dist/lib/routines-project.d.ts +0 -49
  156. package/dist/lib/routines-project.js +0 -306
  157. package/dist/lib/sandbox.d.ts +0 -15
  158. package/dist/lib/sandbox.js +0 -309
  159. package/dist/lib/scheduler.d.ts +0 -23
  160. package/dist/lib/scheduler.js +0 -106
  161. package/dist/lib/scheduling/routines.d.ts +0 -264
  162. package/dist/lib/scheduling/routines.js +0 -1292
  163. package/dist/lib/triggers/webhook.d.ts +0 -26
  164. package/dist/lib/triggers/webhook.js +0 -181
@@ -1,52 +0,0 @@
1
- import { describe } from 'vitest';
2
- import { spawnSync, spawn } from 'child_process';
3
- export declare const REPO_ROOT: string;
4
- export declare const TSX_IMPORT: string;
5
- export declare const CLI_ENTRYPOINT: string;
6
- export declare const describeRoutines: typeof describe.skip;
7
- export declare function makeHome(opts?: {
8
- jobs?: Record<string, unknown>[];
9
- projectJobs?: Record<string, unknown>[];
10
- registry?: Record<string, unknown>;
11
- deviceRoutines?: Record<string, string[]>;
12
- tmpPrefix?: string;
13
- }): string;
14
- export declare function run(home: string, args: string[], extraEnv?: Record<string, string>, cwd?: string): ReturnType<typeof spawnSync>;
15
- export declare function readRoutineYaml(home: string, name: string): Record<string, unknown> | null;
16
- export declare function writeRunMeta(home: string, jobName: string, runId: string, meta: Record<string, unknown>): void;
17
- export declare function isProcessAlive(pid: number): boolean;
18
- export declare function createDaemonHarness(fileSlug: string): {
19
- startIsolatedDaemon: (home: string) => {
20
- child: ReturnType<typeof spawn>;
21
- pidPromise: Promise<number | null>;
22
- };
23
- stopIsolatedDaemon: (child: ReturnType<typeof spawn>) => Promise<void>;
24
- registerLeakDetector: () => void;
25
- makeDaemonHome: (opts?: Omit<Parameters<typeof makeHome>[0], 'tmpPrefix'>) => string;
26
- };
27
- export declare const baseJob: {
28
- name: string;
29
- schedule: string;
30
- agent: string;
31
- prompt: string;
32
- cwd: string;
33
- enabled: boolean;
34
- };
35
- export declare const registry: {
36
- 'yosemite-s0': {
37
- name: string;
38
- platform: string;
39
- };
40
- 'mac-mini': {
41
- name: string;
42
- platform: string;
43
- };
44
- zion: {
45
- name: string;
46
- platform: string;
47
- };
48
- };
49
- export declare function readDeviceRoutines(home: string, device: string): string[];
50
- export declare function writeDeviceRoutines(home: string, device: string, routines: string[]): void;
51
- export declare function writeProject(home: string, name: string): void;
52
- export declare function projectsEnv(home: string): Record<string, string>;
@@ -1,254 +0,0 @@
1
- import { describe, afterAll } from 'vitest';
2
- import { spawnSync, spawn, execFileSync } from 'child_process';
3
- import * as fs from 'fs';
4
- import * as os from 'os';
5
- import * as path from 'path';
6
- import * as yaml from 'yaml';
7
- import { fileURLToPath, pathToFileURL } from 'url';
8
- import { createRequire } from 'module';
9
- export const REPO_ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..', '..');
10
- const require = createRequire(import.meta.url);
11
- export const TSX_IMPORT = pathToFileURL(require.resolve('tsx')).href;
12
- export const CLI_ENTRYPOINT = path.join(REPO_ROOT, 'src', 'index.ts');
13
- export const describeRoutines = process.platform === 'win32' ? describe.skip : describe;
14
- export function makeHome(opts = {}) {
15
- const home = fs.mkdtempSync(opts.tmpPrefix ?? path.join(os.tmpdir(), 'agents-routines-test-'));
16
- const agentsDir = path.join(home, '.agents');
17
- const routinesDir = path.join(agentsDir, 'routines');
18
- const projectDir = path.join(home, 'project');
19
- const projectRoutinesDir = path.join(projectDir, '.agents', 'routines');
20
- fs.mkdirSync(routinesDir, { recursive: true });
21
- fs.mkdirSync(projectRoutinesDir, { recursive: true });
22
- fs.mkdirSync(path.join(projectDir, '.git'), { recursive: true });
23
- fs.writeFileSync(path.join(agentsDir, 'agents.yaml'), 'agents: {}\n');
24
- fs.mkdirSync(path.join(agentsDir, '.system', '.git'), { recursive: true });
25
- for (const job of opts.jobs ?? []) {
26
- fs.writeFileSync(path.join(routinesDir, `${job.name}.yml`), yaml.stringify(job));
27
- }
28
- for (const job of opts.projectJobs ?? []) {
29
- fs.writeFileSync(path.join(projectRoutinesDir, `${job.name}.yml`), yaml.stringify(job));
30
- }
31
- if (opts.registry) {
32
- const devicesDir = path.join(agentsDir, '.history', 'devices');
33
- fs.mkdirSync(devicesDir, { recursive: true });
34
- fs.writeFileSync(path.join(devicesDir, 'registry.json'), JSON.stringify(opts.registry));
35
- }
36
- for (const [device, routines] of Object.entries(opts.deviceRoutines ?? {})) {
37
- writeDeviceRoutines(home, device, routines);
38
- }
39
- return home;
40
- }
41
- export function run(home, args, extraEnv = {}, cwd = REPO_ROOT) {
42
- return spawnSync('node', ['--import', TSX_IMPORT, CLI_ENTRYPOINT, 'routines', ...args], {
43
- cwd,
44
- env: {
45
- ...process.env,
46
- HOME: home,
47
- USERPROFILE: home,
48
- AGENTS_DEVICES_DIR: path.join(home, '.agents', '.history', 'devices'),
49
- AGENTS_SKIP_MIGRATION: '1',
50
- ...extraEnv,
51
- },
52
- encoding: 'utf-8',
53
- timeout: 30_000,
54
- });
55
- }
56
- export function readRoutineYaml(home, name) {
57
- const p = path.join(home, '.agents', 'routines', `${name}.yml`);
58
- if (!fs.existsSync(p))
59
- return null;
60
- return yaml.parse(fs.readFileSync(p, 'utf-8'));
61
- }
62
- export function writeRunMeta(home, jobName, runId, meta) {
63
- const runDir = path.join(home, '.agents', '.history', 'runs', jobName, runId);
64
- fs.mkdirSync(runDir, { recursive: true });
65
- fs.writeFileSync(path.join(runDir, 'meta.json'), JSON.stringify(meta));
66
- }
67
- function daemonPidPath(home) {
68
- return path.join(home, '.agents', '.cache', 'helpers', 'daemon', 'daemon.pid');
69
- }
70
- function readDaemonPid(home) {
71
- const pidPath = daemonPidPath(home);
72
- if (!fs.existsSync(pidPath))
73
- return null;
74
- const raw = fs.readFileSync(pidPath, 'utf-8').trim();
75
- const pid = parseInt(raw, 10);
76
- return isNaN(pid) ? null : pid;
77
- }
78
- export function isProcessAlive(pid) {
79
- try {
80
- process.kill(pid, 0);
81
- return true;
82
- }
83
- catch {
84
- return false;
85
- }
86
- }
87
- export function createDaemonHarness(fileSlug) {
88
- const homePrefix = path.join(os.tmpdir(), `agents-routines-${fileSlug}-`);
89
- const trackedDaemonPids = new Set();
90
- function startIsolatedDaemon(home) {
91
- const child = spawn('node', ['--import', 'tsx', 'src/index.ts', '__daemon-run'], {
92
- cwd: REPO_ROOT,
93
- env: {
94
- ...process.env,
95
- HOME: home,
96
- USERPROFILE: home,
97
- AGENTS_HISTORY_DIR: path.join(home, '.agents', '.history'),
98
- AGENTS_SKIP_MIGRATION: '1',
99
- AGENTS_DAEMON_TEST_HOME: home,
100
- },
101
- detached: true,
102
- stdio: 'ignore',
103
- });
104
- if (child.pid)
105
- trackedDaemonPids.add(child.pid);
106
- const pidPromise = new Promise((resolve) => {
107
- const deadline = Date.now() + 15_000;
108
- const interval = setInterval(() => {
109
- const pid = readDaemonPid(home);
110
- if (pid) {
111
- clearInterval(interval);
112
- resolve(pid);
113
- return;
114
- }
115
- if (Date.now() >= deadline) {
116
- clearInterval(interval);
117
- resolve(null);
118
- }
119
- }, 50);
120
- });
121
- return { child, pidPromise };
122
- }
123
- async function stopIsolatedDaemon(child) {
124
- const pid = child.pid;
125
- try {
126
- if (!pid)
127
- return;
128
- const closePromise = new Promise((resolve) => {
129
- if (child.exitCode !== null || child.signalCode !== null) {
130
- resolve();
131
- return;
132
- }
133
- child.on('close', () => resolve());
134
- });
135
- if (child.exitCode !== null || child.signalCode !== null)
136
- return;
137
- const signalProcessGroup = process.platform !== 'win32';
138
- const signal = (sig) => {
139
- try {
140
- if (signalProcessGroup) {
141
- process.kill(-pid, sig);
142
- }
143
- else {
144
- child.kill(sig);
145
- }
146
- }
147
- catch {
148
- }
149
- };
150
- signal('SIGTERM');
151
- const timer = setTimeout(() => signal('SIGKILL'), 3_000);
152
- await closePromise;
153
- clearTimeout(timer);
154
- }
155
- finally {
156
- if (pid)
157
- trackedDaemonPids.delete(pid);
158
- }
159
- }
160
- function registerLeakDetector() {
161
- afterAll(() => {
162
- const leaks = [];
163
- const killDaemon = (pid) => {
164
- try {
165
- process.kill(-pid, 'SIGKILL');
166
- }
167
- catch { }
168
- try {
169
- process.kill(pid, 'SIGKILL');
170
- }
171
- catch { }
172
- };
173
- for (const pid of trackedDaemonPids) {
174
- if (isProcessAlive(pid)) {
175
- leaks.push(`pid ${pid} (spawned by this test run, never reaped by its own test)`);
176
- killDaemon(pid);
177
- }
178
- }
179
- trackedDaemonPids.clear();
180
- if (process.env.CI && process.platform !== 'win32') {
181
- const prefix = homePrefix;
182
- let psOut = '';
183
- try {
184
- psOut = execFileSync('ps', ['-eo', 'pid=,args='], { encoding: 'utf-8', stdio: ['ignore', 'pipe', 'ignore'] });
185
- }
186
- catch { }
187
- for (const line of psOut.split('\n')) {
188
- const m = line.trim().match(/^(\d+)\s+(.*)$/);
189
- if (!m)
190
- continue;
191
- const tokens = m[2].trim().split(/\s+/);
192
- if (tokens[tokens.length - 1] !== '__daemon-run')
193
- continue;
194
- const pid = parseInt(m[1], 10);
195
- if (isNaN(pid))
196
- continue;
197
- let home = null;
198
- try {
199
- const environ = fs.readFileSync(`/proc/${pid}/environ`, 'utf-8');
200
- const homeVar = environ.split('\0').find((v) => v.startsWith('HOME='));
201
- home = homeVar ? homeVar.slice(5) : null;
202
- }
203
- catch {
204
- continue;
205
- }
206
- if (!home || !home.startsWith(prefix))
207
- continue;
208
- leaks.push(`pid ${pid} HOME=${home} (leaked from a previous interrupted run of this file)`);
209
- killDaemon(pid);
210
- }
211
- }
212
- if (leaks.length > 0) {
213
- throw new Error(`RUSH-2367 leak detector: ${leaks.length} __daemon-run process(es) survived this test file, ` +
214
- `now force-killed: ${leaks.join('; ')}`);
215
- }
216
- });
217
- }
218
- function makeDaemonHome(opts = {}) {
219
- return makeHome({ ...opts, tmpPrefix: homePrefix });
220
- }
221
- return { startIsolatedDaemon, stopIsolatedDaemon, registerLeakDetector, makeDaemonHome };
222
- }
223
- export const baseJob = {
224
- name: 'test-job',
225
- schedule: '0 3 * * *',
226
- agent: 'claude',
227
- prompt: 'noop',
228
- cwd: '~',
229
- enabled: true,
230
- };
231
- export const registry = {
232
- 'yosemite-s0': { name: 'yosemite-s0', platform: 'linux' },
233
- 'mac-mini': { name: 'mac-mini', platform: 'macos' },
234
- 'zion': { name: 'zion', platform: 'macos' },
235
- };
236
- export function readDeviceRoutines(home, device) {
237
- const file = path.join(home, '.agents', 'devices', device, 'agents.yaml');
238
- if (!fs.existsSync(file))
239
- return [];
240
- return yaml.parse(fs.readFileSync(file, 'utf-8')).routines ?? [];
241
- }
242
- export function writeDeviceRoutines(home, device, routines) {
243
- const dir = path.join(home, '.agents', 'devices', device);
244
- fs.mkdirSync(dir, { recursive: true });
245
- fs.writeFileSync(path.join(dir, 'agents.yaml'), yaml.stringify({ routines }));
246
- }
247
- export function writeProject(home, name) {
248
- const dir = path.join(home, '.agents', 'projects');
249
- fs.mkdirSync(dir, { recursive: true });
250
- fs.writeFileSync(path.join(dir, `${name}.yaml`), yaml.stringify({ name }));
251
- }
252
- export function projectsEnv(home) {
253
- return { AGENTS_PROJECTS_DIR: path.join(home, '.agents', 'projects') };
254
- }
@@ -1,19 +0,0 @@
1
- import { type JobConfig, type RunMeta } from './scheduling/routines.js';
2
- import { type OverdueJob } from './overdue.js';
3
- export interface CatchupOutcome {
4
- name: string;
5
- expectedAt: Date;
6
- result: 'ran' | 'recorded' | 'claimed-elsewhere' | 'error';
7
- runId?: string;
8
- error?: string;
9
- }
10
- export declare function shouldCatchUp(job: Pick<JobConfig, 'catchup'>): boolean;
11
- export declare function missedRunId(expectedAt: Date): string;
12
- export declare function claimMissedFire(job: JobConfig, expectedAt: Date): RunMeta | null;
13
- interface CatchupOptions {
14
- dryRun?: boolean;
15
- now?: Date;
16
- overdue?: OverdueJob[];
17
- }
18
- export declare function runCatchup(opts?: CatchupOptions): Promise<CatchupOutcome[]>;
19
- export {};
@@ -1,83 +0,0 @@
1
- import * as fs from 'fs';
2
- import * as path from 'path';
3
- import { readJob, writeRunMeta, getRunDir, } from './scheduling/routines.js';
4
- import { detectOverdueJobs } from './overdue.js';
5
- import { executeJobDetached } from './daemon/runner.js';
6
- export function shouldCatchUp(job) {
7
- return job.catchup !== false;
8
- }
9
- export function missedRunId(expectedAt) {
10
- return expectedAt.toISOString().replace(/[:.]/g, '-');
11
- }
12
- export function claimMissedFire(job, expectedAt) {
13
- const runId = missedRunId(expectedAt);
14
- const runDir = getRunDir(job.name, runId);
15
- fs.mkdirSync(path.dirname(runDir), { recursive: true });
16
- try {
17
- fs.mkdirSync(runDir);
18
- }
19
- catch (err) {
20
- if (err.code === 'EEXIST')
21
- return null;
22
- throw err;
23
- }
24
- const at = expectedAt.toISOString();
25
- const meta = {
26
- jobName: job.name,
27
- runId,
28
- agent: job.agent,
29
- workflow: job.workflow,
30
- command: job.command,
31
- pid: null,
32
- status: 'missed',
33
- startedAt: at,
34
- completedAt: at,
35
- exitCode: null,
36
- errorMessage: 'scheduled fire missed — the scheduler was not running when it came due',
37
- actor: job.actor,
38
- };
39
- writeRunMeta(meta);
40
- return meta;
41
- }
42
- export async function runCatchup(opts = {}) {
43
- const overdue = opts.overdue ?? detectOverdueJobs(opts.now ?? new Date());
44
- const outcomes = [];
45
- for (const entry of overdue) {
46
- const config = readJob(entry.name);
47
- if (!config) {
48
- outcomes.push({
49
- name: entry.name,
50
- expectedAt: entry.expectedAt,
51
- result: 'error',
52
- error: 'config not found',
53
- });
54
- continue;
55
- }
56
- if (claimMissedFire(config, entry.expectedAt) === null) {
57
- outcomes.push({ name: entry.name, expectedAt: entry.expectedAt, result: 'claimed-elsewhere' });
58
- continue;
59
- }
60
- if (!shouldCatchUp(config) || opts.dryRun) {
61
- outcomes.push({ name: entry.name, expectedAt: entry.expectedAt, result: 'recorded' });
62
- continue;
63
- }
64
- try {
65
- const meta = await executeJobDetached(config, undefined, { kind: 'catchup' });
66
- outcomes.push({
67
- name: entry.name,
68
- expectedAt: entry.expectedAt,
69
- result: 'ran',
70
- runId: meta.runId,
71
- });
72
- }
73
- catch (err) {
74
- outcomes.push({
75
- name: entry.name,
76
- expectedAt: entry.expectedAt,
77
- result: 'error',
78
- error: err instanceof Error ? err.message : String(err),
79
- });
80
- }
81
- }
82
- return outcomes;
83
- }
@@ -1,18 +0,0 @@
1
- import { BasePeriodicService, type DaemonContext } from './service.js';
2
- import type { DaemonServiceId } from '../daemon-services.js';
3
- export declare const CATCHUP_TICK_MS: number;
4
- interface CatchupServiceDeps {
5
- isSchedulerBooted: () => boolean;
6
- runPass: (signal: AbortSignal) => Promise<void>;
7
- }
8
- export declare class CatchupService extends BasePeriodicService {
9
- private readonly deps;
10
- readonly id: DaemonServiceId;
11
- readonly intervalMs: number;
12
- readonly deadlineMs: number;
13
- constructor(deps: CatchupServiceDeps);
14
- protected onStart(): Promise<void>;
15
- protected onStop(): Promise<void>;
16
- protected onTick(_ctx: DaemonContext, signal: AbortSignal): Promise<void>;
17
- }
18
- export {};
@@ -1,21 +0,0 @@
1
- import { BasePeriodicService } from './service.js';
2
- export const CATCHUP_TICK_MS = 5 * 60_000;
3
- export class CatchupService extends BasePeriodicService {
4
- deps;
5
- id = 'catchup';
6
- intervalMs = CATCHUP_TICK_MS;
7
- deadlineMs = 4 * 60_000;
8
- constructor(deps) {
9
- super();
10
- this.deps = deps;
11
- }
12
- async onStart() {
13
- }
14
- async onStop() {
15
- }
16
- async onTick(_ctx, signal) {
17
- if (!this.deps.isSchedulerBooted())
18
- return;
19
- await this.deps.runPass(signal);
20
- }
21
- }
@@ -1,91 +0,0 @@
1
- import type { JobConfig, RunMeta } from '../scheduling/routines.js';
2
- import { readMeta } from '../state.js';
3
- import type { AgentId } from '../types.js';
4
- import { type FallbackEntry } from '../exec.js';
5
- import type { LoopDeps } from '../loop.js';
6
- import { resolveRunVersion, resolveAccountCandidate, resolveAccountVersion, type RotateResult } from '../accounting/rotate.js';
7
- export interface RunResult {
8
- meta: RunMeta;
9
- reportPath: string | null;
10
- }
11
- export declare class RoutineAlreadyRunningError extends Error {
12
- constructor(jobName: string, runId: string);
13
- }
14
- export declare function activeRunSkipStreak(runs: RunMeta[]): number;
15
- export declare function launcherClaimPid(): number | null;
16
- interface RoutineTrigger {
17
- kind: NonNullable<RunMeta['triggerKind']>;
18
- scheduledFor?: Date | string;
19
- }
20
- interface RoutineAttempt {
21
- runId: string;
22
- stamp: Partial<Pick<RunMeta, 'triggerKind' | 'scheduledFor' | 'project' | 'requestedCwd' | 'resolvedCwd'>>;
23
- }
24
- export declare function routineSpawnCwd(config: Pick<JobConfig, 'name' | 'project' | 'cwd' | 'agent' | 'workflow' | 'command'>): string;
25
- export declare function bakeRoutineArgv(agent: string): string[] | undefined;
26
- export declare function buildJobCommand(config: JobConfig, resolvedPrompt: string, forwardAccount?: boolean): string[];
27
- export declare function snapshotRoutineTranscriptBase(meta: Pick<RunMeta, 'jobName' | 'agent' | 'version'>, runDir: string, overlayHome?: string): void;
28
- export declare function archiveRoutineTranscripts(meta: Pick<RunMeta, 'jobName' | 'runId' | 'agent' | 'version'>, runDir: string, overlayHome?: string): void;
29
- interface RoutineLaunchPlan {
30
- chain: FallbackEntry[];
31
- rotation: RotateResult | null;
32
- pinned: boolean;
33
- forwardAccount?: boolean;
34
- }
35
- export declare function claudeVersionIsAuthenticated(version: string): boolean;
36
- export declare function resolveRoutineLaunch(config: JobConfig, cwd?: string, deps?: {
37
- resolveRunVersion?: typeof resolveRunVersion;
38
- resolveAccountVersion?: typeof resolveAccountVersion;
39
- resolveAccountCandidate?: typeof resolveAccountCandidate;
40
- findCredentialAccount?: (name: string) => boolean;
41
- readMeta?: typeof readMeta;
42
- resolveCredentialAccount?: (name: string, host: AgentId) => {
43
- env: Record<string, string>;
44
- };
45
- claudeVersionIsAuthenticated?: typeof claudeVersionIsAuthenticated;
46
- }): Promise<RoutineLaunchPlan>;
47
- export declare function pinJobBinary(cmd: string[], agent: AgentId, version: string | undefined): string[];
48
- export declare function assertRoutineAccountLocalForPlacement(config: Pick<JobConfig, 'name' | 'account'>, mode: 'host' | 'cloud', deps?: {
49
- account?: import('../account-registry.js').UnifiedAccount | null;
50
- readMeta?: typeof readMeta;
51
- }): Promise<void>;
52
- export declare function dispatchPlacedJob(config: JobConfig, target: import('../routines-placement.js').PlacementTarget, attempt: RoutineAttempt, deps?: {
53
- account?: import('../account-registry.js').UnifiedAccount | null;
54
- host?: typeof executeJobOnHost;
55
- cloud?: typeof executeJobOnCloud;
56
- }): Promise<RunResult | undefined>;
57
- export declare function buildHostDispatchOptions(config: JobConfig, ctx: {
58
- remoteCwd: string | undefined;
59
- runDir: string;
60
- detached: boolean;
61
- }): import('../hosts/run-target.js').HostPromptRun;
62
- export declare function dispatchesViaAgentsRun(config: Pick<JobConfig, 'workflow' | 'resume' | 'agent' | 'account'>): boolean;
63
- /**
64
- * Inject a provider account's env into a routine spawn. Native accounts do not
65
- * belong here — they re-enter `agents run <agent>#<name>` so T5 slot resolution
66
- * picks the HOME. A provider-pinned routine stays on this path so the durable
67
- * credential is still in the child env (PHNX-3940 T5 seam / T7).
68
- */
69
- export declare function mergeRoutineProviderEnv(env: Record<string, string>, config: Pick<JobConfig, 'account' | 'agent' | 'workflow' | 'resume'>, agent: AgentId): Record<string, string>;
70
- export declare function buildRoutineSpawnEnv(baseEnv: Record<string, string>, agent: AgentId, version: string | undefined, timezone?: string, overlayHome?: string): Record<string, string>;
71
- export declare function executeJob(config: JobConfig, deps?: LoopDeps, trigger?: RoutineTrigger): Promise<RunResult>;
72
- declare function executeJobOnCloud(config: JobConfig, opts: {
73
- detached: boolean;
74
- }, attempt: RoutineAttempt): Promise<RunResult>;
75
- declare function executeJobOnHost(config: JobConfig, opts: {
76
- detached: boolean;
77
- }, attempt: RoutineAttempt): Promise<RunResult>;
78
- interface RoutineHooks {
79
- onFinish?: (meta: RunMeta) => void;
80
- }
81
- export declare function executeJobDetached(config: JobConfig, hooks?: RoutineHooks, trigger?: RoutineTrigger): Promise<RunMeta>;
82
- export declare function extractReport(stdoutPath: string, agentType: AgentId): string | null;
83
- export declare function inferFinalStatusFromLog(stdoutPath: string, agent: AgentId): {
84
- status: 'completed' | 'failed';
85
- exitCode: number;
86
- } | null;
87
- export declare function listLiveRoutineChildren(): number[];
88
- export declare function isRunGenuinelyInFlight(meta: RunMeta): boolean;
89
- export declare function monitorRunningJobs(): void;
90
- export declare function reapExitedRunningJobs(): Promise<void>;
91
- export {};