@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,120 +0,0 @@
1
- /**
2
- * Zod schemas for fleet state (state.yaml)
3
- *
4
- * Defines the schema for tracking fleet-wide state including agent status
5
- */
6
-
7
- import { z } from "zod";
8
-
9
- // =============================================================================
10
- // Schedule State Schemas
11
- // =============================================================================
12
-
13
- /**
14
- * Possible states for a schedule
15
- */
16
- export const ScheduleStatusSchema = z.enum(["idle", "running", "disabled"]);
17
-
18
- /**
19
- * State information for a single schedule
20
- */
21
- export const ScheduleStateSchema = z.object({
22
- /** ISO timestamp of when this schedule last ran */
23
- last_run_at: z.string().nullable().optional(),
24
- /** ISO timestamp of when this schedule will next run */
25
- next_run_at: z.string().nullable().optional(),
26
- /** Current status of the schedule */
27
- status: ScheduleStatusSchema.default("idle"),
28
- /** Last error message if the schedule encountered an error */
29
- last_error: z.string().nullable().optional(),
30
- });
31
-
32
- // =============================================================================
33
- // Agent Status Schemas
34
- // =============================================================================
35
-
36
- /**
37
- * Possible states for an agent
38
- */
39
- export const AgentStatusSchema = z.enum(["idle", "running", "error"]);
40
-
41
- /**
42
- * State information for a single agent
43
- */
44
- export const AgentStateSchema = z.object({
45
- /** Current status of the agent */
46
- status: AgentStatusSchema.default("idle"),
47
- /** ID of the currently running job, if any */
48
- current_job: z.string().nullable().optional(),
49
- /** ID of the last completed job */
50
- last_job: z.string().nullable().optional(),
51
- /** Name of the schedule that will trigger the next run */
52
- next_schedule: z.string().nullable().optional(),
53
- /** ISO timestamp of when the next scheduled run will occur */
54
- next_trigger_at: z.string().nullable().optional(),
55
- /** Docker container ID if running in container */
56
- container_id: z.string().nullable().optional(),
57
- /** Error message if status is 'error' */
58
- error_message: z.string().nullable().optional(),
59
- /** Map of schedule names to their state */
60
- schedules: z.record(z.string(), ScheduleStateSchema).optional(),
61
- });
62
-
63
- // =============================================================================
64
- // Fleet State Schemas
65
- // =============================================================================
66
-
67
- /**
68
- * Fleet metadata stored in state.yaml
69
- */
70
- export const FleetMetadataSchema = z.object({
71
- /** ISO timestamp of when the fleet was first started */
72
- started_at: z.string().optional(),
73
- });
74
-
75
- /**
76
- * Top-level fleet state schema (state.yaml)
77
- */
78
- export const FleetStateSchema = z.object({
79
- /** Fleet metadata */
80
- fleet: FleetMetadataSchema.optional().default({}),
81
- /** Map of agent names to their current state */
82
- agents: z.record(z.string(), AgentStateSchema).optional().default({}),
83
- });
84
-
85
- // =============================================================================
86
- // Type Exports
87
- // =============================================================================
88
-
89
- export type ScheduleStatus = z.infer<typeof ScheduleStatusSchema>;
90
- export type ScheduleState = z.infer<typeof ScheduleStateSchema>;
91
- export type AgentStatus = z.infer<typeof AgentStatusSchema>;
92
- export type AgentState = z.infer<typeof AgentStateSchema>;
93
- export type FleetMetadata = z.infer<typeof FleetMetadataSchema>;
94
- export type FleetState = z.infer<typeof FleetStateSchema>;
95
-
96
- // =============================================================================
97
- // Default State
98
- // =============================================================================
99
-
100
- /**
101
- * Create a new empty fleet state
102
- */
103
- export function createInitialFleetState(): FleetState {
104
- return {
105
- fleet: {},
106
- agents: {},
107
- };
108
- }
109
-
110
- /**
111
- * Create a default schedule state
112
- */
113
- export function createDefaultScheduleState(): ScheduleState {
114
- return {
115
- last_run_at: null,
116
- next_run_at: null,
117
- status: "idle",
118
- last_error: null,
119
- };
120
- }
@@ -1,67 +0,0 @@
1
- /**
2
- * State management schemas
3
- *
4
- * Re-exports all Zod schemas for state management
5
- */
6
-
7
- export {
8
- ScheduleStatusSchema,
9
- ScheduleStateSchema,
10
- AgentStatusSchema,
11
- AgentStateSchema,
12
- FleetMetadataSchema,
13
- FleetStateSchema,
14
- createInitialFleetState,
15
- createDefaultScheduleState,
16
- type ScheduleStatus,
17
- type ScheduleState,
18
- type AgentStatus,
19
- type AgentState,
20
- type FleetMetadata,
21
- type FleetState,
22
- } from "./fleet-state.js";
23
-
24
- export {
25
- JobStatusSchema,
26
- TriggerTypeSchema,
27
- ExitReasonSchema,
28
- JobMetadataSchema,
29
- generateJobId,
30
- createJobMetadata,
31
- type JobStatus,
32
- type TriggerType,
33
- type ExitReason,
34
- type JobMetadata,
35
- type CreateJobOptions,
36
- } from "./job-metadata.js";
37
-
38
- export {
39
- JobOutputTypeSchema,
40
- JobOutputBaseSchema,
41
- SystemMessageSchema,
42
- AssistantMessageSchema,
43
- ToolUseMessageSchema,
44
- ToolResultMessageSchema,
45
- ErrorMessageSchema,
46
- JobOutputMessageSchema,
47
- validateJobOutputMessage,
48
- isValidJobOutputInput,
49
- type JobOutputType,
50
- type JobOutputBase,
51
- type SystemMessage,
52
- type AssistantMessage,
53
- type ToolUseMessage,
54
- type ToolResultMessage,
55
- type ErrorMessage,
56
- type JobOutputMessage,
57
- type JobOutputInput,
58
- } from "./job-output.js";
59
-
60
- export {
61
- SessionModeSchema,
62
- SessionInfoSchema,
63
- createSessionInfo,
64
- type SessionMode,
65
- type SessionInfo,
66
- type CreateSessionOptions,
67
- } from "./session-info.js";
@@ -1,181 +0,0 @@
1
- /**
2
- * Zod schemas for job metadata (job-<id>.yaml)
3
- *
4
- * Defines the schema for tracking individual job execution metadata
5
- * including timing, status, and execution context.
6
- */
7
-
8
- import { z } from "zod";
9
-
10
- // =============================================================================
11
- // Job Status Schemas
12
- // =============================================================================
13
-
14
- /**
15
- * Possible states for a job
16
- */
17
- export const JobStatusSchema = z.enum([
18
- "pending",
19
- "running",
20
- "completed",
21
- "failed",
22
- "cancelled",
23
- ]);
24
-
25
- /**
26
- * How the job was triggered
27
- */
28
- export const TriggerTypeSchema = z.enum([
29
- "manual",
30
- "schedule",
31
- "webhook",
32
- "chat",
33
- "fork",
34
- ]);
35
-
36
- /**
37
- * Reason why a job exited
38
- */
39
- export const ExitReasonSchema = z.enum([
40
- "success",
41
- "error",
42
- "timeout",
43
- "cancelled",
44
- "max_turns",
45
- ]);
46
-
47
- // =============================================================================
48
- // Job Metadata Schema
49
- // =============================================================================
50
-
51
- /**
52
- * Job metadata schema for individual job files
53
- *
54
- * Each job is stored as .herdctl/jobs/job-<id>.yaml
55
- */
56
- export const JobMetadataSchema = z.object({
57
- /** Unique job identifier (format: job-YYYY-MM-DD-<random6>) */
58
- id: z.string().regex(/^job-\d{4}-\d{2}-\d{2}-[a-z0-9]{6}$/, {
59
- message: "Job ID must match format: job-YYYY-MM-DD-<random6>",
60
- }),
61
-
62
- /** Name of the agent that executed this job */
63
- agent: z.string().min(1),
64
-
65
- /** Schedule name that triggered the job (if applicable) */
66
- schedule: z.string().nullable().optional(),
67
-
68
- /** How the job was triggered */
69
- trigger_type: TriggerTypeSchema,
70
-
71
- /** Current status of the job */
72
- status: JobStatusSchema,
73
-
74
- /** Reason the job exited (only set when status is completed/failed/cancelled) */
75
- exit_reason: ExitReasonSchema.nullable().optional(),
76
-
77
- /** Session ID for the Claude agent session */
78
- session_id: z.string().nullable().optional(),
79
-
80
- /** Job ID this was forked from (if trigger_type is 'fork') */
81
- forked_from: z
82
- .string()
83
- .regex(/^job-\d{4}-\d{2}-\d{2}-[a-z0-9]{6}$/)
84
- .nullable()
85
- .optional(),
86
-
87
- /** ISO timestamp when the job started */
88
- started_at: z.string(),
89
-
90
- /** ISO timestamp when the job finished (null if still running) */
91
- finished_at: z.string().nullable().optional(),
92
-
93
- /** Duration of the job in seconds (calculated when finished) */
94
- duration_seconds: z.number().nonnegative().nullable().optional(),
95
-
96
- /** The prompt that was given to the agent */
97
- prompt: z.string().nullable().optional(),
98
-
99
- /** Brief summary of what the job accomplished */
100
- summary: z.string().nullable().optional(),
101
-
102
- /** Path to the output file containing full session output */
103
- output_file: z.string().nullable().optional(),
104
- });
105
-
106
- // =============================================================================
107
- // Type Exports
108
- // =============================================================================
109
-
110
- export type JobStatus = z.infer<typeof JobStatusSchema>;
111
- export type TriggerType = z.infer<typeof TriggerTypeSchema>;
112
- export type ExitReason = z.infer<typeof ExitReasonSchema>;
113
- export type JobMetadata = z.infer<typeof JobMetadataSchema>;
114
-
115
- // =============================================================================
116
- // Factory Functions
117
- // =============================================================================
118
-
119
- /**
120
- * Options for creating a new job
121
- */
122
- export interface CreateJobOptions {
123
- /** Name of the agent executing the job */
124
- agent: string;
125
- /** How the job was triggered */
126
- trigger_type: TriggerType;
127
- /** Schedule name (for scheduled jobs) */
128
- schedule?: string | null;
129
- /** The prompt given to the agent */
130
- prompt?: string | null;
131
- /** Parent job ID (for forked jobs) */
132
- forked_from?: string | null;
133
- }
134
-
135
- /**
136
- * Generate a unique job ID with format: job-YYYY-MM-DD-<random6>
137
- *
138
- * @param date - Optional date to use (defaults to now)
139
- * @param randomFn - Optional random function for testing
140
- */
141
- export function generateJobId(
142
- date: Date = new Date(),
143
- randomFn: () => string = () => Math.random().toString(36).slice(2, 8)
144
- ): string {
145
- const year = date.getFullYear();
146
- const month = String(date.getMonth() + 1).padStart(2, "0");
147
- const day = String(date.getDate()).padStart(2, "0");
148
- const random = randomFn().slice(0, 6).padEnd(6, "0");
149
-
150
- return `job-${year}-${month}-${day}-${random}`;
151
- }
152
-
153
- /**
154
- * Create initial job metadata for a new job
155
- *
156
- * @param options - Job creation options
157
- * @param idGenerator - Optional function to generate job ID (for testing)
158
- */
159
- export function createJobMetadata(
160
- options: CreateJobOptions,
161
- idGenerator: () => string = generateJobId
162
- ): JobMetadata {
163
- const now = new Date().toISOString();
164
-
165
- return {
166
- id: idGenerator(),
167
- agent: options.agent,
168
- schedule: options.schedule ?? null,
169
- trigger_type: options.trigger_type,
170
- status: "pending",
171
- exit_reason: null,
172
- session_id: null,
173
- forked_from: options.forked_from ?? null,
174
- started_at: now,
175
- finished_at: null,
176
- duration_seconds: null,
177
- prompt: options.prompt ?? null,
178
- summary: null,
179
- output_file: null,
180
- };
181
- }
@@ -1,177 +0,0 @@
1
- /**
2
- * Zod schemas for job output messages (job-<id>.jsonl)
3
- *
4
- * Defines the schema for streaming job output from Claude SDK.
5
- * Each line in the JSONL file is a JobOutputMessage.
6
- */
7
-
8
- import { z } from "zod";
9
-
10
- // =============================================================================
11
- // Message Type Schema
12
- // =============================================================================
13
-
14
- /**
15
- * Types of messages from Claude SDK streaming output
16
- */
17
- export const JobOutputTypeSchema = z.enum([
18
- "system",
19
- "assistant",
20
- "tool_use",
21
- "tool_result",
22
- "error",
23
- ]);
24
-
25
- // =============================================================================
26
- // Base Message Schema
27
- // =============================================================================
28
-
29
- /**
30
- * Base fields present in all job output messages
31
- */
32
- export const JobOutputBaseSchema = z.object({
33
- /** Message type */
34
- type: JobOutputTypeSchema,
35
- /** ISO timestamp when message was recorded */
36
- timestamp: z.string(),
37
- });
38
-
39
- // =============================================================================
40
- // Specific Message Type Schemas
41
- // =============================================================================
42
-
43
- /**
44
- * System message schema
45
- */
46
- export const SystemMessageSchema = JobOutputBaseSchema.extend({
47
- type: z.literal("system"),
48
- /** System message content */
49
- content: z.string().optional(),
50
- /** Optional subtype for system messages */
51
- subtype: z.string().optional(),
52
- });
53
-
54
- /**
55
- * Assistant message schema
56
- */
57
- export const AssistantMessageSchema = JobOutputBaseSchema.extend({
58
- type: z.literal("assistant"),
59
- /** Assistant response content */
60
- content: z.string().optional(),
61
- /** Whether this is a partial/streaming chunk */
62
- partial: z.boolean().optional(),
63
- /** Token usage info if available */
64
- usage: z
65
- .object({
66
- input_tokens: z.number().optional(),
67
- output_tokens: z.number().optional(),
68
- })
69
- .optional(),
70
- });
71
-
72
- /**
73
- * Tool use message schema
74
- */
75
- export const ToolUseMessageSchema = JobOutputBaseSchema.extend({
76
- type: z.literal("tool_use"),
77
- /** Tool being invoked */
78
- tool_name: z.string(),
79
- /** Unique identifier for this tool call */
80
- tool_use_id: z.string().optional(),
81
- /** Tool input parameters */
82
- input: z.unknown().optional(),
83
- });
84
-
85
- /**
86
- * Tool result message schema
87
- */
88
- export const ToolResultMessageSchema = JobOutputBaseSchema.extend({
89
- type: z.literal("tool_result"),
90
- /** ID of the tool call this is a result for */
91
- tool_use_id: z.string().optional(),
92
- /** Tool execution result */
93
- result: z.unknown().optional(),
94
- /** Whether the tool execution succeeded */
95
- success: z.boolean().optional(),
96
- /** Error message if tool failed */
97
- error: z.string().optional(),
98
- });
99
-
100
- /**
101
- * Error message schema
102
- */
103
- export const ErrorMessageSchema = JobOutputBaseSchema.extend({
104
- type: z.literal("error"),
105
- /** Error message */
106
- message: z.string(),
107
- /** Error code if available */
108
- code: z.string().optional(),
109
- /** Stack trace if available */
110
- stack: z.string().optional(),
111
- });
112
-
113
- // =============================================================================
114
- // Union Schema for All Message Types
115
- // =============================================================================
116
-
117
- /**
118
- * Schema that validates any job output message type
119
- */
120
- export const JobOutputMessageSchema = z.discriminatedUnion("type", [
121
- SystemMessageSchema,
122
- AssistantMessageSchema,
123
- ToolUseMessageSchema,
124
- ToolResultMessageSchema,
125
- ErrorMessageSchema,
126
- ]);
127
-
128
- // =============================================================================
129
- // Type Exports
130
- // =============================================================================
131
-
132
- export type JobOutputType = z.infer<typeof JobOutputTypeSchema>;
133
- export type JobOutputBase = z.infer<typeof JobOutputBaseSchema>;
134
- export type SystemMessage = z.infer<typeof SystemMessageSchema>;
135
- export type AssistantMessage = z.infer<typeof AssistantMessageSchema>;
136
- export type ToolUseMessage = z.infer<typeof ToolUseMessageSchema>;
137
- export type ToolResultMessage = z.infer<typeof ToolResultMessageSchema>;
138
- export type ErrorMessage = z.infer<typeof ErrorMessageSchema>;
139
- export type JobOutputMessage = z.infer<typeof JobOutputMessageSchema>;
140
-
141
- // =============================================================================
142
- // Input Types (without timestamp - added automatically)
143
- // =============================================================================
144
-
145
- /**
146
- * Input type for appending messages (timestamp added automatically)
147
- */
148
- export type JobOutputInput =
149
- | Omit<SystemMessage, "timestamp">
150
- | Omit<AssistantMessage, "timestamp">
151
- | Omit<ToolUseMessage, "timestamp">
152
- | Omit<ToolResultMessage, "timestamp">
153
- | Omit<ErrorMessage, "timestamp">;
154
-
155
- /**
156
- * Validate a job output message
157
- */
158
- export function validateJobOutputMessage(
159
- message: unknown
160
- ): JobOutputMessage | null {
161
- const result = JobOutputMessageSchema.safeParse(message);
162
- return result.success ? result.data : null;
163
- }
164
-
165
- /**
166
- * Check if a message has the minimum required fields
167
- */
168
- export function isValidJobOutputInput(input: unknown): input is JobOutputInput {
169
- if (typeof input !== "object" || input === null) {
170
- return false;
171
- }
172
- const obj = input as Record<string, unknown>;
173
- return (
174
- typeof obj.type === "string" &&
175
- JobOutputTypeSchema.safeParse(obj.type).success
176
- );
177
- }
@@ -1,92 +0,0 @@
1
- /**
2
- * Zod schemas for session info (sessions/<agent-name>.json)
3
- *
4
- * Defines the schema for tracking Claude session information per agent,
5
- * enabling session resume and fork capabilities.
6
- */
7
-
8
- import { z } from "zod";
9
-
10
- // =============================================================================
11
- // Session Mode Schema
12
- // =============================================================================
13
-
14
- /**
15
- * The operational mode of the session
16
- */
17
- export const SessionModeSchema = z.enum([
18
- "autonomous",
19
- "interactive",
20
- "review",
21
- ]);
22
-
23
- // =============================================================================
24
- // Session Info Schema
25
- // =============================================================================
26
-
27
- /**
28
- * Session info schema for individual agent session files
29
- *
30
- * Each session is stored as .herdctl/sessions/<agent-name>.json
31
- */
32
- export const SessionInfoSchema = z.object({
33
- /** Name of the agent this session belongs to */
34
- agent_name: z.string().min(1, "Agent name cannot be empty"),
35
-
36
- /** Claude session ID for resuming conversations */
37
- session_id: z.string().min(1, "Session ID cannot be empty"),
38
-
39
- /** ISO timestamp when the session was created */
40
- created_at: z.string().datetime({ message: "created_at must be a valid ISO datetime string" }),
41
-
42
- /** ISO timestamp when the session was last used */
43
- last_used_at: z.string().datetime({ message: "last_used_at must be a valid ISO datetime string" }),
44
-
45
- /** Number of jobs executed in this session */
46
- job_count: z.number().int().nonnegative(),
47
-
48
- /** Current operational mode of the session */
49
- mode: SessionModeSchema,
50
- });
51
-
52
- // =============================================================================
53
- // Type Exports
54
- // =============================================================================
55
-
56
- export type SessionMode = z.infer<typeof SessionModeSchema>;
57
- export type SessionInfo = z.infer<typeof SessionInfoSchema>;
58
-
59
- // =============================================================================
60
- // Factory Functions
61
- // =============================================================================
62
-
63
- /**
64
- * Options for creating a new session
65
- */
66
- export interface CreateSessionOptions {
67
- /** Name of the agent */
68
- agent_name: string;
69
- /** Claude session ID */
70
- session_id: string;
71
- /** Operational mode (defaults to 'autonomous') */
72
- mode?: SessionMode;
73
- }
74
-
75
- /**
76
- * Create initial session info for a new session
77
- *
78
- * @param options - Session creation options
79
- * @returns A validated SessionInfo object
80
- */
81
- export function createSessionInfo(options: CreateSessionOptions): SessionInfo {
82
- const now = new Date().toISOString();
83
-
84
- return {
85
- agent_name: options.agent_name,
86
- session_id: options.session_id,
87
- created_at: now,
88
- last_used_at: now,
89
- job_count: 0,
90
- mode: options.mode ?? "autonomous",
91
- };
92
- }