@herdctl/core 0.0.1 → 0.0.2

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 (275) hide show
  1. package/dist/config/__tests__/agent.test.js +31 -13
  2. package/dist/config/__tests__/agent.test.js.map +1 -1
  3. package/dist/config/__tests__/merge.test.js +9 -2
  4. package/dist/config/__tests__/merge.test.js.map +1 -1
  5. package/dist/config/__tests__/schema.test.js +350 -1
  6. package/dist/config/__tests__/schema.test.js.map +1 -1
  7. package/dist/config/index.d.ts +1 -1
  8. package/dist/config/index.d.ts.map +1 -1
  9. package/dist/config/index.js +3 -1
  10. package/dist/config/index.js.map +1 -1
  11. package/dist/config/schema.d.ts +828 -24
  12. package/dist/config/schema.d.ts.map +1 -1
  13. package/dist/config/schema.js +118 -6
  14. package/dist/config/schema.js.map +1 -1
  15. package/dist/fleet-manager/__tests__/coverage.test.js +11 -332
  16. package/dist/fleet-manager/__tests__/coverage.test.js.map +1 -1
  17. package/dist/fleet-manager/__tests__/errors.test.js +1 -49
  18. package/dist/fleet-manager/__tests__/errors.test.js.map +1 -1
  19. package/dist/fleet-manager/__tests__/integration.test.js +109 -0
  20. package/dist/fleet-manager/__tests__/integration.test.js.map +1 -1
  21. package/dist/fleet-manager/__tests__/reload.test.js +1 -1
  22. package/dist/fleet-manager/__tests__/reload.test.js.map +1 -1
  23. package/dist/fleet-manager/config-reload.d.ts +164 -0
  24. package/dist/fleet-manager/config-reload.d.ts.map +1 -0
  25. package/dist/fleet-manager/config-reload.js +445 -0
  26. package/dist/fleet-manager/config-reload.js.map +1 -0
  27. package/dist/fleet-manager/context.d.ts +76 -0
  28. package/dist/fleet-manager/context.d.ts.map +1 -0
  29. package/dist/fleet-manager/context.js +11 -0
  30. package/dist/fleet-manager/context.js.map +1 -0
  31. package/dist/fleet-manager/errors.d.ts +0 -25
  32. package/dist/fleet-manager/errors.d.ts.map +1 -1
  33. package/dist/fleet-manager/errors.js +0 -38
  34. package/dist/fleet-manager/errors.js.map +1 -1
  35. package/dist/fleet-manager/event-emitters.d.ts +123 -0
  36. package/dist/fleet-manager/event-emitters.d.ts.map +1 -0
  37. package/dist/fleet-manager/event-emitters.js +136 -0
  38. package/dist/fleet-manager/event-emitters.js.map +1 -0
  39. package/dist/fleet-manager/event-types.d.ts +0 -15
  40. package/dist/fleet-manager/event-types.d.ts.map +1 -1
  41. package/dist/fleet-manager/fleet-manager.d.ts +40 -653
  42. package/dist/fleet-manager/fleet-manager.d.ts.map +1 -1
  43. package/dist/fleet-manager/fleet-manager.js +95 -1720
  44. package/dist/fleet-manager/fleet-manager.js.map +1 -1
  45. package/dist/fleet-manager/index.d.ts +13 -2
  46. package/dist/fleet-manager/index.d.ts.map +1 -1
  47. package/dist/fleet-manager/index.js +19 -6
  48. package/dist/fleet-manager/index.js.map +1 -1
  49. package/dist/fleet-manager/job-control.d.ts +64 -0
  50. package/dist/fleet-manager/job-control.d.ts.map +1 -0
  51. package/dist/fleet-manager/job-control.js +296 -0
  52. package/dist/fleet-manager/job-control.js.map +1 -0
  53. package/dist/fleet-manager/log-streaming.d.ts +171 -0
  54. package/dist/fleet-manager/log-streaming.d.ts.map +1 -0
  55. package/dist/fleet-manager/log-streaming.js +503 -0
  56. package/dist/fleet-manager/log-streaming.js.map +1 -0
  57. package/dist/fleet-manager/schedule-executor.d.ts +63 -0
  58. package/dist/fleet-manager/schedule-executor.d.ts.map +1 -0
  59. package/dist/fleet-manager/schedule-executor.js +209 -0
  60. package/dist/fleet-manager/schedule-executor.js.map +1 -0
  61. package/dist/fleet-manager/schedule-management.d.ts +71 -0
  62. package/dist/fleet-manager/schedule-management.d.ts.map +1 -0
  63. package/dist/fleet-manager/schedule-management.js +171 -0
  64. package/dist/fleet-manager/schedule-management.js.map +1 -0
  65. package/dist/fleet-manager/status-queries.d.ts +105 -0
  66. package/dist/fleet-manager/status-queries.d.ts.map +1 -0
  67. package/dist/fleet-manager/status-queries.js +247 -0
  68. package/dist/fleet-manager/status-queries.js.map +1 -0
  69. package/dist/fleet-manager/types.d.ts +0 -39
  70. package/dist/fleet-manager/types.d.ts.map +1 -1
  71. package/dist/runner/__tests__/job-executor.test.js +206 -1
  72. package/dist/runner/__tests__/job-executor.test.js.map +1 -1
  73. package/dist/runner/job-executor.d.ts +9 -0
  74. package/dist/runner/job-executor.d.ts.map +1 -1
  75. package/dist/runner/job-executor.js +78 -4
  76. package/dist/runner/job-executor.js.map +1 -1
  77. package/dist/runner/types.d.ts +2 -0
  78. package/dist/runner/types.d.ts.map +1 -1
  79. package/dist/scheduler/__tests__/cron.test.d.ts +2 -0
  80. package/dist/scheduler/__tests__/cron.test.d.ts.map +1 -0
  81. package/dist/scheduler/__tests__/cron.test.js +867 -0
  82. package/dist/scheduler/__tests__/cron.test.js.map +1 -0
  83. package/dist/scheduler/__tests__/scheduler.test.js +164 -5
  84. package/dist/scheduler/__tests__/scheduler.test.js.map +1 -1
  85. package/dist/scheduler/cron.d.ts +126 -0
  86. package/dist/scheduler/cron.d.ts.map +1 -0
  87. package/dist/scheduler/cron.js +390 -0
  88. package/dist/scheduler/cron.js.map +1 -0
  89. package/dist/scheduler/errors.d.ts +81 -1
  90. package/dist/scheduler/errors.d.ts.map +1 -1
  91. package/dist/scheduler/errors.js +81 -6
  92. package/dist/scheduler/errors.js.map +1 -1
  93. package/dist/scheduler/index.d.ts +1 -0
  94. package/dist/scheduler/index.d.ts.map +1 -1
  95. package/dist/scheduler/index.js +2 -0
  96. package/dist/scheduler/index.js.map +1 -1
  97. package/dist/scheduler/schedule-runner.d.ts +2 -2
  98. package/dist/scheduler/schedule-runner.d.ts.map +1 -1
  99. package/dist/scheduler/schedule-runner.js +20 -8
  100. package/dist/scheduler/schedule-runner.js.map +1 -1
  101. package/dist/scheduler/scheduler.d.ts +4 -4
  102. package/dist/scheduler/scheduler.d.ts.map +1 -1
  103. package/dist/scheduler/scheduler.js +86 -20
  104. package/dist/scheduler/scheduler.js.map +1 -1
  105. package/dist/scheduler/types.d.ts +1 -1
  106. package/dist/scheduler/types.d.ts.map +1 -1
  107. package/dist/state/schemas/job-metadata.d.ts +2 -2
  108. package/package.json +33 -8
  109. package/.turbo/turbo-build.log +0 -4
  110. package/.turbo/turbo-test.log +0 -219
  111. package/.turbo/turbo-typecheck.log +0 -4
  112. package/coverage/base.css +0 -224
  113. package/coverage/block-navigation.js +0 -87
  114. package/coverage/coverage-final.json +0 -51
  115. package/coverage/favicon.png +0 -0
  116. package/coverage/index.html +0 -251
  117. package/coverage/prettify.css +0 -1
  118. package/coverage/prettify.js +0 -2
  119. package/coverage/sort-arrow-sprite.png +0 -0
  120. package/coverage/sorter.js +0 -210
  121. package/coverage/src/config/index.html +0 -191
  122. package/coverage/src/config/index.ts.html +0 -442
  123. package/coverage/src/config/interpolate.ts.html +0 -652
  124. package/coverage/src/config/loader.ts.html +0 -1501
  125. package/coverage/src/config/merge.ts.html +0 -823
  126. package/coverage/src/config/parser.ts.html +0 -1213
  127. package/coverage/src/config/schema.ts.html +0 -1123
  128. package/coverage/src/fleet-manager/errors.ts.html +0 -2326
  129. package/coverage/src/fleet-manager/event-types.ts.html +0 -1219
  130. package/coverage/src/fleet-manager/fleet-manager.ts.html +0 -7030
  131. package/coverage/src/fleet-manager/index.html +0 -206
  132. package/coverage/src/fleet-manager/index.ts.html +0 -469
  133. package/coverage/src/fleet-manager/job-manager.ts.html +0 -2074
  134. package/coverage/src/fleet-manager/job-queue.ts.html +0 -2479
  135. package/coverage/src/fleet-manager/types.ts.html +0 -2602
  136. package/coverage/src/index.html +0 -116
  137. package/coverage/src/index.ts.html +0 -181
  138. package/coverage/src/runner/errors.ts.html +0 -1006
  139. package/coverage/src/runner/index.html +0 -191
  140. package/coverage/src/runner/index.ts.html +0 -256
  141. package/coverage/src/runner/job-executor.ts.html +0 -1429
  142. package/coverage/src/runner/message-processor.ts.html +0 -1150
  143. package/coverage/src/runner/sdk-adapter.ts.html +0 -658
  144. package/coverage/src/runner/types.ts.html +0 -559
  145. package/coverage/src/scheduler/errors.ts.html +0 -388
  146. package/coverage/src/scheduler/index.html +0 -206
  147. package/coverage/src/scheduler/index.ts.html +0 -244
  148. package/coverage/src/scheduler/interval.ts.html +0 -652
  149. package/coverage/src/scheduler/schedule-runner.ts.html +0 -1411
  150. package/coverage/src/scheduler/schedule-state.ts.html +0 -718
  151. package/coverage/src/scheduler/scheduler.ts.html +0 -1795
  152. package/coverage/src/scheduler/types.ts.html +0 -733
  153. package/coverage/src/state/directory.ts.html +0 -736
  154. package/coverage/src/state/errors.ts.html +0 -376
  155. package/coverage/src/state/fleet-state.ts.html +0 -937
  156. package/coverage/src/state/index.html +0 -221
  157. package/coverage/src/state/index.ts.html +0 -322
  158. package/coverage/src/state/job-metadata.ts.html +0 -1420
  159. package/coverage/src/state/job-output.ts.html +0 -1033
  160. package/coverage/src/state/schemas/fleet-state.ts.html +0 -445
  161. package/coverage/src/state/schemas/index.html +0 -176
  162. package/coverage/src/state/schemas/index.ts.html +0 -286
  163. package/coverage/src/state/schemas/job-metadata.ts.html +0 -628
  164. package/coverage/src/state/schemas/job-output.ts.html +0 -616
  165. package/coverage/src/state/schemas/session-info.ts.html +0 -361
  166. package/coverage/src/state/session.ts.html +0 -844
  167. package/coverage/src/state/types.ts.html +0 -262
  168. package/coverage/src/state/utils/atomic.ts.html +0 -748
  169. package/coverage/src/state/utils/index.html +0 -146
  170. package/coverage/src/state/utils/index.ts.html +0 -103
  171. package/coverage/src/state/utils/reads.ts.html +0 -1621
  172. package/coverage/src/work-sources/adapters/github.ts.html +0 -3583
  173. package/coverage/src/work-sources/adapters/index.html +0 -131
  174. package/coverage/src/work-sources/adapters/index.ts.html +0 -277
  175. package/coverage/src/work-sources/errors.ts.html +0 -298
  176. package/coverage/src/work-sources/index.html +0 -176
  177. package/coverage/src/work-sources/index.ts.html +0 -529
  178. package/coverage/src/work-sources/manager.ts.html +0 -1324
  179. package/coverage/src/work-sources/registry.ts.html +0 -619
  180. package/coverage/src/work-sources/types.ts.html +0 -568
  181. package/dist/fleet-manager/__tests__/event-helpers.test.d.ts +0 -7
  182. package/dist/fleet-manager/__tests__/event-helpers.test.d.ts.map +0 -1
  183. package/dist/fleet-manager/__tests__/event-helpers.test.js +0 -368
  184. package/dist/fleet-manager/__tests__/event-helpers.test.js.map +0 -1
  185. package/src/config/__tests__/agent.test.ts +0 -864
  186. package/src/config/__tests__/interpolate.test.ts +0 -644
  187. package/src/config/__tests__/loader.test.ts +0 -784
  188. package/src/config/__tests__/merge.test.ts +0 -751
  189. package/src/config/__tests__/parser.test.ts +0 -533
  190. package/src/config/__tests__/schema.test.ts +0 -873
  191. package/src/config/index.ts +0 -119
  192. package/src/config/interpolate.ts +0 -189
  193. package/src/config/loader.ts +0 -472
  194. package/src/config/merge.ts +0 -246
  195. package/src/config/parser.ts +0 -376
  196. package/src/config/schema.ts +0 -346
  197. package/src/fleet-manager/__tests__/coverage.test.ts +0 -2869
  198. package/src/fleet-manager/__tests__/errors.test.ts +0 -660
  199. package/src/fleet-manager/__tests__/event-helpers.test.ts +0 -448
  200. package/src/fleet-manager/__tests__/integration.test.ts +0 -1209
  201. package/src/fleet-manager/__tests__/job-control.test.ts +0 -283
  202. package/src/fleet-manager/__tests__/job-manager.test.ts +0 -869
  203. package/src/fleet-manager/__tests__/job-queue.test.ts +0 -401
  204. package/src/fleet-manager/__tests__/reload.test.ts +0 -751
  205. package/src/fleet-manager/__tests__/status-queries.test.ts +0 -595
  206. package/src/fleet-manager/__tests__/trigger.test.ts +0 -601
  207. package/src/fleet-manager/errors.ts +0 -747
  208. package/src/fleet-manager/event-types.ts +0 -378
  209. package/src/fleet-manager/fleet-manager.ts +0 -2315
  210. package/src/fleet-manager/index.ts +0 -128
  211. package/src/fleet-manager/job-manager.ts +0 -663
  212. package/src/fleet-manager/job-queue.ts +0 -798
  213. package/src/fleet-manager/types.ts +0 -839
  214. package/src/index.ts +0 -32
  215. package/src/runner/__tests__/errors.test.ts +0 -382
  216. package/src/runner/__tests__/job-executor.test.ts +0 -1708
  217. package/src/runner/__tests__/message-processor.test.ts +0 -960
  218. package/src/runner/__tests__/sdk-adapter.test.ts +0 -626
  219. package/src/runner/errors.ts +0 -307
  220. package/src/runner/index.ts +0 -57
  221. package/src/runner/job-executor.ts +0 -448
  222. package/src/runner/message-processor.ts +0 -355
  223. package/src/runner/sdk-adapter.ts +0 -191
  224. package/src/runner/types.ts +0 -158
  225. package/src/scheduler/__tests__/errors.test.ts +0 -159
  226. package/src/scheduler/__tests__/interval.test.ts +0 -515
  227. package/src/scheduler/__tests__/schedule-runner.test.ts +0 -798
  228. package/src/scheduler/__tests__/schedule-state.test.ts +0 -671
  229. package/src/scheduler/__tests__/scheduler.test.ts +0 -1280
  230. package/src/scheduler/errors.ts +0 -101
  231. package/src/scheduler/index.ts +0 -53
  232. package/src/scheduler/interval.ts +0 -189
  233. package/src/scheduler/schedule-runner.ts +0 -442
  234. package/src/scheduler/schedule-state.ts +0 -211
  235. package/src/scheduler/scheduler.ts +0 -570
  236. package/src/scheduler/types.ts +0 -216
  237. package/src/state/__tests__/directory.test.ts +0 -595
  238. package/src/state/__tests__/fleet-state.test.ts +0 -868
  239. package/src/state/__tests__/job-metadata-schema.test.ts +0 -414
  240. package/src/state/__tests__/job-metadata.test.ts +0 -831
  241. package/src/state/__tests__/job-output.test.ts +0 -856
  242. package/src/state/__tests__/session-schema.test.ts +0 -378
  243. package/src/state/__tests__/session.test.ts +0 -604
  244. package/src/state/directory.ts +0 -217
  245. package/src/state/errors.ts +0 -97
  246. package/src/state/fleet-state.ts +0 -284
  247. package/src/state/index.ts +0 -79
  248. package/src/state/job-metadata.ts +0 -445
  249. package/src/state/job-output.ts +0 -316
  250. package/src/state/schemas/__tests__/job-output.test.ts +0 -338
  251. package/src/state/schemas/fleet-state.ts +0 -120
  252. package/src/state/schemas/index.ts +0 -67
  253. package/src/state/schemas/job-metadata.ts +0 -181
  254. package/src/state/schemas/job-output.ts +0 -177
  255. package/src/state/schemas/session-info.ts +0 -92
  256. package/src/state/session.ts +0 -253
  257. package/src/state/types.ts +0 -59
  258. package/src/state/utils/__tests__/atomic.test.ts +0 -723
  259. package/src/state/utils/__tests__/reads.test.ts +0 -1071
  260. package/src/state/utils/atomic.ts +0 -221
  261. package/src/state/utils/index.ts +0 -6
  262. package/src/state/utils/reads.ts +0 -512
  263. package/src/work-sources/__tests__/github.test.ts +0 -1800
  264. package/src/work-sources/__tests__/manager.test.ts +0 -529
  265. package/src/work-sources/__tests__/registry.test.ts +0 -477
  266. package/src/work-sources/__tests__/types.test.ts +0 -479
  267. package/src/work-sources/adapters/github.ts +0 -1166
  268. package/src/work-sources/adapters/index.ts +0 -64
  269. package/src/work-sources/errors.ts +0 -71
  270. package/src/work-sources/index.ts +0 -148
  271. package/src/work-sources/manager.ts +0 -413
  272. package/src/work-sources/registry.ts +0 -178
  273. package/src/work-sources/types.ts +0 -161
  274. package/tsconfig.json +0 -9
  275. package/vitest.config.ts +0 -19
