@a5c-ai/genty-runtime 5.1.1-staging.00ceebd28cf2

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 (221) hide show
  1. package/README.md +69 -0
  2. package/dist/apiResult.d.ts +19 -0
  3. package/dist/apiResult.d.ts.map +1 -0
  4. package/dist/apiResult.js +16 -0
  5. package/dist/background/state.d.ts +20 -0
  6. package/dist/background/state.d.ts.map +1 -0
  7. package/dist/background/state.js +52 -0
  8. package/dist/backgroundProcessRegistry.d.ts +124 -0
  9. package/dist/backgroundProcessRegistry.d.ts.map +1 -0
  10. package/dist/backgroundProcessRegistry.js +427 -0
  11. package/dist/cost/claudeCodeParser.d.ts +81 -0
  12. package/dist/cost/claudeCodeParser.d.ts.map +1 -0
  13. package/dist/cost/claudeCodeParser.js +232 -0
  14. package/dist/cost/collector.d.ts +42 -0
  15. package/dist/cost/collector.d.ts.map +1 -0
  16. package/dist/cost/collector.js +105 -0
  17. package/dist/cost/effectCost.d.ts +23 -0
  18. package/dist/cost/effectCost.d.ts.map +1 -0
  19. package/dist/cost/effectCost.js +26 -0
  20. package/dist/cost/index.d.ts +19 -0
  21. package/dist/cost/index.d.ts.map +1 -0
  22. package/dist/cost/index.js +39 -0
  23. package/dist/cost/journal.d.ts +40 -0
  24. package/dist/cost/journal.d.ts.map +1 -0
  25. package/dist/cost/journal.js +137 -0
  26. package/dist/cost/types.d.ts +164 -0
  27. package/dist/cost/types.d.ts.map +1 -0
  28. package/dist/cost/types.js +228 -0
  29. package/dist/daemon/automationExecutor.d.ts +16 -0
  30. package/dist/daemon/automationExecutor.d.ts.map +1 -0
  31. package/dist/daemon/automationExecutor.js +222 -0
  32. package/dist/daemon/config.d.ts +8 -0
  33. package/dist/daemon/config.d.ts.map +1 -0
  34. package/dist/daemon/config.js +245 -0
  35. package/dist/daemon/daemonLog.d.ts +30 -0
  36. package/dist/daemon/daemonLog.d.ts.map +1 -0
  37. package/dist/daemon/daemonLog.js +140 -0
  38. package/dist/daemon/durableQueue.d.ts +41 -0
  39. package/dist/daemon/durableQueue.d.ts.map +1 -0
  40. package/dist/daemon/durableQueue.js +183 -0
  41. package/dist/daemon/fileWatcher.d.ts +9 -0
  42. package/dist/daemon/fileWatcher.d.ts.map +1 -0
  43. package/dist/daemon/fileWatcher.js +144 -0
  44. package/dist/daemon/index.d.ts +15 -0
  45. package/dist/daemon/index.d.ts.map +1 -0
  46. package/dist/daemon/index.js +25 -0
  47. package/dist/daemon/lifecycle.d.ts +13 -0
  48. package/dist/daemon/lifecycle.d.ts.map +1 -0
  49. package/dist/daemon/lifecycle.js +320 -0
  50. package/dist/daemon/loop.d.ts +27 -0
  51. package/dist/daemon/loop.d.ts.map +1 -0
  52. package/dist/daemon/loop.js +387 -0
  53. package/dist/daemon/timerScheduler.d.ts +13 -0
  54. package/dist/daemon/timerScheduler.d.ts.map +1 -0
  55. package/dist/daemon/timerScheduler.js +212 -0
  56. package/dist/daemon/types.d.ts +122 -0
  57. package/dist/daemon/types.d.ts.map +1 -0
  58. package/dist/daemon/types.js +25 -0
  59. package/dist/daemon/webhookListener.d.ts +6 -0
  60. package/dist/daemon/webhookListener.d.ts.map +1 -0
  61. package/dist/daemon/webhookListener.js +132 -0
  62. package/dist/execution/index.d.ts +10 -0
  63. package/dist/execution/index.d.ts.map +1 -0
  64. package/dist/execution/index.js +20 -0
  65. package/dist/execution/modes/docker.d.ts +26 -0
  66. package/dist/execution/modes/docker.d.ts.map +1 -0
  67. package/dist/execution/modes/docker.js +183 -0
  68. package/dist/execution/modes/index.d.ts +10 -0
  69. package/dist/execution/modes/index.d.ts.map +1 -0
  70. package/dist/execution/modes/index.js +14 -0
  71. package/dist/execution/modes/kubernetes.d.ts +46 -0
  72. package/dist/execution/modes/kubernetes.d.ts.map +1 -0
  73. package/dist/execution/modes/kubernetes.js +334 -0
  74. package/dist/execution/modes/local.d.ts +23 -0
  75. package/dist/execution/modes/local.d.ts.map +1 -0
  76. package/dist/execution/modes/local.js +117 -0
  77. package/dist/execution/modes/ssh.d.ts +23 -0
  78. package/dist/execution/modes/ssh.d.ts.map +1 -0
  79. package/dist/execution/modes/ssh.js +144 -0
  80. package/dist/execution/policy.d.ts +15 -0
  81. package/dist/execution/policy.d.ts.map +1 -0
  82. package/dist/execution/policy.js +121 -0
  83. package/dist/execution/provider.d.ts +32 -0
  84. package/dist/execution/provider.d.ts.map +1 -0
  85. package/dist/execution/provider.js +90 -0
  86. package/dist/execution/types.d.ts +189 -0
  87. package/dist/execution/types.d.ts.map +1 -0
  88. package/dist/execution/types.js +9 -0
  89. package/dist/index.d.ts +12 -0
  90. package/dist/index.d.ts.map +1 -0
  91. package/dist/index.js +44 -0
  92. package/dist/observability/diagnostics.d.ts +25 -0
  93. package/dist/observability/diagnostics.d.ts.map +1 -0
  94. package/dist/observability/diagnostics.js +98 -0
  95. package/dist/observability/health.d.ts +19 -0
  96. package/dist/observability/health.d.ts.map +1 -0
  97. package/dist/observability/health.js +145 -0
  98. package/dist/observability/index.d.ts +7 -0
  99. package/dist/observability/index.d.ts.map +1 -0
  100. package/dist/observability/index.js +25 -0
  101. package/dist/observability/runStatus.d.ts +44 -0
  102. package/dist/observability/runStatus.d.ts.map +1 -0
  103. package/dist/observability/runStatus.js +169 -0
  104. package/dist/observability/timeline.d.ts +11 -0
  105. package/dist/observability/timeline.d.ts.map +1 -0
  106. package/dist/observability/timeline.js +176 -0
  107. package/dist/observability/types.d.ts +65 -0
  108. package/dist/observability/types.d.ts.map +1 -0
  109. package/dist/observability/types.js +8 -0
  110. package/dist/observability/webhooks.d.ts +68 -0
  111. package/dist/observability/webhooks.d.ts.map +1 -0
  112. package/dist/observability/webhooks.js +132 -0
  113. package/dist/resources/budget-tracker.d.ts +56 -0
  114. package/dist/resources/budget-tracker.d.ts.map +1 -0
  115. package/dist/resources/budget-tracker.js +131 -0
  116. package/dist/resources/concurrency-guard.d.ts +55 -0
  117. package/dist/resources/concurrency-guard.d.ts.map +1 -0
  118. package/dist/resources/concurrency-guard.js +132 -0
  119. package/dist/resources/index.d.ts +12 -0
  120. package/dist/resources/index.d.ts.map +1 -0
  121. package/dist/resources/index.js +20 -0
  122. package/dist/resources/manager.d.ts +52 -0
  123. package/dist/resources/manager.d.ts.map +1 -0
  124. package/dist/resources/manager.js +150 -0
  125. package/dist/resources/timeout-cascade.d.ts +56 -0
  126. package/dist/resources/timeout-cascade.d.ts.map +1 -0
  127. package/dist/resources/timeout-cascade.js +145 -0
  128. package/dist/resources/types.d.ts +130 -0
  129. package/dist/resources/types.d.ts.map +1 -0
  130. package/dist/resources/types.js +9 -0
  131. package/dist/rpc/index.d.ts +5 -0
  132. package/dist/rpc/index.d.ts.map +1 -0
  133. package/dist/rpc/index.js +7 -0
  134. package/dist/rpc/server.d.ts +13 -0
  135. package/dist/rpc/server.d.ts.map +1 -0
  136. package/dist/rpc/server.js +64 -0
  137. package/dist/rpc/server.test.d.ts +2 -0
  138. package/dist/rpc/server.test.d.ts.map +1 -0
  139. package/dist/rpc/server.test.js +35 -0
  140. package/dist/rpc/types.d.ts +23 -0
  141. package/dist/rpc/types.d.ts.map +1 -0
  142. package/dist/rpc/types.js +20 -0
  143. package/dist/session/context.d.ts +22 -0
  144. package/dist/session/context.d.ts.map +1 -0
  145. package/dist/session/context.js +113 -0
  146. package/dist/session/continuityState.d.ts +39 -0
  147. package/dist/session/continuityState.d.ts.map +1 -0
  148. package/dist/session/continuityState.js +164 -0
  149. package/dist/session/cost.d.ts +63 -0
  150. package/dist/session/cost.d.ts.map +1 -0
  151. package/dist/session/cost.js +194 -0
  152. package/dist/session/discovery.d.ts +22 -0
  153. package/dist/session/discovery.d.ts.map +1 -0
  154. package/dist/session/discovery.js +35 -0
  155. package/dist/session/export.d.ts +4 -0
  156. package/dist/session/export.d.ts.map +1 -0
  157. package/dist/session/export.js +56 -0
  158. package/dist/session/export.test.d.ts +2 -0
  159. package/dist/session/export.test.d.ts.map +1 -0
  160. package/dist/session/export.test.js +42 -0
  161. package/dist/session/history.d.ts +30 -0
  162. package/dist/session/history.d.ts.map +1 -0
  163. package/dist/session/history.js +143 -0
  164. package/dist/session/index.d.ts +20 -0
  165. package/dist/session/index.d.ts.map +1 -0
  166. package/dist/session/index.js +78 -0
  167. package/dist/session/memoryExtraction.d.ts +65 -0
  168. package/dist/session/memoryExtraction.d.ts.map +1 -0
  169. package/dist/session/memoryExtraction.js +201 -0
  170. package/dist/session/parse.d.ts +45 -0
  171. package/dist/session/parse.d.ts.map +1 -0
  172. package/dist/session/parse.js +170 -0
  173. package/dist/session/persistence.d.ts +46 -0
  174. package/dist/session/persistence.d.ts.map +1 -0
  175. package/dist/session/persistence.js +180 -0
  176. package/dist/session/rewind.d.ts +45 -0
  177. package/dist/session/rewind.d.ts.map +1 -0
  178. package/dist/session/rewind.js +68 -0
  179. package/dist/session/rewind.test.d.ts +2 -0
  180. package/dist/session/rewind.test.d.ts.map +1 -0
  181. package/dist/session/rewind.test.js +96 -0
  182. package/dist/session/tree.d.ts +29 -0
  183. package/dist/session/tree.d.ts.map +1 -0
  184. package/dist/session/tree.js +115 -0
  185. package/dist/session/tree.test.d.ts +2 -0
  186. package/dist/session/tree.test.d.ts.map +1 -0
  187. package/dist/session/tree.test.js +75 -0
  188. package/dist/session/types.d.ts +267 -0
  189. package/dist/session/types.d.ts.map +1 -0
  190. package/dist/session/types.js +45 -0
  191. package/dist/session/write.d.ts +61 -0
  192. package/dist/session/write.d.ts.map +1 -0
  193. package/dist/session/write.js +213 -0
  194. package/dist/shellInvocation.d.ts +6 -0
  195. package/dist/shellInvocation.d.ts.map +1 -0
  196. package/dist/shellInvocation.js +8 -0
  197. package/dist/shellInvocation.test.d.ts +2 -0
  198. package/dist/shellInvocation.test.d.ts.map +1 -0
  199. package/dist/shellInvocation.test.js +18 -0
  200. package/dist/telemetry/audit-log.d.ts +56 -0
  201. package/dist/telemetry/audit-log.d.ts.map +1 -0
  202. package/dist/telemetry/audit-log.js +59 -0
  203. package/dist/telemetry/exporters.d.ts +35 -0
  204. package/dist/telemetry/exporters.d.ts.map +1 -0
  205. package/dist/telemetry/exporters.js +141 -0
  206. package/dist/telemetry/index.d.ts +12 -0
  207. package/dist/telemetry/index.d.ts.map +1 -0
  208. package/dist/telemetry/index.js +25 -0
  209. package/dist/telemetry/provider.d.ts +57 -0
  210. package/dist/telemetry/provider.d.ts.map +1 -0
  211. package/dist/telemetry/provider.js +261 -0
  212. package/dist/telemetry/span-tree.d.ts +46 -0
  213. package/dist/telemetry/span-tree.d.ts.map +1 -0
  214. package/dist/telemetry/span-tree.js +93 -0
  215. package/dist/telemetry/traceContext.d.ts +10 -0
  216. package/dist/telemetry/traceContext.d.ts.map +1 -0
  217. package/dist/telemetry/traceContext.js +43 -0
  218. package/dist/telemetry/types.d.ts +109 -0
  219. package/dist/telemetry/types.d.ts.map +1 -0
  220. package/dist/telemetry/types.js +21 -0
  221. package/package.json +137 -0
