@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,64 +0,0 @@
1
- /**
2
- * Built-in Work Source Adapters
3
- *
4
- * This module exports built-in adapters and registers them with the
5
- * work source registry at module load time.
6
- */
7
-
8
- import { registerWorkSource, isWorkSourceRegistered } from "../registry.js";
9
- import {
10
- createGitHubAdapter,
11
- GitHubWorkSourceAdapter,
12
- GitHubAPIError,
13
- GitHubAuthError,
14
- extractRateLimitInfo,
15
- isRateLimitResponse,
16
- calculateBackoffDelay,
17
- type GitHubWorkSourceConfig,
18
- type GitHubIssue,
19
- type RateLimitInfo,
20
- type RateLimitWarningOptions,
21
- type RetryOptions,
22
- } from "./github.js";
23
-
24
- // =============================================================================
25
- // Re-export Adapters
26
- // =============================================================================
27
-
28
- export {
29
- GitHubWorkSourceAdapter,
30
- createGitHubAdapter,
31
- GitHubAPIError,
32
- GitHubAuthError,
33
- extractRateLimitInfo,
34
- isRateLimitResponse,
35
- calculateBackoffDelay,
36
- };
37
- export type {
38
- GitHubWorkSourceConfig,
39
- GitHubIssue,
40
- RateLimitInfo,
41
- RateLimitWarningOptions,
42
- RetryOptions,
43
- };
44
-
45
- // =============================================================================
46
- // Auto-registration of Built-in Adapters
47
- // =============================================================================
48
-
49
- /**
50
- * Register built-in adapters
51
- *
52
- * This function is called automatically when the module is imported.
53
- * It only registers adapters that haven't already been registered,
54
- * allowing tests to pre-register mocks before importing this module.
55
- */
56
- function registerBuiltInAdapters(): void {
57
- // Register GitHub adapter if not already registered
58
- if (!isWorkSourceRegistered("github")) {
59
- registerWorkSource("github", createGitHubAdapter);
60
- }
61
- }
62
-
63
- // Auto-register on module load
64
- registerBuiltInAdapters();
@@ -1,71 +0,0 @@
1
- /**
2
- * Error classes for work-sources module
3
- *
4
- * Provides typed errors with descriptive messages for work source operations.
5
- */
6
-
7
- // =============================================================================
8
- // Base Error Class
9
- // =============================================================================
10
-
11
- /**
12
- * Base error class for all work source errors
13
- */
14
- export class WorkSourceError extends Error {
15
- constructor(message: string, options?: { cause?: Error }) {
16
- super(message);
17
- this.name = "WorkSourceError";
18
- this.cause = options?.cause;
19
- }
20
- }
21
-
22
- // =============================================================================
23
- // Registry Errors
24
- // =============================================================================
25
-
26
- /**
27
- * Error thrown when attempting to get a work source adapter for an unregistered type
28
- *
29
- * This error indicates that no factory has been registered for the requested
30
- * work source type. Use `registerWorkSource()` to register a factory before
31
- * attempting to get an adapter.
32
- */
33
- export class UnknownWorkSourceError extends WorkSourceError {
34
- /** The work source type that was requested */
35
- public readonly sourceType: string;
36
- /** List of currently registered work source types */
37
- public readonly availableTypes: string[];
38
-
39
- constructor(
40
- sourceType: string,
41
- availableTypes: string[],
42
- options?: { cause?: Error }
43
- ) {
44
- const availableList =
45
- availableTypes.length > 0 ? availableTypes.join(", ") : "none";
46
- super(
47
- `Unknown work source type: "${sourceType}". Available types: ${availableList}`,
48
- options
49
- );
50
- this.name = "UnknownWorkSourceError";
51
- this.sourceType = sourceType;
52
- this.availableTypes = availableTypes;
53
- }
54
- }
55
-
56
- /**
57
- * Error thrown when attempting to register a work source type that is already registered
58
- */
59
- export class DuplicateWorkSourceError extends WorkSourceError {
60
- /** The work source type that was already registered */
61
- public readonly sourceType: string;
62
-
63
- constructor(sourceType: string, options?: { cause?: Error }) {
64
- super(
65
- `Work source type "${sourceType}" is already registered. Use a different type name or unregister the existing one first.`,
66
- options
67
- );
68
- this.name = "DuplicateWorkSourceError";
69
- this.sourceType = sourceType;
70
- }
71
- }
@@ -1,148 +0,0 @@
1
- /**
2
- * Work Sources Module
3
- *
4
- * Provides a common interface for fetching and managing work items
5
- * from various sources (GitHub Issues, Linear, etc.).
6
- *
7
- * All work source adapters implement the WorkSource interface to ensure
8
- * consistent behavior across different backends.
9
- *
10
- * The registry allows dynamic registration of adapter factories,
11
- * enabling extensibility without modifying core code.
12
- *
13
- * The WorkSourceManager interface defines the contract between work sources
14
- * and the scheduler/runner, allowing clean integration without coupling.
15
- */
16
-
17
- // Re-export all types
18
- export * from "./types.js";
19
-
20
- // Re-export errors
21
- export * from "./errors.js";
22
-
23
- // Re-export manager interface and types
24
- export type {
25
- WorkSourceManager,
26
- WorkSourceManagerFactory,
27
- GetNextWorkItemOptions,
28
- GetNextWorkItemResult,
29
- ReleaseWorkItemOptions,
30
- ReportOutcomeOptions,
31
- } from "./manager.js";
32
-
33
- // Re-export registry functions and types
34
- export {
35
- registerWorkSource,
36
- getWorkSource,
37
- getRegisteredTypes,
38
- isWorkSourceRegistered,
39
- unregisterWorkSource,
40
- clearWorkSourceRegistry,
41
- } from "./registry.js";
42
- export type { WorkSourceConfig, WorkSourceFactory } from "./registry.js";
43
-
44
- // Re-export built-in adapters (also triggers auto-registration)
45
- export * from "./adapters/index.js";
46
-
47
- // Import types for interface definition
48
- import type {
49
- WorkItem,
50
- FetchOptions,
51
- FetchResult,
52
- ClaimResult,
53
- WorkResult,
54
- ReleaseOptions,
55
- ReleaseResult,
56
- } from "./types.js";
57
-
58
- // =============================================================================
59
- // WorkSourceAdapter Interface
60
- // =============================================================================
61
-
62
- /**
63
- * Common interface for all work source adapters
64
- *
65
- * Work sources provide work items from external systems (GitHub, Linear, etc.)
66
- * and handle the lifecycle of claiming, completing, and releasing work.
67
- *
68
- * @example
69
- * ```typescript
70
- * const github = new GitHubWorkSourceAdapter({ owner: 'org', repo: 'repo' });
71
- *
72
- * // Fetch available work
73
- * const { items } = await github.fetchAvailableWork({ labels: ['agent-ready'] });
74
- *
75
- * // Claim a work item
76
- * const claim = await github.claimWork(items[0].id);
77
- * if (claim.success) {
78
- * // Do work...
79
- * await github.completeWork(items[0].id, { outcome: 'success', summary: 'Fixed the bug' });
80
- * }
81
- * ```
82
- */
83
- export interface WorkSourceAdapter {
84
- /**
85
- * The type identifier for this work source (e.g., 'github', 'linear')
86
- *
87
- * Used to prefix work item IDs and identify the source in logs/state.
88
- */
89
- readonly type: string;
90
-
91
- /**
92
- * Fetch available work items from the source
93
- *
94
- * Returns work items that match the specified filters and are available
95
- * to be claimed (not already in progress by another agent).
96
- *
97
- * @param options - Filtering and pagination options
98
- * @returns Promise resolving to fetched items with pagination info
99
- */
100
- fetchAvailableWork(options?: FetchOptions): Promise<FetchResult>;
101
-
102
- /**
103
- * Claim a work item for processing
104
- *
105
- * Marks the work item as in-progress in the external system to prevent
106
- * other agents from picking it up. The exact mechanism depends on the
107
- * source (e.g., adding a label, assigning to a bot user).
108
- *
109
- * @param workItemId - The ID of the work item to claim
110
- * @returns Promise resolving to the claim result
111
- */
112
- claimWork(workItemId: string): Promise<ClaimResult>;
113
-
114
- /**
115
- * Complete a work item with the given result
116
- *
117
- * Updates the external system to reflect completion (e.g., closing an issue,
118
- * adding a comment with the summary). The work item is released from claim.
119
- *
120
- * @param workItemId - The ID of the work item to complete
121
- * @param result - The outcome and details of the work
122
- * @returns Promise resolving when the completion is recorded
123
- */
124
- completeWork(workItemId: string, result: WorkResult): Promise<void>;
125
-
126
- /**
127
- * Release a claimed work item without completing it
128
- *
129
- * Returns the work item to available status so other agents can claim it.
130
- * Use this when an agent cannot complete the work (e.g., timeout, error).
131
- *
132
- * @param workItemId - The ID of the work item to release
133
- * @param options - Options for the release (reason, add comment, etc.)
134
- * @returns Promise resolving to the release result
135
- */
136
- releaseWork(workItemId: string, options?: ReleaseOptions): Promise<ReleaseResult>;
137
-
138
- /**
139
- * Get a specific work item by ID
140
- *
141
- * Fetches the current state of a work item from the source.
142
- * Returns undefined if the work item doesn't exist.
143
- *
144
- * @param workItemId - The ID of the work item to fetch
145
- * @returns Promise resolving to the work item or undefined
146
- */
147
- getWork(workItemId: string): Promise<WorkItem | undefined>;
148
- }
@@ -1,413 +0,0 @@
1
- /**
2
- * Work Source Manager Interface
3
- *
4
- * Defines the contract between work sources and the scheduler/runner.
5
- * The scheduler uses this interface to fetch work, report outcomes,
6
- * and manage work source instances per agent.
7
- *
8
- * This module defines ONLY the interface - no scheduler logic is implemented here.
9
- * The scheduler implementation will import and use this interface.
10
- *
11
- * @example Scheduler Usage Pattern
12
- * ```typescript
13
- * // The scheduler will use the manager like this:
14
- * const manager: WorkSourceManager = getWorkSourceManager();
15
- *
16
- * // 1. Get next available work for an agent
17
- * const workItem = await manager.getNextWorkItem(agent);
18
- * if (!workItem) {
19
- * // No work available, scheduler may check other agents or wait
20
- * return;
21
- * }
22
- *
23
- * // 2. Work item is already claimed by getNextWorkItem()
24
- * // Build prompt from work item and execute job
25
- * const prompt = buildPromptFromWorkItem(workItem);
26
- * const result = await executeJob({ agent, prompt, ... });
27
- *
28
- * // 3. Report outcome to update external system
29
- * await manager.reportOutcome(workItem.id, {
30
- * outcome: result.success ? 'success' : 'failure',
31
- * summary: result.summary ?? 'Job completed',
32
- * error: result.error?.message,
33
- * });
34
- * ```
35
- *
36
- * @example Error Handling Pattern
37
- * ```typescript
38
- * try {
39
- * const workItem = await manager.getNextWorkItem(agent);
40
- * // ... execute work ...
41
- * await manager.reportOutcome(workItem.id, { outcome: 'success', summary: '...' });
42
- * } catch (error) {
43
- * // On unexpected error, release the work item back to available pool
44
- * if (workItem) {
45
- * await manager.releaseWorkItem(workItem.id, `Unexpected error: ${error.message}`);
46
- * }
47
- * }
48
- * ```
49
- *
50
- * @example Multiple Agents Pattern
51
- * ```typescript
52
- * // Manager caches adapters per agent to avoid repeated instantiation
53
- * for (const agent of agents) {
54
- * // Each call uses cached adapter for the agent's work source
55
- * const workItem = await manager.getNextWorkItem(agent);
56
- * // ...
57
- * }
58
- * ```
59
- */
60
-
61
- import type { ResolvedAgent } from "../config/loader.js";
62
- import type {
63
- WorkItem,
64
- WorkResult,
65
- ClaimResult,
66
- ReleaseResult,
67
- ReleaseOptions,
68
- FetchOptions,
69
- } from "./types.js";
70
- import type { WorkSourceAdapter } from "./index.js";
71
-
72
- // =============================================================================
73
- // Manager Types
74
- // =============================================================================
75
-
76
- /**
77
- * Options for fetching the next work item
78
- *
79
- * Allows the scheduler to customize work item selection beyond
80
- * what's configured in the agent's work source.
81
- */
82
- export interface GetNextWorkItemOptions {
83
- /**
84
- * Additional labels to filter by (combined with agent's configured labels)
85
- */
86
- labels?: string[];
87
-
88
- /**
89
- * Whether to automatically claim the work item
90
- * Defaults to true - the scheduler typically wants to claim immediately
91
- */
92
- autoClaim?: boolean;
93
-
94
- /**
95
- * Custom fetch options to pass to the adapter
96
- * These override the default options for this specific fetch
97
- */
98
- fetchOptions?: Partial<FetchOptions>;
99
- }
100
-
101
- /**
102
- * Result of getting the next work item
103
- *
104
- * Includes both the work item (if found) and claim status (if autoClaim was true).
105
- * This allows the scheduler to handle various scenarios:
106
- * - No work available (item is null)
107
- * - Work found and claimed successfully
108
- * - Work found but claim failed (race condition with another agent)
109
- */
110
- export interface GetNextWorkItemResult {
111
- /**
112
- * The work item, or null if no work is available
113
- */
114
- item: WorkItem | null;
115
-
116
- /**
117
- * Whether the work item was claimed
118
- * Only relevant when autoClaim is true and item is not null
119
- */
120
- claimed: boolean;
121
-
122
- /**
123
- * Claim result details if claiming was attempted
124
- * Contains failure reason if claimed is false
125
- */
126
- claimResult?: ClaimResult;
127
- }
128
-
129
- /**
130
- * Options for releasing a work item
131
- */
132
- export interface ReleaseWorkItemOptions extends ReleaseOptions {
133
- /**
134
- * The agent that claimed the work item
135
- * Used to resolve the correct adapter for the release operation
136
- */
137
- agent: ResolvedAgent;
138
- }
139
-
140
- /**
141
- * Options for reporting work outcome
142
- */
143
- export interface ReportOutcomeOptions {
144
- /**
145
- * The agent that processed the work item
146
- * Used to resolve the correct adapter for the completion operation
147
- */
148
- agent: ResolvedAgent;
149
- }
150
-
151
- // =============================================================================
152
- // WorkSourceManager Interface
153
- // =============================================================================
154
-
155
- /**
156
- * Interface for managing work sources and coordinating with the scheduler
157
- *
158
- * The WorkSourceManager provides a high-level interface for the scheduler to:
159
- * 1. Fetch available work items for agents
160
- * 2. Claim work items to prevent race conditions
161
- * 3. Report outcomes after job completion
162
- * 4. Release work items on error/timeout
163
- *
164
- * The manager handles:
165
- * - Work source adapter instantiation and caching per agent
166
- * - Resolving work source configuration from agent configs
167
- * - Coordinating claim/release lifecycle
168
- *
169
- * Implementation Notes for Scheduler Authors:
170
- * - Call getNextWorkItem() with autoClaim=true (default) for atomic fetch+claim
171
- * - Always call reportOutcome() or releaseWorkItem() after processing
172
- * - The manager caches adapters, so repeated calls are efficient
173
- * - If an agent has no work_source configured, getNextWorkItem returns { item: null }
174
- *
175
- * @example Basic Scheduler Loop
176
- * ```typescript
177
- * async function processAgent(manager: WorkSourceManager, agent: ResolvedAgent) {
178
- * // Check if we can run more instances
179
- * if (activeJobs[agent.name] >= (agent.instances?.max_concurrent ?? 1)) {
180
- * return; // Already at capacity
181
- * }
182
- *
183
- * // Try to get work
184
- * const { item, claimed, claimResult } = await manager.getNextWorkItem(agent);
185
- *
186
- * if (!item) {
187
- * return; // No work available
188
- * }
189
- *
190
- * if (!claimed) {
191
- * // Someone else claimed it first (race condition)
192
- * console.log(`Work ${item.id} claimed by another agent: ${claimResult?.reason}`);
193
- * return;
194
- * }
195
- *
196
- * // Execute the job
197
- * try {
198
- * const result = await executeJob(agent, item);
199
- * await manager.reportOutcome(item.id, result, { agent });
200
- * } catch (error) {
201
- * await manager.releaseWorkItem(item.id, {
202
- * agent,
203
- * reason: error.message,
204
- * addComment: true,
205
- * });
206
- * }
207
- * }
208
- * ```
209
- */
210
- export interface WorkSourceManager {
211
- /**
212
- * Get the next available work item for an agent
213
- *
214
- * Fetches the highest priority available work item from the agent's
215
- * configured work source. By default, also claims the item atomically
216
- * to prevent race conditions with other agents.
217
- *
218
- * @param agent - The resolved agent configuration
219
- * @param options - Options for fetching and claiming
220
- * @returns Result containing the work item (if any) and claim status
221
- *
222
- * @remarks
223
- * - Returns { item: null, claimed: false } if agent has no work_source
224
- * - Returns { item: null, claimed: false } if no work is available
225
- * - With autoClaim=true, claimed=false means another agent claimed it first
226
- * - The scheduler should handle claim failures by retrying or moving on
227
- *
228
- * @example
229
- * ```typescript
230
- * const result = await manager.getNextWorkItem(agent);
231
- *
232
- * if (!result.item) {
233
- * console.log('No work available for agent:', agent.name);
234
- * return;
235
- * }
236
- *
237
- * if (!result.claimed) {
238
- * console.log('Work was claimed by another agent');
239
- * return;
240
- * }
241
- *
242
- * // Safe to process the work item
243
- * console.log('Processing:', result.item.title);
244
- * ```
245
- */
246
- getNextWorkItem(
247
- agent: ResolvedAgent,
248
- options?: GetNextWorkItemOptions
249
- ): Promise<GetNextWorkItemResult>;
250
-
251
- /**
252
- * Report the outcome of processing a work item
253
- *
254
- * Updates the external system (GitHub, Linear, etc.) with the job result.
255
- * This typically involves:
256
- * - Adding a comment with the summary
257
- * - Closing the issue/task if successful
258
- * - Removing in-progress labels
259
- * - Adding completion labels
260
- *
261
- * @param taskId - The work item ID (from WorkItem.id)
262
- * @param result - The outcome of the work
263
- * @param options - Options including the agent that processed the item
264
- *
265
- * @remarks
266
- * - Must be called after job completion (success or failure)
267
- * - For failures, use result.outcome='failure' and include result.error
268
- * - The external system behavior depends on the adapter implementation
269
- *
270
- * @example
271
- * ```typescript
272
- * // Success case
273
- * await manager.reportOutcome(
274
- * workItem.id,
275
- * {
276
- * outcome: 'success',
277
- * summary: 'Fixed the authentication bug',
278
- * details: 'Updated the JWT validation logic...',
279
- * artifacts: ['https://github.com/org/repo/pull/123'],
280
- * },
281
- * { agent }
282
- * );
283
- *
284
- * // Failure case
285
- * await manager.reportOutcome(
286
- * workItem.id,
287
- * {
288
- * outcome: 'failure',
289
- * summary: 'Unable to reproduce the issue',
290
- * error: 'Tests pass on all environments',
291
- * },
292
- * { agent }
293
- * );
294
- * ```
295
- */
296
- reportOutcome(
297
- taskId: string,
298
- result: WorkResult,
299
- options: ReportOutcomeOptions
300
- ): Promise<void>;
301
-
302
- /**
303
- * Release a claimed work item without completing it
304
- *
305
- * Returns the work item to the available pool so other agents can claim it.
306
- * Use this when:
307
- * - Job times out
308
- * - Unexpected error prevents completion
309
- * - Agent is shutting down mid-task
310
- * - Manual intervention is needed
311
- *
312
- * @param taskId - The work item ID (from WorkItem.id)
313
- * @param options - Release options including reason and agent
314
- * @returns Result indicating if the release was successful
315
- *
316
- * @remarks
317
- * - Always call this or reportOutcome after claiming work
318
- * - If addComment is true, posts a comment explaining the release
319
- * - The work item becomes available for other agents to claim
320
- *
321
- * @example
322
- * ```typescript
323
- * // On timeout
324
- * await manager.releaseWorkItem(workItem.id, {
325
- * agent,
326
- * reason: 'Job timed out after 30 minutes',
327
- * addComment: true,
328
- * });
329
- *
330
- * // On error
331
- * await manager.releaseWorkItem(workItem.id, {
332
- * agent,
333
- * reason: `Unexpected error: ${error.message}`,
334
- * addComment: true,
335
- * });
336
- * ```
337
- */
338
- releaseWorkItem(
339
- taskId: string,
340
- options: ReleaseWorkItemOptions
341
- ): Promise<ReleaseResult>;
342
-
343
- /**
344
- * Get the work source adapter for an agent
345
- *
346
- * Returns the cached adapter instance for the agent's work source,
347
- * or null if the agent has no work source configured.
348
- *
349
- * This is useful for:
350
- * - Direct adapter operations not covered by the manager
351
- * - Inspecting adapter state or configuration
352
- * - Testing and debugging
353
- *
354
- * @param agent - The resolved agent configuration
355
- * @returns The adapter instance or null
356
- *
357
- * @remarks
358
- * - Adapters are cached per agent (by agent name + work source type)
359
- * - Creating new adapters is cheap but caching improves consistency
360
- * - The adapter is created lazily on first access
361
- *
362
- * @example
363
- * ```typescript
364
- * const adapter = await manager.getAdapter(agent);
365
- *
366
- * if (!adapter) {
367
- * console.log('Agent has no work source configured');
368
- * return;
369
- * }
370
- *
371
- * // Direct adapter operations
372
- * const workItem = await adapter.getWork('github:12345');
373
- * ```
374
- */
375
- getAdapter(agent: ResolvedAgent): Promise<WorkSourceAdapter | null>;
376
-
377
- /**
378
- * Clear the adapter cache
379
- *
380
- * Removes all cached adapter instances. Use this when:
381
- * - Configuration has changed and adapters need to be recreated
382
- * - Testing requires fresh adapter instances
383
- * - Memory cleanup is needed
384
- *
385
- * @remarks
386
- * - Subsequent getAdapter/getNextWorkItem calls will create new adapters
387
- * - In-flight operations on old adapters are not affected
388
- * - Does not affect external system state
389
- */
390
- clearCache(): void;
391
- }
392
-
393
- // =============================================================================
394
- // Factory Function Type
395
- // =============================================================================
396
-
397
- /**
398
- * Factory function for creating WorkSourceManager instances
399
- *
400
- * The scheduler will use this to get a manager instance. The default
401
- * implementation is provided by the work-sources module, but this can
402
- * be customized for testing or advanced use cases.
403
- *
404
- * @example
405
- * ```typescript
406
- * // Default usage
407
- * const manager = createWorkSourceManager();
408
- *
409
- * // With custom options (future extension point)
410
- * const manager = createWorkSourceManager({ cache: customCache });
411
- * ```
412
- */
413
- export type WorkSourceManagerFactory = () => WorkSourceManager;