@@ -1,88 +1,28 @@
1
1
  /**
2
- * FleetManager class for library consumers
2
+ * FleetManager - High-level orchestration layer for autonomous agents
3
3
  *
4
- * Provides a simple, high-level API to initialize and run a fleet of agents
5
- * with minimal configuration. Handles config loading, state directory setup,
6
- * and scheduler orchestration internally.
7
- *
8
- * @example
9
- * ```typescript
10
- * import { FleetManager } from '@herdctl/core';
11
- *
12
- * const manager = new FleetManager({
13
- * configPath: './herdctl.yaml',
14
- * stateDir: './.herdctl',
15
- * });
16
- *
17
- * await manager.initialize();
18
- * await manager.start();
4
+ * The FleetManager class provides a simple interface for library consumers
5
+ * to initialize and run agent fleets. It coordinates between:
6
+ * - Configuration loading and validation
7
+ * - State directory management
8
+ * - Scheduler setup and lifecycle
9
+ * - Event emission for monitoring
19
10
  *
20
- * // Later...
21
- * await manager.stop();
22
- * ```
11
+ * @module fleet-manager
23
12
  */
24
13
  import { EventEmitter } from "node:events";
25
14
  import { type ResolvedConfig, type ResolvedAgent } from "../config/index.js";
26
- import type { FleetManagerOptions, FleetManagerState, ConfigReloadedPayload, AgentStartedPayload, AgentStoppedPayload, ScheduleSkippedPayload, JobCreatedPayload, JobOutputPayload, JobCompletedPayload, JobFailedPayload, JobCancelledPayload, JobForkedPayload, FleetStatus, AgentInfo, ScheduleInfo, TriggerOptions, TriggerResult, JobModifications, CancelJobResult, ForkJobResult, FleetManagerStopOptions, LogEntry, LogStreamOptions } from "./types.js";
15
+ import { type StateDirectory } from "../state/index.js";
16
+ import { Scheduler } from "../scheduler/index.js";
17
+ import type { FleetManagerContext } from "./context.js";
18
+ import type { FleetManagerOptions, FleetManagerState, FleetManagerStatus, FleetManagerLogger, FleetManagerStopOptions, FleetStatus, AgentInfo, ScheduleInfo, TriggerOptions, TriggerResult, JobModifications, CancelJobResult, ForkJobResult, LogEntry, LogStreamOptions, ConfigChange, ConfigReloadedPayload } from "./types.js";
27
19
  /**
28
- * FleetManager provides a simple API to manage a fleet of agents
29
- *
30
- * This class is the primary entry point for library consumers who want to
31
- * run herdctl programmatically. It handles:
32
- *
33
- * - Configuration loading and validation
34
- * - State directory initialization
35
- * - Scheduler lifecycle management
36
- * - Event emission for monitoring
37
- *
38
- * ## Lifecycle
39
- *
40
- * 1. **Construction**: Create with options (configPath, stateDir)
41
- * 2. **Initialize**: Call `initialize()` to load config and prepare state
42
- * 3. **Start**: Call `start()` to begin scheduler and process schedules
43
- * 4. **Stop**: Call `stop()` to gracefully shut down
44
- *
45
- * ## Events
46
- *
47
- * The FleetManager emits events for monitoring:
48
- * - `initialized` - After successful initialization
49
- * - `started` - When the scheduler starts running
50
- * - `stopped` - When the scheduler stops
51
- * - `error` - When an error occurs
52
- * - `schedule:trigger` - When a schedule triggers an agent
53
- * - `schedule:complete` - When an agent run completes
54
- * - `schedule:error` - When an agent run fails
55
- *
56
- * ## Typed Events (US-2)
20
+ * FleetManager provides high-level orchestration for autonomous agents
57
21
  *
58
- * The FleetManager also supports strongly-typed events via TypeScript:
59
- * - `config:reloaded` - When configuration is hot-reloaded
60
- * - `agent:started` - When an agent is started
61
- * - `agent:stopped` - When an agent is stopped
62
- * - `schedule:triggered` - When a schedule triggers (with payload)
63
- * - `schedule:skipped` - When a schedule is skipped
64
- * - `job:created` - When a job is created
65
- * - `job:output` - When a job produces output
66
- * - `job:completed` - When a job completes successfully
67
- * - `job:failed` - When a job fails
68
- *
69
- * @example
70
- * ```typescript
71
- * // Subscribe to typed events
72
- * manager.on('job:created', (payload) => {
73
- * console.log(`Job ${payload.job.id} created for ${payload.agentName}`);
74
- * });
75
- *
76
- * manager.on('job:output', (payload) => {
77
- * process.stdout.write(payload.output);
78
- * });
79
- *
80
- * manager.on('job:completed', (payload) => {
81
- * console.log(`Job completed in ${payload.durationSeconds}s`);
82
- * });
83
- * ```
22
+ * Implements FleetManagerContext to provide clean access to internal state
23
+ * for composed module classes.
84
24
  */
