@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,309 +0,0 @@
1
- import * as fs from 'fs';
2
- import * as path from 'path';
3
- import * as os from 'os';
4
- import { getRoutinesDir, getUserAgentsDir } from './state.js';
5
- import { safeJoin } from './paths.js';
6
- import { createLink } from './platform/index.js';
7
- import { getVersionHomePath } from './installations/versions.js';
8
- function resolveRealHome() {
9
- const home = os.homedir();
10
- try {
11
- return fs.realpathSync(home);
12
- }
13
- catch {
14
- return home;
15
- }
16
- }
17
- const ENV_ALLOWLIST = [
18
- 'PATH',
19
- 'SHELL',
20
- 'TERM',
21
- 'LANG',
22
- 'LC_ALL',
23
- 'LC_CTYPE',
24
- 'USER',
25
- 'LOGNAME',
26
- 'TMPDIR',
27
- 'XDG_RUNTIME_DIR',
28
- 'XDG_CONFIG_HOME',
29
- 'XDG_DATA_HOME',
30
- 'XDG_CACHE_HOME',
31
- 'NODE_PATH',
32
- 'NVM_DIR',
33
- 'BUN_INSTALL',
34
- 'EDITOR',
35
- 'VISUAL',
36
- 'NO_COLOR',
37
- 'FORCE_COLOR',
38
- 'GH_TOKEN',
39
- 'GH_HOST',
40
- 'GH_ENTERPRISE_TOKEN',
41
- 'GITHUB_TOKEN',
42
- 'GH_CONFIG_DIR',
43
- ];
44
- const SAFE_TOOLS = {
45
- web_search: 'WebSearch(*)',
46
- web_fetch: 'WebFetch(*)',
47
- };
48
- const DIR_SCOPED_TOOLS = new Set(['read', 'write', 'edit', 'glob', 'grep', 'notebook_edit']);
49
- function tomlString(value) {
50
- if (/[\r\n]/.test(value)) {
51
- throw new Error(`TOML value contains newline: ${JSON.stringify(value)}`);
52
- }
53
- return `"${value.replace(/\\/g, '\\\\').replace(/"/g, '\\"')}"`;
54
- }
55
- export function resolveHostGhConfigDir() {
56
- if (process.env.GH_CONFIG_DIR && fs.existsSync(process.env.GH_CONFIG_DIR)) {
57
- return process.env.GH_CONFIG_DIR;
58
- }
59
- const configHome = process.env.XDG_CONFIG_HOME || path.join(resolveRealHome(), '.config');
60
- const ghDir = path.join(configHome, 'gh');
61
- return fs.existsSync(ghDir) ? ghDir : null;
62
- }
63
- export function hostHasGhAuth() {
64
- if (process.env.GH_TOKEN || process.env.GH_ENTERPRISE_TOKEN || process.env.GITHUB_TOKEN) {
65
- return true;
66
- }
67
- const dir = resolveHostGhConfigDir();
68
- if (!dir)
69
- return false;
70
- return fs.existsSync(path.join(dir, 'hosts.yml'));
71
- }
72
- export function buildSpawnEnv(overlayHome, extraEnv) {
73
- const env = {
74
- HOME: overlayHome,
75
- AGENTS_USER_DIR: getUserAgentsDir(),
76
- };
77
- for (const key of ENV_ALLOWLIST) {
78
- if (process.env[key]) {
79
- env[key] = process.env[key];
80
- }
81
- }
82
- const hostGh = resolveHostGhConfigDir();
83
- if (hostGh) {
84
- env.GH_CONFIG_DIR = hostGh;
85
- }
86
- else {
87
- delete env.GH_CONFIG_DIR;
88
- }
89
- if (extraEnv) {
90
- Object.assign(env, extraEnv);
91
- }
92
- return env;
93
- }
94
- export function getJobHomePath(name) {
95
- return path.join(safeJoin(getRoutinesDir(), name), 'home');
96
- }
97
- export function prepareJobHome(config, version) {
98
- const overlayHome = getJobHomePath(config.name);
99
- cleanJobHome(config.name);
100
- fs.mkdirSync(overlayHome, { recursive: true });
101
- if (config.agent === 'claude') {
102
- generateClaudeConfig(overlayHome, config);
103
- }
104
- else if (config.agent === 'codex') {
105
- generateCodexConfig(overlayHome, config);
106
- linkVersionAuth(overlayHome, 'codex', version);
107
- }
108
- else if (config.agent === 'cursor') {
109
- generateCursorConfig(overlayHome);
110
- }
111
- linkHostGhConfig(overlayHome);
112
- if (config.allow?.dirs) {
113
- symlinkAllowedDirs(overlayHome, config.allow.dirs);
114
- }
115
- return overlayHome;
116
- }
117
- export function linkVersionAuth(overlayHome, agent, version) {
118
- if (!version)
119
- return;
120
- const versionHome = getVersionHomePath(agent, version);
121
- const pairs = agent === 'claude'
122
- ? [
123
- [path.join(versionHome, '.claude', '.claude.json'), path.join(overlayHome, '.claude', '.claude.json')],
124
- [path.join(versionHome, '.claude', '.credentials.json'), path.join(overlayHome, '.claude', '.credentials.json')],
125
- ]
126
- : agent === 'codex'
127
- ? [[path.join(versionHome, '.codex', 'auth.json'), path.join(overlayHome, '.codex', 'auth.json')]]
128
- : [];
129
- for (const [source, target] of pairs) {
130
- if (!fs.existsSync(source))
131
- continue;
132
- fs.mkdirSync(path.dirname(target), { recursive: true });
133
- try {
134
- fs.rmSync(target, { force: true });
135
- }
136
- catch { }
137
- try {
138
- createLink(source, target);
139
- }
140
- catch { }
141
- }
142
- }
143
- export function linkHostGhConfig(overlayHome) {
144
- const realGhDir = resolveHostGhConfigDir();
145
- if (!realGhDir || !fs.existsSync(realGhDir))
146
- return;
147
- const overlayGhDir = path.join(overlayHome, '.config', 'gh');
148
- if (fs.existsSync(overlayGhDir))
149
- return;
150
- fs.mkdirSync(path.dirname(overlayGhDir), { recursive: true });
151
- try {
152
- createLink(realGhDir, overlayGhDir);
153
- }
154
- catch {
155
- }
156
- }
157
- export function assertSandboxForwardsHostGhAuth(spawnEnv) {
158
- if (!hostHasGhAuth())
159
- return;
160
- if (spawnEnv.GH_TOKEN || spawnEnv.GH_ENTERPRISE_TOKEN || spawnEnv.GITHUB_TOKEN)
161
- return;
162
- if (spawnEnv.GH_CONFIG_DIR && fs.existsSync(path.join(spawnEnv.GH_CONFIG_DIR, 'hosts.yml')))
163
- return;
164
- if (spawnEnv.HOME && fs.existsSync(path.join(spawnEnv.HOME, '.config', 'gh', 'hosts.yml')))
165
- return;
166
- throw new Error("sandbox spawn would hide this host's GitHub auth from the child " +
167
- '(no GH_CONFIG_DIR / ~/.config/gh / GH_TOKEN). Refusing to launch — ' +
168
- 'the agent would record ok then fail every gh call (RUSH-2860).');
169
- }
170
- export function generateCursorConfig(overlayHome) {
171
- const realCursorDir = path.join(process.env.AGENTS_REAL_HOME || resolveRealHome(), '.cursor');
172
- const realAuth = path.join(realCursorDir, 'auth.json');
173
- if (!fs.existsSync(realAuth))
174
- return;
175
- const overlayCursorDir = path.join(overlayHome, '.cursor');
176
- fs.mkdirSync(overlayCursorDir, { recursive: true });
177
- const overlayAuth = path.join(overlayCursorDir, 'auth.json');
178
- if (process.platform === 'win32') {
179
- try {
180
- fs.linkSync(realAuth, overlayAuth);
181
- }
182
- catch { }
183
- }
184
- else {
185
- fs.symlinkSync(realAuth, overlayAuth);
186
- }
187
- const realCliConfig = path.join(realCursorDir, 'cli-config.json');
188
- if (fs.existsSync(realCliConfig)) {
189
- const overlayCliConfig = path.join(overlayCursorDir, 'cli-config.json');
190
- try {
191
- if (process.platform === 'win32')
192
- fs.linkSync(realCliConfig, overlayCliConfig);
193
- else
194
- fs.symlinkSync(realCliConfig, overlayCliConfig);
195
- }
196
- catch { }
197
- }
198
- }
199
- export function cleanJobHome(name) {
200
- const overlayHome = getJobHomePath(name);
201
- if (fs.existsSync(overlayHome)) {
202
- fs.rmSync(overlayHome, { recursive: true, force: true });
203
- }
204
- }
205
- export function symlinkAllowedDirs(overlayHome, dirs) {
206
- const realHome = resolveRealHome();
207
- for (const dir of dirs) {
208
- const expanded = dir.replace(/^~/, realHome);
209
- let realPath;
210
- try {
211
- realPath = fs.realpathSync(expanded);
212
- }
213
- catch {
214
- realPath = path.resolve(expanded);
215
- }
216
- if (!realPath.startsWith(realHome + path.sep) && realPath !== realHome) {
217
- continue;
218
- }
219
- const relativePath = path.relative(realHome, realPath);
220
- const symlinkTarget = path.join(overlayHome, relativePath);
221
- const parentDir = path.dirname(symlinkTarget);
222
- fs.mkdirSync(parentDir, { recursive: true });
223
- if (!fs.existsSync(symlinkTarget)) {
224
- try {
225
- createLink(realPath, symlinkTarget);
226
- }
227
- catch { }
228
- }
229
- }
230
- }
231
- export function generateClaudeConfig(overlayHome, config) {
232
- const realHome = resolveRealHome();
233
- const claudeDir = path.join(overlayHome, '.claude');
234
- fs.mkdirSync(claudeDir, { recursive: true });
235
- const allowPermissions = [];
236
- const enabledTools = new Set(config.allow?.tools || []);
237
- if (config.allow?.tools) {
238
- for (const tool of config.allow.tools) {
239
- if (tool in SAFE_TOOLS) {
240
- allowPermissions.push(SAFE_TOOLS[tool]);
241
- continue;
242
- }
243
- if (DIR_SCOPED_TOOLS.has(tool)) {
244
- continue;
245
- }
246
- if (tool === 'bash') {
247
- throw new Error('Bare "bash" not allowed in sandbox — use scoped patterns like "Bash(git *)"');
248
- }
249
- if (/^\w+\(\*\)$/.test(tool)) {
250
- throw new Error(`Wildcard "${tool}" not allowed in sandbox — use scoped patterns`);
251
- }
252
- allowPermissions.push(tool);
253
- }
254
- }
255
- if (config.allow?.dirs) {
256
- for (const dir of config.allow.dirs) {
257
- const resolved = dir.replace(/^~/, realHome);
258
- allowPermissions.push(`Read(${resolved}/**)`);
259
- if (config.mode === 'edit') {
260
- allowPermissions.push(`Write(${resolved}/**)`);
261
- allowPermissions.push(`Edit(${resolved}/**)`);
262
- }
263
- if (enabledTools.has('glob')) {
264
- allowPermissions.push(`Glob(${resolved}/**)`);
265
- }
266
- if (enabledTools.has('grep')) {
267
- allowPermissions.push(`Grep(${resolved}/**)`);
268
- }
269
- if (enabledTools.has('notebook_edit') && config.mode === 'edit') {
270
- allowPermissions.push(`NotebookEdit(${resolved}/**)`);
271
- }
272
- }
273
- }
274
- const settings = {
275
- permissions: {
276
- allow: allowPermissions,
277
- deny: [],
278
- },
279
- };
280
- fs.writeFileSync(path.join(claudeDir, 'settings.json'), JSON.stringify(settings, null, 2), 'utf-8');
281
- }
282
- export function generateCodexConfig(overlayHome, config) {
283
- const codexDir = path.join(overlayHome, '.codex');
284
- fs.mkdirSync(codexDir, { recursive: true });
285
- const lines = [];
286
- const model = config.config?.model;
287
- if (model) {
288
- lines.push(`model = ${tomlString(model)}`);
289
- }
290
- if (config.mode === 'edit') {
291
- lines.push('approval_mode = "full-auto"');
292
- }
293
- else {
294
- lines.push('approval_mode = "suggest"');
295
- }
296
- if (config.config) {
297
- for (const [key, value] of Object.entries(config.config)) {
298
- if (key === 'model')
299
- continue;
300
- if (typeof value === 'string') {
301
- lines.push(`${key} = ${tomlString(value)}`);
302
- }
303
- else if (typeof value === 'boolean' || typeof value === 'number') {
304
- lines.push(`${key} = ${value}`);
305
- }
306
- }
307
- }
308
- fs.writeFileSync(path.join(codexDir, 'config.toml'), lines.join('\n') + '\n', 'utf-8');
309
- }
@@ -1,23 +0,0 @@
1
- import { Cron } from 'croner';
2
- import type { JobConfig } from './scheduling/routines.js';
3
- interface TriggerContext {
4
- scheduledFor?: Date;
5
- }
6
- export declare function fireSlot(cron: Cron): Date;
7
- export declare class JobScheduler {
8
- private jobs;
9
- private onTrigger;
10
- constructor(onTrigger: (config: JobConfig, ctx?: TriggerContext) => Promise<void>);
11
- loadAll(): void;
12
- schedule(config: JobConfig): void;
13
- unschedule(name: string): void;
14
- reloadAll(): void;
15
- stopAll(): void;
16
- getNextRun(name: string): Date | null;
17
- listScheduled(): Array<{
18
- name: string;
19
- nextRun: Date | null;
20
- enabled: boolean;
21
- }>;
22
- }
23
- export {};
@@ -1,106 +0,0 @@
1
- import { Cron } from 'croner';
2
- import { alignedSlotForFire, listJobs, deleteJob, isPastEndAt, isPastOneShotRoutine, isOneShotRoutine, setJobEnabled, shouldPurgeCompletedOneShotRoutine, jobRunsOnThisDevice, hasAmbiguousDevicePin, routineOwnerDevice, } from './scheduling/routines.js';
3
- export function fireSlot(cron) {
4
- const fire = cron.currentRun() ?? new Date();
5
- return alignedSlotForFire(cron, fire) ?? fire;
6
- }
7
- export class JobScheduler {
8
- jobs = new Map();
9
- onTrigger;
10
- constructor(onTrigger) {
11
- this.onTrigger = onTrigger;
12
- }
13
- loadAll() {
14
- const configs = listJobs();
15
- for (const config of configs) {
16
- if (!config.enabled || !config.schedule)
17
- continue;
18
- if (hasAmbiguousDevicePin(config)) {
19
- const owner = routineOwnerDevice(config);
20
- console.warn(`Job '${config.name}' pins ${config.devices.length} devices; a routine runs on exactly one. ` +
21
- `Firing only on '${owner}'. Fix with: agents routines devices ${config.name} --set ${owner}`);
22
- }
23
- if (!jobRunsOnThisDevice(config))
24
- continue;
25
- if (shouldPurgeCompletedOneShotRoutine(config)) {
26
- deleteJob(config.name);
27
- continue;
28
- }
29
- if (isPastOneShotRoutine(config))
30
- continue;
31
- this.schedule(config);
32
- }
33
- }
34
- schedule(config) {
35
- if (!config.schedule)
36
- return;
37
- this.unschedule(config.name);
38
- if (shouldPurgeCompletedOneShotRoutine(config)) {
39
- deleteJob(config.name);
40
- return;
41
- }
42
- if (isPastOneShotRoutine(config))
43
- return;
44
- const cronOptions = { catch: true };
45
- if (config.timezone)
46
- cronOptions.timezone = config.timezone;
47
- const cron = new Cron(config.schedule, cronOptions, async (self) => {
48
- if (isPastEndAt(config)) {
49
- this.unschedule(config.name);
50
- try {
51
- setJobEnabled(config.name, false);
52
- }
53
- catch (err) {
54
- console.error(`Job '${config.name}' endAt auto-disable failed:`, err.message);
55
- }
56
- console.log(`Job '${config.name}' reached endAt (${config.endAt}); auto-disabled.`);
57
- return;
58
- }
59
- try {
60
- await this.onTrigger(config, { scheduledFor: fireSlot(self) });
61
- }
62
- catch (err) {
63
- console.error(`Job '${config.name}' failed:`, err.message);
64
- }
65
- if (isOneShotRoutine(config)) {
66
- this.unschedule(config.name);
67
- deleteJob(config.name);
68
- }
69
- });
70
- this.jobs.set(config.name, { config, cron });
71
- }
72
- unschedule(name) {
73
- const existing = this.jobs.get(name);
74
- if (existing) {
75
- existing.cron.stop();
76
- this.jobs.delete(name);
77
- }
78
- }
79
- reloadAll() {
80
- this.stopAll();
81
- this.loadAll();
82
- }
83
- stopAll() {
84
- for (const [, job] of this.jobs) {
85
- job.cron.stop();
86
- }
87
- this.jobs.clear();
88
- }
89
- getNextRun(name) {
90
- const job = this.jobs.get(name);
91
- if (!job)
92
- return null;
93
- return job.cron.nextRun() || null;
94
- }
95
- listScheduled() {
96
- const result = [];
97
- for (const [name, job] of this.jobs) {
98
- result.push({
99
- name,
100
- nextRun: job.cron.nextRun() || null,
101
- enabled: job.config.enabled,
102
- });
103
- }
104
- return result;
105
- }
106
- }
@@ -1,264 +0,0 @@
1
- import { Cron } from 'croner';
2
- import { type ResolvedExecutionContext, type ProjectResolution, type PlacementMode, type ContextFsProbe } from '../routine-context.js';
3
- import type { AgentId, RunStrategy } from '../types.js';
4
- import type { LoopConfig } from '../loop.js';
5
- import { JobScheduler } from '../scheduler.js';
6
- export declare function fireConditionLabel(job: JobConfig): string;
7
- export declare function nextRunForDisplay(job: JobConfig, scheduler: JobScheduler): Date | null;
8
- export declare function nextRunLabel(job: JobConfig, scheduler: JobScheduler, now: Date): string;
9
- export declare function localLatestRun(job: JobConfig): RunMeta | null;
10
- export declare function listJobsForDisplay(cwd?: string): JobConfig[];
11
- export declare function buildRoutineListJson(): Record<string, unknown>[];
12
- interface RoutineStatusRow {
13
- name: string;
14
- ownerDevice: string | null;
15
- ambiguousDevicePin: boolean;
16
- enabledDevices: string[];
17
- runsHere: boolean;
18
- enabled: boolean;
19
- overdue: boolean;
20
- nextRun: string | null;
21
- lastStatus: RunMeta['status'] | null;
22
- failureReason: string | null;
23
- lastRunStartedAt: string | null;
24
- lastRunCompletedAt: string | null;
25
- inFlight: {
26
- runId: string;
27
- pid: number | null;
28
- startedAt: string;
29
- triggerKind: RunMeta['triggerKind'] | null;
30
- } | null;
31
- }
32
- export declare function buildRoutineStatusRows(): RoutineStatusRow[];
33
- export interface JobAllowConfig {
34
- tools?: string[];
35
- sites?: string[];
36
- dirs?: string[];
37
- }
38
- export type HostStrategy = 'local' | 'host' | 'fleet' | 'cloud';
39
- export declare const HOST_STRATEGIES: readonly HostStrategy[];
40
- export interface JobSource {
41
- kind: 'project';
42
- projectPath: string;
43
- repo?: string;
44
- branch?: string;
45
- commit?: string;
46
- }
47
- export type GithubTriggerEvent = 'pull_request' | 'push' | 'issue_comment' | 'workflow_run';
48
- export declare const GITHUB_TRIGGER_EVENTS: readonly GithubTriggerEvent[];
49
- export type LinearTriggerEvent = 'Issue' | 'IssueLabel' | 'Comment' | 'Project' | 'Cycle';
50
- export declare function normalizeTriggerEvent(input: string): GithubTriggerEvent | null;
51
- export interface GithubJobTrigger {
52
- type: 'github_event';
53
- event: GithubTriggerEvent;
54
- repo?: string;
55
- branch?: string;
56
- action?: string;
57
- label?: string;
58
- }
59
- export interface LinearJobTrigger {
60
- type: 'linear_event';
61
- event: LinearTriggerEvent;
62
- action?: string;
63
- teamKey?: string;
64
- label?: string;
65
- stateTo?: string;
66
- stateFrom?: string;
67
- }
68
- export type JobTrigger = GithubJobTrigger | LinearJobTrigger;
69
- export interface JobConfig {
70
- name: string;
71
- schedule?: string;
72
- trigger?: JobTrigger;
73
- agent?: AgentId | (string & {});
74
- workflow?: string;
75
- command?: string;
76
- mode: 'plan' | 'edit' | 'auto' | 'skip' | 'full';
77
- effort: 'low' | 'medium' | 'high' | 'xhigh' | 'max' | 'auto';
78
- timeout: string;
79
- enabled: boolean;
80
- prompt: string;
81
- timezone?: string;
82
- repo?: string;
83
- project?: string;
84
- cwd?: string;
85
- devices?: string[];
86
- catchup?: boolean;
87
- createdAt?: string;
88
- env?: Record<string, string>;
89
- host?: string;
90
- hostStrategy?: HostStrategy;
91
- remoteCwd?: string;
92
- source?: JobSource;
93
- variables?: Record<string, string>;
94
- sandbox?: boolean;
95
- allow?: JobAllowConfig;
96
- config?: Record<string, unknown>;
97
- version?: string;
98
- strategy?: RunStrategy;
99
- account?: string;
100
- runOnce?: boolean;
101
- endAt?: string;
102
- resume?: string;
103
- loop?: LoopConfig;
104
- actor?: string;
105
- projects?: string[];
106
- dispatchedBy?: 'webhook';
107
- }
108
- export declare function normalizeProjects(projects: string[] | undefined): string[] | undefined;
109
- type ProjectGroup = {
110
- kind: 'named';
111
- name: string;
112
- } | {
113
- kind: 'all';
114
- } | {
115
- kind: 'cross';
116
- } | {
117
- kind: 'operations';
118
- } | {
119
- kind: 'unknown';
120
- };
121
- export declare function computeProjectGroupKind(projects: string[] | undefined, knownProjectNames: Set<string>): ProjectGroup;
122
- export declare function projectGroupTitle(group: ProjectGroup): string;
123
- export declare function projectGroupKey(group: ProjectGroup): string;
124
- export declare function projectGroupOrder(group: ProjectGroup): number;
125
- export declare function computeProjectGroup(projects: string[] | undefined, knownProjectNames: Set<string>): string;
126
- export declare function resolveJobExecutionContext(config: Pick<JobConfig, 'name' | 'project' | 'cwd' | 'agent' | 'workflow' | 'command'>, opts?: {
127
- targetHome?: string;
128
- mode?: PlacementMode;
129
- probe?: ContextFsProbe | null;
130
- projectResolution?: ProjectResolution;
131
- }): ResolvedExecutionContext;
132
- export interface RunMeta {
133
- jobName: string;
134
- runId: string;
135
- agent?: AgentId | (string & {});
136
- version?: string;
137
- workflow?: string;
138
- command?: string;
139
- pid: number | null;
140
- spawnedAt?: number;
141
- timeoutMs?: number;
142
- status: 'running' | 'completed' | 'failed' | 'timeout' | 'missed' | 'blocked' | 'skipped';
143
- triggerKind?: 'schedule' | 'catchup' | 'manual' | 'webhook' | 'event';
144
- scheduledFor?: string;
145
- project?: string;
146
- requestedCwd?: string;
147
- resolvedCwd?: string;
148
- readiness?: {
149
- code: string;
150
- message: string;
151
- repair?: string;
152
- };
153
- skipReason?: 'duplicate_slot' | 'active_run' | 'wrong_owner';
154
- activeRunId?: string;
155
- startedAt: string;
156
- completedAt: string | null;
157
- exitCode: number | null;
158
- errorMessage?: string;
159
- duration?: number;
160
- host?: string;
161
- hostTaskId?: string;
162
- cloudTaskId?: string;
163
- cloudProvider?: string;
164
- actor?: string;
165
- triggeredBy?: string;
166
- }
167
- export declare function finalizeRunMeta(meta: RunMeta, status: RunMeta['status'], exitCode: number | null, opts?: {
168
- errorMessage?: string;
169
- completedAt?: string;
170
- }): void;
171
- export declare function jobRunsOnThisDevice(config: Pick<JobConfig, 'name' | 'devices' | 'dispatchedBy'>): boolean;
172
- export declare function routineOwnerDevice(config: Pick<JobConfig, 'devices'>): string | null;
173
- export declare function hasAmbiguousDevicePin(config: Pick<JobConfig, 'devices'>): boolean;
174
- interface AmbiguousDevicePin {
175
- name: string;
176
- devices: string[];
177
- owner: string;
178
- }
179
- export declare function findAmbiguousDevicePins(cwd?: string): AmbiguousDevicePin[];
180
- export declare function resolveHostStrategy(config: Pick<JobConfig, 'hostStrategy' | 'host'>): HostStrategy;
181
- export declare function parseHostStrategy(raw: string | undefined | null): HostStrategy | null;
182
- export declare function placementRequiresFiringPin(strategy: HostStrategy): boolean;
183
- interface JobEligibilityResult {
184
- message: string;
185
- suggestion: string;
186
- allowedLabel: string;
187
- firstHost: string;
188
- }
189
- export declare function checkJobDeviceEligibility(config: Pick<JobConfig, 'name' | 'devices' | 'dispatchedBy'>): JobEligibilityResult | null;
190
- export declare function listJobs(cwd?: string): JobConfig[];
191
- export declare function readJob(name: string, cwd?: string): JobConfig | null;
192
- type RoutineReadResult = {
193
- config: JobConfig;
194
- problem: null;
195
- } | {
196
- config: null;
197
- problem: string;
198
- };
199
- export declare function readJobFileResult(filePath: string): RoutineReadResult;
200
- export declare function writeJob(config: JobConfig): void;
201
- export declare function serializeJob(output: Record<string, unknown>, existingText: string | null): string;
202
- export declare function deleteJob(name: string): boolean;
203
- export declare function setJobEnabled(name: string, enabled: boolean): void;
204
- export declare function migrateLegacyRoutineActivation(): boolean;
205
- export declare function validateJob(config: Partial<JobConfig>): string[];
206
- export declare function validateTrigger(trigger: unknown): string[];
207
- export declare function isPastEndAt(config: Pick<JobConfig, 'endAt'>, now?: Date): boolean;
208
- interface OneShotScheduleParts {
209
- minute: number;
210
- hour: number;
211
- day: number;
212
- month: number;
213
- }
214
- export declare function parseOneShotLikeSchedule(schedule: string | undefined | null): OneShotScheduleParts | null;
215
- export declare function isOneShotLikeSchedule(schedule: string | undefined | null): boolean;
216
- export declare function isOneShotRoutine(config: Pick<JobConfig, 'schedule' | 'runOnce'>): boolean;
217
- export declare function oneShotScheduleFireDate(schedule: string | undefined | null, now?: Date, timezone?: string): Date | null;
218
- export declare function isPastOneShotRoutine(config: Pick<JobConfig, 'schedule' | 'runOnce' | 'timezone'>, now?: Date): boolean;
219
- export declare function hasCompletedOneShotRun(config: Pick<JobConfig, 'name' | 'schedule' | 'runOnce' | 'timezone'>, now?: Date): boolean;
220
- export declare function shouldPurgeCompletedOneShotRoutine(config: Pick<JobConfig, 'name' | 'schedule' | 'runOnce' | 'timezone'>, now?: Date): boolean;
221
- export declare function resolveJobPrompt(config: JobConfig): string;
222
- export declare function parseTimeout(timeout: string): number | null;
223
- export declare function listRuns(jobName: string): RunMeta[];
224
- export declare function getLatestRun(jobName: string): RunMeta | null;
225
- export declare function getLatestCompletedRun(jobName: string): RunMeta | null;
226
- interface RoutineStats {
227
- count: number;
228
- failed: number;
229
- missed: number;
230
- avgMs: number;
231
- p50: number;
232
- p95: number;
233
- }
234
- export declare function routineStats(jobName: string): RoutineStats;
235
- export declare function writeRunMeta(meta: RunMeta): void;
236
- export declare function readRunMeta(jobName: string, runId: string): RunMeta | null;
237
- export declare function getJobRunsDir(jobName: string): string;
238
- export declare function getRunDir(jobName: string, runId: string): string;
239
- export declare function slotRunId(scheduledFor: Date | string): string;
240
- export declare function alignedSlotForFire(cron: Cron, at: Date): Date | null;
241
- export declare function claimRunSlot(jobName: string, runId: string): boolean;
242
- export declare function discoverJobsFromRepo(repoPath: string): Array<{
243
- name: string;
244
- path: string;
245
- }>;
246
- export declare function jobExists(name: string): boolean;
247
- export declare function isCanonicalRoutineSource(sourcePath: string, name: string): boolean;
248
- export declare function getJobPath(name: string): string | null;
249
- export declare function resolveJobFilePath(name: string): string | null;
250
- export declare function parseAtTime(atTime: string): {
251
- schedule: string;
252
- runOnce: boolean;
253
- } | null;
254
- export declare function countAllRuns(): number;
255
- export declare function previewRunsPrune(keep: number): Array<{
256
- jobName: string;
257
- runId: string;
258
- startedAt: string;
259
- }>;
260
- export declare function pruneRuns(keep: number): {
261
- deleted: number;
262
- bytesFreed: number;
263
- };
264
- export {};