@@ -0,0 +1,267 @@
1
+ /**
2
+ * Session state management types for babysitter orchestration.
3
+ * These types represent the state stored in markdown files with YAML frontmatter.
4
+ */
5
+ /**
6
+ * Session state stored in the state file's YAML frontmatter.
7
+ */
8
+ export interface SessionState {
9
+ /** Whether the session is currently active */
10
+ active: boolean;
11
+ /** Current iteration number (1-based) */
12
+ iteration: number;
13
+ /** Maximum allowed iterations (0 = unlimited) */
14
+ maxIterations: number;
15
+ /** The single currently-active run bound to this session (empty string if unbound) */
16
+ runId: string;
17
+ /** Historical audit trail of all run IDs ever bound to this session, chronological (GAP-SESSION-001) */
18
+ runIds: string[];
19
+ /** ISO timestamp when session started */
20
+ startedAt: string;
21
+ /** ISO timestamp of last iteration */
22
+ lastIterationAt: string;
23
+ /** Array of recent iteration durations in seconds (last 3) */
24
+ iterationTimes: number[];
25
+ /** Optional key-value metadata (e.g. external correlation IDs) */
26
+ metadata?: Record<string, string>;
27
+ }
28
+ /**
29
+ * Accumulated context shared across runs within a session (GAP-SESSION-001).
30
+ * Persisted as a JSON file alongside the session state file.
31
+ */
32
+ export interface SessionWorktreeContext {
33
+ /** Workspace or worktree path bound to the session. */
34
+ workspacePath: string;
35
+ /** More specific current path within the workspace, when known. */
36
+ currentPath?: string;
37
+ /** Materialization mode when the binding is known. */
38
+ mode?: "worktree" | "symlink";
39
+ /** Repo alias within a multi-repo workspace, when known. */
40
+ repoAlias?: string;
41
+ /** Branch bound to the worktree, when known. */
42
+ branch?: string | null;
43
+ }
44
+ export interface SessionContext {
45
+ /** Accumulated notes from across runs */
46
+ notes: string[];
47
+ /** Shared knowledge key-value pairs accumulated across runs */
48
+ sharedKnowledge: Record<string, string>;
49
+ /** Bound workspace/worktree metadata carried across runs when available. */
50
+ worktree?: SessionWorktreeContext;
51
+ }
52
+ /** A recorded decision made during a session. */
53
+ export interface SessionDecision {
54
+ /** ISO timestamp when the decision was recorded */
55
+ timestamp: string;
56
+ /** What was decided */
57
+ description: string;
58
+ /** Why it was decided */
59
+ rationale?: string;
60
+ /** Run in which this decision was made */
61
+ runId?: string;
62
+ }
63
+ /** Summary of a completed run within a session. */
64
+ export interface SessionRunSummary {
65
+ /** Run identifier */
66
+ runId: string;
67
+ /** Process that was executed */
68
+ processId: string;
69
+ /** Terminal status */
70
+ status: string;
71
+ /** ISO timestamp when the run started */
72
+ startedAt: string;
73
+ /** ISO timestamp when the run finished */
74
+ completedAt?: string;
75
+ /** Human-readable outcome */
76
+ outcome?: string;
77
+ /** Quality score (0-100) if available */
78
+ score?: number;
79
+ }
80
+ /** Point-in-time snapshot of session context. */
81
+ export interface SessionContextSnapshot {
82
+ /** ISO timestamp when the snapshot was taken */
83
+ timestamp: string;
84
+ /** Run during which this snapshot was taken */
85
+ runId?: string;
86
+ /** Arbitrary context data */
87
+ snapshot: Record<string, unknown>;
88
+ }
89
+ /**
90
+ * Rich session history: extends SessionContext with accumulated
91
+ * decisions, run summaries, and context snapshots (GAP-SESSION-002).
92
+ */
93
+ export interface SessionHistory extends SessionContext {
94
+ /** Accumulated decisions made during this session */
95
+ decisions: SessionDecision[];
96
+ /** Summaries of all runs that have executed in this session */
97
+ runSummaries: SessionRunSummary[];
98
+ /** Point-in-time context snapshots */
99
+ contextSnapshots: SessionContextSnapshot[];
100
+ }
101
+ /**
102
+ * Complete session file content including state and prompt.
103
+ */
104
+ export interface SessionFile {
105
+ /** Parsed YAML frontmatter state */
106
+ state: SessionState;
107
+ /** Prompt content (everything after the YAML frontmatter) */
108
+ prompt: string;
109
+ /** Path to the state file */
110
+ filePath: string;
111
+ }
112
+ /**
113
+ * Options for initializing a new session.
114
+ */
115
+ export interface SessionInitOptions {
116
+ /** Claude session ID */
117
+ sessionId: string;
118
+ /** Maximum iterations (default: 65000) */
119
+ maxIterations?: number;
120
+ /** Optional run ID if already known */
121
+ runId?: string;
122
+ /** Directory to store state files */
123
+ stateDir: string;
124
+ /** Initial prompt text */
125
+ prompt: string;
126
+ }
127
+ /**
128
+ * Options for associating a session with a run.
129
+ */
130
+ export interface SessionAssociateOptions {
131
+ /** Claude session ID */
132
+ sessionId: string;
133
+ /** Run ID to associate */
134
+ runId: string;
135
+ /** Directory containing state files */
136
+ stateDir: string;
137
+ }
138
+ /**
139
+ * Options for resuming an existing session.
140
+ */
141
+ export interface SessionResumeOptions {
142
+ /** Claude session ID */
143
+ sessionId: string;
144
+ /** Run ID to resume */
145
+ runId: string;
146
+ /** Maximum iterations (default: 65000) */
147
+ maxIterations?: number;
148
+ /** Directory to store state files */
149
+ stateDir: string;
150
+ /** Runs directory (default: ~/.a5c/runs, or <repo>/.a5c/runs when BABYSITTER_RUNS_SCOPE=repo) */
151
+ runsDir?: string;
152
+ }
153
+ /**
154
+ * Options for reading session state.
155
+ */
156
+ export interface SessionStateOptions {
157
+ /** Claude session ID */
158
+ sessionId: string;
159
+ /** Directory containing state files */
160
+ stateDir: string;
161
+ }
162
+ /**
163
+ * Options for updating session state.
164
+ */
165
+ export interface SessionUpdateOptions {
166
+ /** Claude session ID */
167
+ sessionId: string;
168
+ /** Directory containing state files */
169
+ stateDir: string;
170
+ /** New iteration number */
171
+ iteration?: number;
172
+ /** New last iteration timestamp */
173
+ lastIterationAt?: string;
174
+ /** New iteration times array */
175
+ iterationTimes?: number[];
176
+ }
177
+ /**
178
+ * Result of session:init command.
179
+ */
180
+ export interface SessionInitResult {
181
+ /** Path to created state file */
182
+ stateFile: string;
183
+ /** Initial iteration number */
184
+ iteration: number;
185
+ /** Maximum iterations */
186
+ maxIterations: number;
187
+ /** Run ID (may be empty) */
188
+ runId: string;
189
+ }
190
+ /**
191
+ * Result of session:associate command.
192
+ */
193
+ export interface SessionAssociateResult {
194
+ /** Path to updated state file */
195
+ stateFile: string;
196
+ /** Associated run ID */
197
+ runId: string;
198
+ }
199
+ /**
200
+ * Result of session:resume command.
201
+ */
202
+ export interface SessionResumeResult {
203
+ /** Path to created state file */
204
+ stateFile: string;
205
+ /** Run ID being resumed */
206
+ runId: string;
207
+ /** Current run state */
208
+ runState: string;
209
+ /** Process ID from run metadata */
210
+ processId: string;
211
+ }
212
+ /**
213
+ * Result of session:state command.
214
+ */
215
+ export interface SessionStateResult {
216
+ /** Whether state file exists */
217
+ found: boolean;
218
+ /** Session state (if found) */
219
+ state?: SessionState;
220
+ /** Prompt content (if found) */
221
+ prompt?: string;
222
+ /** Path to state file */
223
+ stateFile: string;
224
+ }
225
+ /**
226
+ * Result of session:update command.
227
+ */
228
+ export interface SessionUpdateResult {
229
+ /** Whether update was successful */
230
+ success: boolean;
231
+ /** Updated state */
232
+ state?: SessionState;
233
+ /** Path to state file */
234
+ stateFile: string;
235
+ }
236
+ /**
237
+ * Error thrown when session operations fail.
238
+ */
239
+ export declare class SessionError extends Error {
240
+ readonly code: SessionErrorCode;
241
+ readonly details?: Record<string, unknown> | undefined;
242
+ constructor(message: string, code: SessionErrorCode, details?: Record<string, unknown> | undefined);
243
+ }
244
+ /**
245
+ * Session error codes.
246
+ */
247
+ export declare enum SessionErrorCode {
248
+ /** Session ID not provided */
249
+ MISSING_SESSION_ID = "MISSING_SESSION_ID",
250
+ /** State file already exists */
251
+ SESSION_EXISTS = "SESSION_EXISTS",
252
+ /** State file not found */
253
+ SESSION_NOT_FOUND = "SESSION_NOT_FOUND",
254
+ /** Run already associated */
255
+ RUN_ALREADY_ASSOCIATED = "RUN_ALREADY_ASSOCIATED",
256
+ /** Run not found */
257
+ RUN_NOT_FOUND = "RUN_NOT_FOUND",
258
+ /** Run already completed */
259
+ RUN_COMPLETED = "RUN_COMPLETED",
260
+ /** State file corrupted */
261
+ CORRUPTED_STATE = "CORRUPTED_STATE",
262
+ /** Invalid state value */
263
+ INVALID_STATE_VALUE = "INVALID_STATE_VALUE",
264
+ /** File system error */
265
+ FS_ERROR = "FS_ERROR"
266
+ }
267
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/session/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,8CAA8C;IAC9C,MAAM,EAAE,OAAO,CAAC;IAChB,yCAAyC;IACzC,SAAS,EAAE,MAAM,CAAC;IAClB,iDAAiD;IACjD,aAAa,EAAE,MAAM,CAAC;IACtB,sFAAsF;IACtF,KAAK,EAAE,MAAM,CAAC;IACd,wGAAwG;IACxG,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,yCAAyC;IACzC,SAAS,EAAE,MAAM,CAAC;IAClB,sCAAsC;IACtC,eAAe,EAAE,MAAM,CAAC;IACxB,8DAA8D;IAC9D,cAAc,EAAE,MAAM,EAAE,CAAC;IACzB,kEAAkE;IAClE,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACnC;AAED;;;GAGG;AACH,MAAM,WAAW,sBAAsB;IACrC,uDAAuD;IACvD,aAAa,EAAE,MAAM,CAAC;IACtB,mEAAmE;IACnE,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,sDAAsD;IACtD,IAAI,CAAC,EAAE,UAAU,GAAG,SAAS,CAA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AAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,qBAAa,YAAa,SAAQ,KAAK;aAGnB,IAAI,EAAE,gBAAgB;aACtB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;gBAFjD,OAAO,EAAE,MAAM,EACC,IAAI,EAAE,gBAAgB,EACtB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,YAAA;CAKpD;AAED;;GAEG;AACH,oBAAY,gBAAgB;IAC1B,8BAA8B;IAC9B,kBAAkB,uBAAuB;IACzC,gCAAgC;IAChC,cAAc,mBAAmB;IACjC,2BAA2B;IAC3B,iBAAiB,sBAAsB;IACvC,6BAA6B;IAC7B,sBAAsB,2BAA2B;IACjD,oBAAoB;IACpB,aAAa,kBAAkB;IAC/B,4BAA4B;IAC5B,aAAa,kBAAkB;IAC/B,2BAA2B;IAC3B,eAAe,oBAAoB;IACnC,0BAA0B;IAC1B,mBAAmB,wBAAwB;IAC3C,wBAAwB;IACxB,QAAQ,aAAa;CACtB"}
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ /**
3
+ * Session state management types for babysitter orchestration.
4
+ * These types represent the state stored in markdown files with YAML frontmatter.
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.SessionErrorCode = exports.SessionError = void 0;
8
+ /**
9
+ * Error thrown when session operations fail.
10
+ */
11
+ class SessionError extends Error {
12
+ code;
13
+ details;
14
+ constructor(message, code, details) {
15
+ super(message);
16
+ this.code = code;
17
+ this.details = details;
18
+ this.name = 'SessionError';
19
+ }
20
+ }
21
+ exports.SessionError = SessionError;
22
+ /**
23
+ * Session error codes.
24
+ */
25
+ var SessionErrorCode;
26
+ (function (SessionErrorCode) {
27
+ /** Session ID not provided */
28
+ SessionErrorCode["MISSING_SESSION_ID"] = "MISSING_SESSION_ID";
29
+ /** State file already exists */
30
+ SessionErrorCode["SESSION_EXISTS"] = "SESSION_EXISTS";
31
+ /** State file not found */
32
+ SessionErrorCode["SESSION_NOT_FOUND"] = "SESSION_NOT_FOUND";
33
+ /** Run already associated */
34
+ SessionErrorCode["RUN_ALREADY_ASSOCIATED"] = "RUN_ALREADY_ASSOCIATED";
35
+ /** Run not found */
36
+ SessionErrorCode["RUN_NOT_FOUND"] = "RUN_NOT_FOUND";
37
+ /** Run already completed */
38
+ SessionErrorCode["RUN_COMPLETED"] = "RUN_COMPLETED";
39
+ /** State file corrupted */
40
+ SessionErrorCode["CORRUPTED_STATE"] = "CORRUPTED_STATE";
41
+ /** Invalid state value */
42
+ SessionErrorCode["INVALID_STATE_VALUE"] = "INVALID_STATE_VALUE";
43
+ /** File system error */
44
+ SessionErrorCode["FS_ERROR"] = "FS_ERROR";
45
+ })(SessionErrorCode || (exports.SessionErrorCode = SessionErrorCode = {}));
@@ -0,0 +1,61 @@
1
+ /**
2
+ * Session state file writing utilities.
3
+ * Provides atomic writes for session state files.
4
+ */
5
+ import type { SessionState } from './types';
6
+ /**
7
+ * Serialize session state to YAML frontmatter format.
8
+ */
9
+ export declare function serializeSessionState(state: SessionState): string;
10
+ /**
11
+ * Create full session file content with YAML frontmatter and prompt.
12
+ */
13
+ export declare function createSessionFileContent(state: SessionState, prompt: string): string;
14
+ /**
15
+ * Write session state file atomically.
16
+ * Uses temp file + rename pattern to ensure atomic writes.
17
+ */
18
+ export declare function writeSessionFile(filePath: string, state: SessionState, prompt: string): Promise<void>;
19
+ /**
20
+ * Update specific fields in an existing session state file.
21
+ * Reads, modifies, and atomically writes the file.
22
+ */
23
+ export declare function updateSessionState(filePath: string, updates: Partial<SessionState>, existingContent?: {
24
+ state: SessionState;
25
+ prompt: string;
26
+ }): Promise<SessionState>;
27
+ /**
28
+ * Bind a new run to the session, retiring the previous active run to history.
29
+ *
30
+ * Invariant: only one run is active at a time (`runId`).
31
+ * The previous `runId` (if any) is pushed into `runIds` as audit history.
32
+ * Idempotent: re-binding the same runId is a no-op.
33
+ *
34
+ * Throws if the caller tries to bind a new run while `runId` is still set
35
+ * and `retirePrevious` is not explicitly true — this forces callers to
36
+ * acknowledge that the prior run is done.
37
+ */
38
+ export declare function addRunToSession(state: SessionState, runId: string, options?: {
39
+ retirePrevious?: boolean;
40
+ }): SessionState;
41
+ /**
42
+ * Get the historical audit trail of all run IDs for this session (GAP-SESSION-001).
43
+ * Falls back to [runId] when runIds is empty for backward compatibility
44
+ * with sessions created before the runIds field existed.
45
+ */
46
+ export declare function getSessionRuns(state: SessionState): string[];
47
+ /**
48
+ * Get current ISO timestamp.
49
+ */
50
+ export declare function getCurrentTimestamp(): string;
51
+ /**
52
+ * Convert ISO timestamp to epoch seconds.
53
+ * Returns null if conversion fails.
54
+ */
55
+ export declare function isoToEpochSeconds(isoTimestamp: string): number | null;
56
+ /**
57
+ * Calculate iteration duration and update times array.
58
+ * Keeps only the last 10 durations for diagnostics.
59
+ */
60
+ export declare function updateIterationTimes(existingTimes: number[], lastIterationAt: string, currentTime: string): number[];
61
+ //# sourceMappingURL=write.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"write.d.ts","sourceRoot":"","sources":["../../src/session/write.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAG5C;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,YAAY,GAAG,MAAM,CAgBjE;AAED;;GAEG;AACH,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAGpF;AAED;;;GAGG;AACH,wBAAsB,gBAAgB,CACpC,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,YAAY,EACnB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,IAAI,CAAC,CA6Bf;AAED;;;GAGG;AACH,wBAAsB,kBAAkB,CACtC,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,OAAO,CAAC,YAAY,CAAC,EAC9B,eAAe,CAAC,EAAE;IAAE,KAAK,EAAE,YAAY,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GACxD,OAAO,CAAC,YAAY,CAAC,CAyBvB;AAGD;;;;;;;;;;GAUG;AACH,wBAAgB,eAAe,CAC7B,KAAK,EAAE,YAAY,EACnB,KAAK,EAAE,MAAM,EACb,OAAO,CAAC,EAAE;IAAE,cAAc,CAAC,EAAE,OAAO,CAAA;CAAE,GACrC,YAAY,CAyBd;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,YAAY,GAAG,MAAM,EAAE,CAG5D;AAED;;GAEG;AACH,wBAAgB,mBAAmB,IAAI,MAAM,CAE5C;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CASrE;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAClC,aAAa,EAAE,MAAM,EAAE,EACvB,eAAe,EAAE,MAAM,EACvB,WAAW,EAAE,MAAM,GAClB,MAAM,EAAE,CAgBV"}
@@ -0,0 +1,213 @@
1
+ "use strict";
2
+ /**
3
+ * Session state file writing utilities.
4
+ * Provides atomic writes for session state files.
5
+ */
6
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
7
+ if (k2 === undefined) k2 = k;
8
+ var desc = Object.getOwnPropertyDescriptor(m, k);
9
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
10
+ desc = { enumerable: true, get: function() { return m[k]; } };
11
+ }
12
+ Object.defineProperty(o, k2, desc);
13
+ }) : (function(o, m, k, k2) {
14
+ if (k2 === undefined) k2 = k;
15
+ o[k2] = m[k];
16
+ }));
17
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
18
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
19
+ }) : function(o, v) {
20
+ o["default"] = v;
21
+ });
22
+ var __importStar = (this && this.__importStar) || (function () {
23
+ var ownKeys = function(o) {
24
+ ownKeys = Object.getOwnPropertyNames || function (o) {
25
+ var ar = [];
26
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
27
+ return ar;
28
+ };
29
+ return ownKeys(o);
30
+ };
31
+ return function (mod) {
32
+ if (mod && mod.__esModule) return mod;
33
+ var result = {};
34
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
35
+ __setModuleDefault(result, mod);
36
+ return result;
37
+ };
38
+ })();
39
+ Object.defineProperty(exports, "__esModule", { value: true });
40
+ exports.serializeSessionState = serializeSessionState;
41
+ exports.createSessionFileContent = createSessionFileContent;
42
+ exports.writeSessionFile = writeSessionFile;
43
+ exports.updateSessionState = updateSessionState;
44
+ exports.addRunToSession = addRunToSession;
45
+ exports.getSessionRuns = getSessionRuns;
46
+ exports.getCurrentTimestamp = getCurrentTimestamp;
47
+ exports.isoToEpochSeconds = isoToEpochSeconds;
48
+ exports.updateIterationTimes = updateIterationTimes;
49
+ const node_fs_1 = require("node:fs");
50
+ const path = __importStar(require("node:path"));
51
+ const types_1 = require("./types");
52
+ /**
53
+ * Serialize session state to YAML frontmatter format.
54
+ */
55
+ function serializeSessionState(state) {
56
+ const lines = [];
57
+ lines.push(`active: ${state.active}`);
58
+ lines.push(`iteration: ${state.iteration}`);
59
+ lines.push(`max_iterations: ${state.maxIterations}`);
60
+ lines.push(`run_id: "${state.runId}"`);
61
+ lines.push(`run_ids: ${state.runIds.join(',')}`);
62
+ lines.push(`started_at: "${state.startedAt}"`);
63
+ lines.push(`last_iteration_at: "${state.lastIterationAt}"`);
64
+ lines.push(`iteration_times: ${state.iterationTimes.join(',')}`);
65
+ for (const [key, value] of Object.entries(state.metadata ?? {})) {
66
+ lines.push(`metadata_${key}: "${String(value).replace(/\\/g, '\\\\').replace(/"/g, '\\"')}"`);
67
+ }
68
+ return lines.join('\n');
69
+ }
70
+ /**
71
+ * Create full session file content with YAML frontmatter and prompt.
72
+ */
73
+ function createSessionFileContent(state, prompt) {
74
+ const frontmatter = serializeSessionState(state);
75
+ return `---\n${frontmatter}\n---\n\n${prompt}\n`;
76
+ }
77
+ /**
78
+ * Write session state file atomically.
79
+ * Uses temp file + rename pattern to ensure atomic writes.
80
+ */
81
+ async function writeSessionFile(filePath, state, prompt) {
82
+ const content = createSessionFileContent(state, prompt);
83
+ const dir = path.dirname(filePath);
84
+ const tempPath = `${filePath}.tmp.${process.pid}`;
85
+ try {
86
+ // Ensure directory exists
87
+ await node_fs_1.promises.mkdir(dir, { recursive: true });
88
+ // Write to temp file
89
+ await node_fs_1.promises.writeFile(tempPath, content, 'utf8');
90
+ // Atomic rename
91
+ await node_fs_1.promises.rename(tempPath, filePath);
92
+ }
93
+ catch (error) {
94
+ // Clean up temp file on error
95
+ try {
96
+ await node_fs_1.promises.unlink(tempPath);
97
+ }
98
+ catch {
99
+ // Ignore cleanup errors
100
+ }
101
+ const err = error;
102
+ throw new types_1.SessionError(`Failed to write session state file: ${err.message}`, types_1.SessionErrorCode.FS_ERROR, { filePath, originalError: err.message });
103
+ }
104
+ }
105
+ /**
106
+ * Update specific fields in an existing session state file.
107
+ * Reads, modifies, and atomically writes the file.
108
+ */
109
+ async function updateSessionState(filePath, updates, existingContent) {
110
+ let state;
111
+ let prompt;
112
+ if (existingContent) {
113
+ state = existingContent.state;
114
+ prompt = existingContent.prompt;
115
+ }
116
+ else {
117
+ // Read existing file
118
+ const { readSessionFile } = await Promise.resolve().then(() => __importStar(require('./parse')));
119
+ const file = await readSessionFile(filePath);
120
+ state = file.state;
121
+ prompt = file.prompt;
122
+ }
123
+ // Apply updates
124
+ const updatedState = {
125
+ ...state,
126
+ ...updates,
127
+ };
128
+ // Write updated file
129
+ await writeSessionFile(filePath, updatedState, prompt);
130
+ return updatedState;
131
+ }
132
+ /**
133
+ * Bind a new run to the session, retiring the previous active run to history.
134
+ *
135
+ * Invariant: only one run is active at a time (`runId`).
136
+ * The previous `runId` (if any) is pushed into `runIds` as audit history.
137
+ * Idempotent: re-binding the same runId is a no-op.
138
+ *
139
+ * Throws if the caller tries to bind a new run while `runId` is still set
140
+ * and `retirePrevious` is not explicitly true — this forces callers to
141
+ * acknowledge that the prior run is done.
142
+ */
143
+ function addRunToSession(state, runId, options) {
144
+ // Idempotent: already bound to this run
145
+ if (state.runId === runId)
146
+ return state;
147
+ // Guard: refuse to silently overwrite an active run
148
+ if (state.runId && !options?.retirePrevious) {
149
+ throw new types_1.SessionError(`Session already bound to run ${state.runId}. ` +
150
+ `Pass { retirePrevious: true } to retire it and bind ${runId}.`, types_1.SessionErrorCode.RUN_ALREADY_ASSOCIATED, { currentRunId: state.runId, requestedRunId: runId });
151
+ }
152
+ // Retire the old runId into history (if not already there)
153
+ const runIds = [...state.runIds];
154
+ if (state.runId && !runIds.includes(state.runId)) {
155
+ runIds.push(state.runId);
156
+ }
157
+ // Add the new one to the audit trail too
158
+ if (!runIds.includes(runId)) {
159
+ runIds.push(runId);
160
+ }
161
+ return { ...state, runId, runIds };
162
+ }
163
+ /**
164
+ * Get the historical audit trail of all run IDs for this session (GAP-SESSION-001).
165
+ * Falls back to [runId] when runIds is empty for backward compatibility
166
+ * with sessions created before the runIds field existed.
167
+ */
168
+ function getSessionRuns(state) {
169
+ if (state.runIds.length > 0)
170
+ return state.runIds;
171
+ return state.runId ? [state.runId] : [];
172
+ }
173
+ /**
174
+ * Get current ISO timestamp.
175
+ */
176
+ function getCurrentTimestamp() {
177
+ return new Date().toISOString().replace(/\.\d{3}Z$/, 'Z');
178
+ }
179
+ /**
180
+ * Convert ISO timestamp to epoch seconds.
181
+ * Returns null if conversion fails.
182
+ */
183
+ function isoToEpochSeconds(isoTimestamp) {
184
+ if (!isoTimestamp)
185
+ return null;
186
+ try {
187
+ const date = new Date(isoTimestamp);
188
+ if (Number.isNaN(date.getTime()))
189
+ return null;
190
+ return Math.floor(date.getTime() / 1000);
191
+ }
192
+ catch {
193
+ return null;
194
+ }
195
+ }
196
+ /**
197
+ * Calculate iteration duration and update times array.
198
+ * Keeps only the last 10 durations for diagnostics.
199
+ */
200
+ function updateIterationTimes(existingTimes, lastIterationAt, currentTime) {
201
+ const lastEpoch = isoToEpochSeconds(lastIterationAt);
202
+ const currentEpoch = isoToEpochSeconds(currentTime);
203
+ if (lastEpoch === null || currentEpoch === null) {
204
+ return existingTimes;
205
+ }
206
+ const duration = currentEpoch - lastEpoch;
207
+ if (duration <= 0) {
208
+ return existingTimes;
209
+ }
210
+ const newTimes = [...existingTimes, duration];
211
+ // Keep only last 10
212
+ return newTimes.slice(-10);
213
+ }
@@ -0,0 +1,6 @@
1
+ export interface ShellInvocation {
2
+ command: string;
3
+ args: string[];
4
+ }
5
+ export declare function buildShellInvocation(command: string, platform?: NodeJS.Platform): ShellInvocation;
6
+ //# sourceMappingURL=shellInvocation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shellInvocation.d.ts","sourceRoot":"","sources":["../src/shellInvocation.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,EAAE,CAAC;CAChB;AAED,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,MAAM,EACf,QAAQ,GAAE,MAAM,CAAC,QAA2B,GAC3C,eAAe,CAIjB"}
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildShellInvocation = buildShellInvocation;
4
+ function buildShellInvocation(command, platform = process.platform) {
5
+ return platform === "win32"
6
+ ? { command: "cmd.exe", args: ["/c", command] }
7
+ : { command: "/bin/bash", args: ["-c", command] };
8
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=shellInvocation.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shellInvocation.test.d.ts","sourceRoot":"","sources":["../src/shellInvocation.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const vitest_1 = require("vitest");
4
+ const shellInvocation_1 = require("./shellInvocation");
5
+ (0, vitest_1.describe)("buildShellInvocation", () => {
6
+ (0, vitest_1.it)("builds the Windows command shell argv contract", () => {
7
+ (0, vitest_1.expect)((0, shellInvocation_1.buildShellInvocation)("echo \"hello world\"", "win32")).toEqual({
8
+ command: "cmd.exe",
9
+ args: ["/c", "echo \"hello world\""],
10
+ });
11
+ });
12
+ (0, vitest_1.it)("builds the POSIX bash argv contract", () => {
13
+ (0, vitest_1.expect)((0, shellInvocation_1.buildShellInvocation)("printf '%s' \"$HOME\"", "linux")).toEqual({
14
+ command: "/bin/bash",
15
+ args: ["-c", "printf '%s' \"$HOME\""],
16
+ });
17
+ });
18
+ });