85
- export declare class FleetManager extends EventEmitter {
25
+ export declare class FleetManager extends EventEmitter implements FleetManagerContext {
86
26
  private readonly configPath?;
87
27
  private readonly stateDir;
88
28
  private readonly logger;
@@ -95,605 +35,52 @@ export declare class FleetManager extends EventEmitter {
95
35
  private startedAt;
96
36
  private stoppedAt;
97
37
  private lastError;
98
- /**
99
- * Create a new FleetManager instance
100
- *
101
- * @param options - Configuration options
102
- *
103
- * @example
104
- * ```typescript
105
- * // Minimal configuration
106
- * const manager = new FleetManager({
107
- * configPath: './herdctl.yaml',
108
- * stateDir: './.herdctl',
109
- * });
110
- *
111
- * // With custom logger
112
- * const manager = new FleetManager({
113
- * configPath: './herdctl.yaml',
114
- * stateDir: './.herdctl',
115
- * logger: myLogger,
116
- * checkInterval: 5000, // 5 seconds
117
- * });
118
- * ```
119
- */
38
+ private statusQueries;
39
+ private scheduleManagement;
40
+ private configReloadModule;
41
+ private jobControl;
42
+ private logStreaming;
43
+ private scheduleExecutor;
120
44
  constructor(options: FleetManagerOptions);
121
- /**
122
- * Get the current fleet manager state
123
- *
124
- * This provides a snapshot of the fleet manager's current status and
125
- * configuration for monitoring purposes.
126
- */
127
- get state(): FleetManagerState;
128
- /**
129
- * Get the loaded configuration
130
- *
131
- * @returns The resolved configuration, or null if not initialized
132
- */
133
45
  getConfig(): ResolvedConfig | null;
134
- /**
135
- * Get the loaded agents
136
- *
137
- * @returns Array of resolved agents, or empty array if not initialized
138
- */
46
+ getStateDir(): string;
47
+ getStateDirInfo(): StateDirectory | null;
48
+ getLogger(): FleetManagerLogger;
49
+ getScheduler(): Scheduler | null;
50
+ getStatus(): FleetManagerStatus;
51
+ getInitializedAt(): string | null;
52
+ getStartedAt(): string | null;
53
+ getStoppedAt(): string | null;
54
+ getLastError(): string | null;
55
+ getCheckInterval(): number;
56
+ getEmitter(): EventEmitter;
57
+ get state(): FleetManagerState;
139
58
  getAgents(): ResolvedAgent[];
140
- /**
141
- * Get overall fleet status
142
- *
143
- * Returns a comprehensive snapshot of the fleet state including:
144
- * - Current state and uptime
145
- * - Agent counts (total, idle, running, error)
146
- * - Job counts
147
- * - Scheduler information
148
- *
149
- * This method works whether the fleet is running or stopped.
150
- *
151
- * @returns A consistent FleetStatus snapshot
152
- *
153
- * @example
154
- * ```typescript
155
- * const status = await manager.getFleetStatus();
156
- * console.log(`Fleet: ${status.state}`);
157
- * console.log(`Uptime: ${status.uptimeSeconds}s`);
158
- * console.log(`Running jobs: ${status.counts.runningJobs}`);
159
- * ```
160
- */
59
+ initialize(): Promise<void>;
60
+ start(): Promise<void>;
61
+ stop(options?: FleetManagerStopOptions): Promise<void>;
161
62
  getFleetStatus(): Promise<FleetStatus>;
162
- /**
163
- * Get information about all configured agents
164
- *
165
- * Returns detailed information for each agent including:
166
- * - Current status and job information
167
- * - Schedule details with runtime state
168
- * - Configuration details
169
- *
170
- * This method works whether the fleet is running or stopped.
171
- *
172
- * @returns Array of AgentInfo objects with current state
173
- *
174
- * @example
175
- * ```typescript
176
- * const agents = await manager.getAgentInfo();
177
- * for (const agent of agents) {
178
- * console.log(`${agent.name}: ${agent.status}`);
179
- * console.log(` Schedules: ${agent.scheduleCount}`);
180
- * }
181
- * ```
182
- */
183
63
  getAgentInfo(): Promise<AgentInfo[]>;
184
- /**
185
- * Get information about a specific agent by name
186
- *
187
- * Returns detailed information for the specified agent including:
188
- * - Current status and job information
189
- * - Schedule details with runtime state
190
- * - Configuration details
191
- *
192
- * This method works whether the fleet is running or stopped.
193
- *
194
- * @param name - The agent name to look up
195
- * @returns AgentInfo for the specified agent
196
- * @throws {AgentNotFoundError} If no agent with that name exists
197
- *
198
- * @example
199
- * ```typescript
200
- * const agent = await manager.getAgentInfoByName('my-agent');
201
- * console.log(`Agent: ${agent.name}`);
202
- * console.log(`Status: ${agent.status}`);
203
- * console.log(`Running: ${agent.runningCount}/${agent.maxConcurrent}`);
204
- * ```
205
- */
206
64
  getAgentInfoByName(name: string): Promise<AgentInfo>;
207
- /**
208
- * Read fleet state from disk for status queries
209
- *
210
- * This provides a consistent snapshot of the fleet state.
211
- */
212
- private readFleetStateSnapshot;
213
- /**
214
- * Build AgentInfo from configuration and state
215
- */
216
- private buildAgentInfo;
217
- /**
218
- * Build schedule info list from agent configuration and state
219
- */
220
- private buildScheduleInfoList;
221
- /**
222
- * Compute fleet counts from agent info list
223
- */
224
- private computeFleetCounts;
225
- /**
226
- * Get all schedules across all agents
227
- *
228
- * Returns a list of all configured schedules with their current state,
229
- * including next trigger times.
230
- *
231
- * @returns Array of ScheduleInfo objects with current state
232
- *
233
- * @example
234
- * ```typescript
235
- * const schedules = await manager.getSchedules();
236
- * for (const schedule of schedules) {
237
- * console.log(`${schedule.agentName}/${schedule.name}: ${schedule.status}`);
238
- * console.log(` Next run: ${schedule.nextRunAt}`);
239
- * }
240
- * ```
241
- */
242
65
  getSchedules(): Promise<ScheduleInfo[]>;
243
- /**
244
- * Get a specific schedule by agent name and schedule name
245
- *
246
- * @param agentName - The name of the agent
247
- * @param scheduleName - The name of the schedule
248
- * @returns The schedule info with current state
249
- * @throws {AgentNotFoundError} If the agent doesn't exist
250
- * @throws {ScheduleNotFoundError} If the schedule doesn't exist
251
- *
252
- * @example
253
- * ```typescript
254
- * const schedule = await manager.getSchedule('my-agent', 'hourly');
255
- * console.log(`Status: ${schedule.status}`);
256
- * console.log(`Last run: ${schedule.lastRunAt}`);
257
- * console.log(`Next run: ${schedule.nextRunAt}`);
258
- * ```
259
- */
260
66
  getSchedule(agentName: string, scheduleName: string): Promise<ScheduleInfo>;
261
- /**
262
- * Enable a disabled schedule
263
- *
264
- * Enables a schedule that was previously disabled, allowing it to trigger
265
- * again on its configured interval. The enabled state is persisted to the
266
- * state directory and survives restarts.
267
- *
268
- * @param agentName - The name of the agent
269
- * @param scheduleName - The name of the schedule
270
- * @returns The updated schedule info
271
- * @throws {AgentNotFoundError} If the agent doesn't exist
272
- * @throws {ScheduleNotFoundError} If the schedule doesn't exist
273
- *
274
- * @example
275
- * ```typescript
276
- * // Enable a previously disabled schedule
277
- * const schedule = await manager.enableSchedule('my-agent', 'hourly');
278
- * console.log(`Schedule status: ${schedule.status}`); // 'idle'
279
- * ```
280
- */
281
67
  enableSchedule(agentName: string, scheduleName: string): Promise<ScheduleInfo>;
282
- /**
283
- * Disable a schedule
284
- *
285
- * Disables a schedule, preventing it from triggering on its configured
286
- * interval. The schedule remains in the configuration but won't run until
287
- * re-enabled. The disabled state is persisted to the state directory and
288
- * survives restarts.
289
- *
290
- * @param agentName - The name of the agent
291
- * @param scheduleName - The name of the schedule
292
- * @returns The updated schedule info
293
- * @throws {AgentNotFoundError} If the agent doesn't exist
294
- * @throws {ScheduleNotFoundError} If the schedule doesn't exist
295
- *
296
- * @example
297
- * ```typescript
298
- * // Disable a schedule temporarily
299
- * const schedule = await manager.disableSchedule('my-agent', 'hourly');
300
- * console.log(`Schedule status: ${schedule.status}`); // 'disabled'
301
- *
302
- * // Later, re-enable it
303
- * await manager.enableSchedule('my-agent', 'hourly');
304
- * ```
305
- */
306
68
  disableSchedule(agentName: string, scheduleName: string): Promise<ScheduleInfo>;
307
- /**
308
- * Initialize the fleet manager
309
- *
310
- * This method:
311
- * 1. Loads and validates the configuration file
312
- * 2. Initializes the state directory structure
313
- * 3. Prepares the scheduler (but does not start it)
314
- *
315
- * After initialization, the fleet manager is ready to start.
316
- *
317
- * @throws {FleetManagerStateError} If already initialized or running
318
- * @throws {FleetManagerConfigError} If configuration is invalid or not found
319
- * @throws {FleetManagerStateDirError} If state directory cannot be created
320
- *
321
- * @example
322
- * ```typescript
323
- * const manager = new FleetManager({ ... });
324
- * await manager.initialize();
325
- * console.log(`Loaded ${manager.state.agentCount} agents`);
326
- * ```
327
- */
328
- initialize(): Promise<void>;
329
- /**
330
- * Start the fleet manager
331
- *
332
- * This begins the scheduler, which will:
333
- * 1. Check agent schedules at the configured interval
334
- * 2. Trigger agents when their schedules are due
335
- * 3. Track schedule state in the state directory
336
- *
337
- * @throws {FleetManagerStateError} If not initialized
338
- *
339
- * @example
340
- * ```typescript
341
- * await manager.initialize();
342
- * await manager.start();
343
- *
344
- * // The manager is now running and processing schedules
345
- * manager.on('schedule:trigger', (agent, schedule) => {
346
- * console.log(`Triggered ${agent}/${schedule}`);
347
- * });
348
- * ```
349
- */
350
- start(): Promise<void>;
351
- /**
352
- * Stop the fleet manager gracefully
353
- *
354
- * This will:
355
- * 1. Signal the scheduler to stop accepting new triggers
356
- * 2. Wait for running jobs to complete (with timeout)
357
- * 3. If timeout is reached and cancelOnTimeout is true, cancel remaining jobs
358
- * 4. Persist all state before shutdown completes
359
- * 5. Emit 'stopped' event when complete
360
- *
361
- * @param options - Stop options for controlling shutdown behavior
362
- * @throws {FleetManagerShutdownError} If shutdown times out and cancelOnTimeout is false
363
- *
364
- * @example
365
- * ```typescript
366
- * // Normal shutdown - wait for jobs with default 30s timeout
367
- * await manager.stop();
368
- *
369
- * // Shutdown with custom timeout
370
- * await manager.stop({ timeout: 60000 });
371
- *
372
- * // Shutdown without waiting for jobs (not recommended)
373
- * await manager.stop({ waitForJobs: false });
374
- *
375
- * // Cancel jobs if they don't complete in time
376
- * await manager.stop({
377
- * timeout: 30000,
378
- * cancelOnTimeout: true,
379
- * cancelTimeout: 10000,
380
- * });
381
- * ```
382
- */
383
- stop(options?: FleetManagerStopOptions): Promise<void>;
384
- /**
385
- * Reload configuration without restarting the fleet
386
- *
387
- * This method provides hot configuration reload capability:
388
- * 1. Loads and validates the new configuration
389
- * 2. If validation fails, keeps the old configuration (fails gracefully)
390
- * 3. Running jobs continue with their original configuration
391
- * 4. New jobs will use the new configuration
392
- * 5. Updates the scheduler with new agent definitions and schedules
393
- * 6. Emits a 'config:reloaded' event with a list of changes
394
- *
395
- * @returns The reload result with change details
396
- * @throws {InvalidStateError} If the fleet manager is not initialized
397
- * @throws {FleetManagerConfigError} If the new configuration is invalid (re-thrown after logging)
398
- *
399
- * @example
400
- * ```typescript
401
- * // Reload configuration
402
- * const result = await manager.reload();
403
- * console.log(`Reloaded with ${result.changes.length} changes`);
404
- *
405
- * // Subscribe to reload events
406
- * manager.on('config:reloaded', (payload) => {
407
- * console.log(`Config reloaded: ${payload.changes.length} changes`);
408
- * for (const change of payload.changes) {
409
- * console.log(` ${change.type} ${change.category}: ${change.name}`);
410
- * }
411
- * });
412
- * ```
413
- */
414
69
  reload(): Promise<ConfigReloadedPayload>;
415
- /**
416
- * Compute the list of changes between old and new configuration
417
- */
418
- private computeConfigChanges;
419
- /**
420
- * Check if an agent configuration has been modified
421
- * Returns a description of what changed, or null if not modified
422
- */
423
- private isAgentModified;
424
- /**
425
- * Check if a schedule configuration has been modified
426
- */
427
- private isScheduleModified;
428
- /**
429
- * Get a description of what changed in a schedule
430
- */
431
- private getScheduleModificationDetails;
432
- /**
433
- * Cancel all running jobs during shutdown
434
- *
435
- * @param cancelTimeout - Timeout for each job cancellation
436
- */
437
- private cancelRunningJobs;
438
- /**
439
- * Persist shutdown state to ensure all state is saved before completing
440
- */
441
- private persistShutdownState;
442
- /**
443
- * Manually trigger an agent outside its normal schedule
444
- *
445
- * This method allows you to trigger an agent on-demand for testing or
446
- * handling urgent situations. You can optionally specify a schedule to use
447
- * for configuration (prompt, work source, etc.) or pass runtime options
448
- * to override defaults.
449
- *
450
- * @param agentName - Name of the agent to trigger
451
- * @param scheduleName - Optional schedule name to use for configuration
452
- * @param options - Optional runtime options to override defaults
453
- * @returns The created job information
454
- * @throws {InvalidStateError} If the fleet manager is not initialized
455
- * @throws {AgentNotFoundError} If the agent doesn't exist
456
- * @throws {ScheduleNotFoundError} If the specified schedule doesn't exist
457
- * @throws {ConcurrencyLimitError} If the agent is at capacity and bypassConcurrencyLimit is false
458
- *
459
- * @example
460
- * ```typescript
461
- * // Trigger with agent defaults
462
- * const job = await manager.trigger('my-agent');
463
- *
464
- * // Trigger a specific schedule
465
- * const job = await manager.trigger('my-agent', 'hourly');
466
- *
467
- * // Trigger with custom prompt
468
- * const job = await manager.trigger('my-agent', undefined, {
469
- * prompt: 'Review the latest security updates',
470
- * });
471
- *
472
- * // Force trigger even at capacity
473
- * const job = await manager.trigger('my-agent', undefined, {
474
- * bypassConcurrencyLimit: true,
475
- * });
476
- * ```
477
- */
70
+ computeConfigChanges(oldConfig: ResolvedConfig | null, newConfig: ResolvedConfig): ConfigChange[];
478
71
  trigger(agentName: string, scheduleName?: string, options?: TriggerOptions): Promise<TriggerResult>;
479
- /**
480
- * Cancel a running job gracefully
481
- *
482
- * This method cancels a running job by first sending SIGTERM to allow
483
- * graceful shutdown. If the job doesn't terminate within the timeout,
484
- * it will be forcefully killed with SIGKILL.
485
- *
486
- * @param jobId - ID of the job to cancel
487
- * @param options - Optional cancellation options
488
- * @param options.timeout - Time in ms to wait for graceful shutdown (default: 10000)
489
- * @returns Result of the cancellation operation
490
- * @throws {InvalidStateError} If the fleet manager is not initialized
491
- * @throws {JobNotFoundError} If the job doesn't exist
492
- *
493
- * @example
494
- * ```typescript
495
- * // Cancel with default timeout
496
- * const result = await manager.cancelJob('job-2024-01-15-abc123');
497
- * console.log(`Job cancelled: ${result.terminationType}`);
498
- *
499
- * // Cancel with custom timeout
500
- * const result = await manager.cancelJob('job-2024-01-15-abc123', {
501
- * timeout: 30000, // 30 seconds
502
- * });
503
- * ```
504
- */
505
72
  cancelJob(jobId: string, options?: {
506
73
  timeout?: number;
507
74
  }): Promise<CancelJobResult>;
508
- /**
509
- * Fork a job to create a new job based on an existing one
510
- *
511
- * This method creates a new job that is based on an existing job's
512
- * configuration. The new job will have the same agent and can optionally
513
- * have modifications applied (different prompt, schedule, etc.).
514
- *
515
- * If the original job has a session ID, the new job will fork from that
516
- * session, preserving conversation context.
517
- *
518
- * @param jobId - ID of the job to fork
519
- * @param modifications - Optional modifications to apply to the forked job
520
- * @returns Result of the fork operation including the new job ID
521
- * @throws {InvalidStateError} If the fleet manager is not initialized
522
- * @throws {JobNotFoundError} If the original job doesn't exist
523
- * @throws {JobForkError} If the job cannot be forked (e.g., no session)
524
- *
525
- * @example
526
- * ```typescript
527
- * // Fork with same configuration
528
- * const result = await manager.forkJob('job-2024-01-15-abc123');
529
- * console.log(`Forked to: ${result.jobId}`);
530
- *
531
- * // Fork with modified prompt
532
- * const result = await manager.forkJob('job-2024-01-15-abc123', {
533
- * prompt: 'Continue the previous task but focus on testing',
534
- * });
535
- *
536
- * // Fork with different schedule
537
- * const result = await manager.forkJob('job-2024-01-15-abc123', {
538
- * schedule: 'nightly',
539
- * });
540
- * ```
541
- */
542
75
  forkJob(jobId: string, modifications?: JobModifications): Promise<ForkJobResult>;
543
- /**
544
- * Stream all fleet logs as an async iterable
545
- *
546
- * Provides a unified stream of logs from all sources in the fleet including
547
- * agents, jobs, and the scheduler. Logs can be filtered by level and optionally
548
- * by agent or job.
549
- *
550
- * For completed jobs, this will replay their history (if includeHistory is true)
551
- * before streaming new logs from running jobs.
552
- *
553
- * @param options - Options for filtering and configuring the stream
554
- * @returns An async iterable of LogEntry objects
555
- *
556
- * @example
557
- * ```typescript
558
- * // Stream all info+ logs
559
- * for await (const log of manager.streamLogs()) {
560
- * console.log(`[${log.level}] ${log.message}`);
561
- * }
562
- *
563
- * // Stream only errors for a specific agent
564
- * for await (const log of manager.streamLogs({
565
- * level: 'error',
566
- * agentName: 'my-agent',
567
- * })) {
568
- * console.error(log.message);
569
- * }
570
- * ```
571
- */
572
76
  streamLogs(options?: LogStreamOptions): AsyncIterable<LogEntry>;
573
- /**
574
- * Stream output from a specific job as an async iterable
575
- *
576
- * Provides a stream of log entries for a specific job. For completed jobs,
577
- * this will replay the job's history and then complete. For running jobs,
578
- * it will continue streaming until the job completes.
579
- *
580
- * @param jobId - The ID of the job to stream output from
581
- * @returns An async iterable of LogEntry objects
582
- * @throws {JobNotFoundError} If the job doesn't exist
583
- *
584
- * @example
585
- * ```typescript
586
- * // Stream job output
587
- * for await (const log of manager.streamJobOutput('job-2024-01-15-abc123')) {
588
- * console.log(`[${log.level}] ${log.message}`);
589
- * }
590
- * ```
591
- */
592
77
  streamJobOutput(jobId: string): AsyncIterable<LogEntry>;
593
- /**
594
- * Stream logs for a specific agent as an async iterable
595
- *
596
- * Provides a stream of log entries for all jobs belonging to a specific agent.
597
- * For completed jobs, this will replay their history. For running jobs, it
598
- * will continue streaming until the iterator is stopped.
599
- *
600
- * @param agentName - The name of the agent to stream logs for
601
- * @returns An async iterable of LogEntry objects
602
- * @throws {AgentNotFoundError} If the agent doesn't exist in the configuration
603
- *
604
- * @example
605
- * ```typescript
606
- * // Stream all logs for an agent
607
- * for await (const log of manager.streamAgentLogs('my-agent')) {
608
- * console.log(`[${log.jobId}] ${log.message}`);
609
- * }
610
- * ```
611
- */
612
78
  streamAgentLogs(agentName: string): AsyncIterable<LogEntry>;
613
- /**
614
- * Convert a job output message to a LogEntry
615
- */
616
- private jobOutputToLogEntry;
617
- /**
618
- * Determine if a log entry should be yielded based on filters
619
- */
620
- private shouldYieldLog;
621
- /**
622
- * Load configuration with proper error handling
623
- */
79
+ private initializeModules;
624
80
  private loadConfiguration;
625
- /**
626
- * Initialize state directory with proper error handling
627
- */
628
81
  private initializeStateDir;
629
- /**
630
- * Start the scheduler asynchronously (don't block on the loop)
631
- */
632
82
  private startSchedulerAsync;
633
- /**
634
- * Handle schedule trigger callback from scheduler
635
- */
636
83
  private handleScheduleTrigger;
637
- /**
638
- * Emit a config:reloaded event
639
- *
640
- * Called when configuration is hot-reloaded.
641
- */
642
- emitConfigReloaded(payload: ConfigReloadedPayload): void;
643
- /**
644
- * Emit an agent:started event
645
- *
646
- * Called when an agent is started/registered with the fleet.
647
- */
648
- emitAgentStarted(payload: AgentStartedPayload): void;
649
- /**
650
- * Emit an agent:stopped event
651
- *
652
- * Called when an agent is stopped/unregistered from the fleet.
653
- */
654
- emitAgentStopped(payload: AgentStoppedPayload): void;
655
- /**
656
- * Emit a schedule:skipped event
657
- *
658
- * Called when a schedule check is skipped (already running, disabled, etc.).
659
- */
660
- emitScheduleSkipped(payload: ScheduleSkippedPayload): void;
661
- /**
662
- * Emit a job:created event
663
- *
664
- * Called when a new job is created.
665
- */
666
- emitJobCreated(payload: JobCreatedPayload): void;
667
- /**
668
- * Emit a job:output event
669
- *
670
- * Called when a job produces output during execution.
671
- * This enables real-time streaming of output to UIs.
672
- */
673
- emitJobOutput(payload: JobOutputPayload): void;
674
- /**
675
- * Emit a job:completed event
676
- *
677
- * Called when a job completes successfully.
678
- */
679
- emitJobCompleted(payload: JobCompletedPayload): void;
680
- /**
681
- * Emit a job:failed event
682
- *
683
- * Called when a job fails.
684
- */
685
- emitJobFailed(payload: JobFailedPayload): void;
686
- /**
687
- * Emit a job:cancelled event (US-6)
688
- *
689
- * Called when a job is cancelled.
690
- */
691
- emitJobCancelled(payload: JobCancelledPayload): void;
692
- /**
693
- * Emit a job:forked event (US-6)
694
- *
695
- * Called when a job is forked to create a new job.
696
- */
697
- emitJobForked(payload: JobForkedPayload): void;
84
+ private persistShutdownState;
698
85
  }
699
86
  //# sourceMappingURL=fleet-manager.d.ts.map