@neotx/core 0.1.0-alpha.21 → 0.1.0-alpha.22

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.
package/dist/index.d.ts CHANGED
@@ -132,6 +132,10 @@ declare const globalConfigSchema: z.ZodObject<{
132
132
  maxDurationMs: z.ZodDefault<z.ZodNumber>;
133
133
  dir: z.ZodDefault<z.ZodString>;
134
134
  }, z.core.$strip>>;
135
+ journal: z.ZodOptional<z.ZodDefault<z.ZodObject<{
136
+ maxCostJournalSizeBytes: z.ZodDefault<z.ZodNumber>;
137
+ maxEventJournalSizeBytes: z.ZodDefault<z.ZodNumber>;
138
+ }, z.core.$strip>>>;
135
139
  webhooks: z.ZodDefault<z.ZodArray<z.ZodObject<{
136
140
  url: z.ZodString;
137
141
  events: z.ZodOptional<z.ZodArray<z.ZodString>>;
@@ -206,6 +210,10 @@ declare const neoConfigSchema: z.ZodObject<{
206
210
  maxDurationMs: z.ZodDefault<z.ZodNumber>;
207
211
  dir: z.ZodDefault<z.ZodString>;
208
212
  }, z.core.$strip>>;
213
+ journal: z.ZodOptional<z.ZodDefault<z.ZodObject<{
214
+ maxCostJournalSizeBytes: z.ZodDefault<z.ZodNumber>;
215
+ maxEventJournalSizeBytes: z.ZodDefault<z.ZodNumber>;
216
+ }, z.core.$strip>>>;
209
217
  webhooks: z.ZodDefault<z.ZodArray<z.ZodObject<{
210
218
  url: z.ZodString;
211
219
  events: z.ZodOptional<z.ZodArray<z.ZodString>>;
@@ -451,6 +459,7 @@ interface ActiveSession {
451
459
  interface OrchestratorStatus {
452
460
  paused: boolean;
453
461
  activeSessions: ActiveSession[];
462
+ activeRunCount: number;
454
463
  queueDepth: number;
455
464
  costToday: number;
456
465
  budgetCapUsd: number;
@@ -699,8 +708,10 @@ declare class CostJournal {
699
708
  private readonly dir;
700
709
  private readonly dirCache;
701
710
  private dayCache;
711
+ private readonly maxFileSizeBytes;
702
712
  constructor(options: {
703
713
  dir: string;
714
+ maxFileSizeBytes?: number;
704
715
  });
705
716
  append(entry: CostEntry): Promise<void>;
706
717
  getDayTotal(date?: Date): Promise<number>;
@@ -731,8 +742,10 @@ declare class NeoEventEmitter {
731
742
  declare class EventJournal {
732
743
  private readonly dir;
733
744
  private readonly dirCache;
745
+ private readonly maxFileSizeBytes;
734
746
  constructor(options: {
735
747
  dir: string;
748
+ maxFileSizeBytes?: number;
736
749
  });
737
750
  append(event: NeoEvent): Promise<void>;
738
751
  }
@@ -836,9 +849,11 @@ declare function buildSandboxConfig(agent: ResolvedAgent, sessionPath?: string):
836
849
  * File per session. Uses `{ decision: "async" }` so it never blocks the chain.
837
850
  *
838
851
  * Call `flush()` to force-write remaining entries (e.g. on shutdown).
852
+ * Call `cleanup()` to stop the internal timer (e.g. on shutdown or before GC).
839
853
  */
840
854
  interface AuditLogMiddleware extends Middleware {
841
855
  flush: () => Promise<void>;
856
+ cleanup: () => void;
842
857
  }
843
858
  declare function auditLog(options: {
844
859
  dir: string;
@@ -925,6 +940,7 @@ declare class Orchestrator extends NeoEventEmitter {
925
940
  drain(): Promise<void>;
926
941
  get status(): OrchestratorStatus;
927
942
  get activeSessions(): ActiveSession[];
943
+ get activeRunCount(): number;
928
944
  start(): Promise<void>;
929
945
  shutdown(): Promise<void>;
930
946
  emit(event: NeoEvent): void;
@@ -1178,12 +1194,12 @@ declare const decisionSchema: z.ZodObject<{
1178
1194
  type: z.ZodDefault<z.ZodString>;
1179
1195
  source: z.ZodString;
1180
1196
  metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
1181
- createdAt: z.ZodString;
1182
- expiresAt: z.ZodOptional<z.ZodString>;
1197
+ createdAt: z.ZodCoercedString<unknown>;
1198
+ expiresAt: z.ZodOptional<z.ZodCoercedString<unknown>>;
1183
1199
  defaultAnswer: z.ZodOptional<z.ZodString>;
1184
- answeredAt: z.ZodOptional<z.ZodString>;
1200
+ answeredAt: z.ZodOptional<z.ZodCoercedString<unknown>>;
1185
1201
  answer: z.ZodOptional<z.ZodString>;
1186
- expiredAt: z.ZodOptional<z.ZodString>;
1202
+ expiredAt: z.ZodOptional<z.ZodCoercedString<unknown>>;
1187
1203
  }, z.core.$strip>;
1188
1204
  type DecisionOption = z.infer<typeof decisionOptionSchema>;
1189
1205
  type Decision = z.infer<typeof decisionSchema>;
@@ -1191,12 +1207,20 @@ type DecisionInput = Omit<Decision, "id" | "createdAt" | "answeredAt" | "answer"
1191
1207
  /**
1192
1208
  * JSONL-backed store for decisions.
1193
1209
  * Append-only with in-place updates for answers and expiration.
1210
+ * Uses an in-memory mutex to serialize write operations.
1194
1211
  */
1195
1212
  declare class DecisionStore {
1196
1213
  private readonly filePath;
1197
1214
  private readonly dir;
1198
1215
  private readonly dirCache;
1216
+ /** Promise-based mutex to serialize write operations */
1217
+ private writeLock;
1199
1218
  constructor(filePath: string);
1219
+ /**
1220
+ * Acquire the write lock and execute a callback.
1221
+ * Serializes all write operations to prevent race conditions.
1222
+ */
1223
+ private withWriteLock;
1200
1224
  /**
1201
1225
  * Create a new decision and persist it.
1202
1226
  * @returns The generated decision ID
@@ -1205,6 +1229,7 @@ declare class DecisionStore {
1205
1229
  /**
1206
1230
  * Answer a decision by ID.
1207
1231
  * Reads all entries, updates the matching one, and rewrites the file.
1232
+ * Uses a mutex to serialize concurrent calls and prevent race conditions.
1208
1233
  */
1209
1234
  answer(id: string, answer: string): Promise<void>;
1210
1235
  /**
@@ -1223,6 +1248,7 @@ declare class DecisionStore {
1223
1248
  /**
1224
1249
  * Auto-answer expired decisions with their defaultAnswer.
1225
1250
  * Decisions without defaultAnswer are marked as expired (expiredAt).
1251
+ * Uses a mutex to serialize concurrent calls and prevent race conditions.
1226
1252
  * @returns The decisions that were auto-answered or marked expired
1227
1253
  */
1228
1254
  expire(): Promise<Decision[]>;
@@ -1639,6 +1665,23 @@ declare class HeartbeatLoop {
1639
1665
  * Check if supervisor daily budget is exceeded.
1640
1666
  */
1641
1667
  private checkBudgetExceeded;
1668
+ /**
1669
+ * Process decision answers from inbox and expire old decisions.
1670
+ * Returns pending, answered, and expiry status for prompt context.
1671
+ */
1672
+ private processDecisions;
1673
+ /**
1674
+ * Gather event context: drain queue, fetch active runs, memories, and recent actions.
1675
+ */
1676
+ private gatherEventContext;
1677
+ /**
1678
+ * Handle post-SDK processing: mark events as processed, consolidate log buffer.
1679
+ */
1680
+ private handlePostSdkProcessing;
1681
+ /**
1682
+ * Emit completion webhook events: heartbeat completed and run completed events.
1683
+ */
1684
+ private emitCompletionEvents;
1642
1685
  /**
1643
1686
  * Handle skip logic for idle and active-work scenarios.
1644
1687
  * Uses IdleDetector to make skip decisions based on context.
@@ -1848,6 +1891,24 @@ declare class StatusReader {
1848
1891
  * Returns empty array if the activity file doesn't exist or is empty.
1849
1892
  */
1850
1893
  queryActivity(options?: ActivityQueryOptions): ActivityEntry[];
1894
+ /**
1895
+ * Count runs with status "running" from .neo/runs/.
1896
+ * Fails silently — returns 0 if the runs directory doesn't exist.
1897
+ */
1898
+ private countActiveRuns;
1899
+ /**
1900
+ * Collect all run JSON files from the runs directory tree.
1901
+ * Searches both top-level and repo subdirectories.
1902
+ */
1903
+ private collectRunFiles;
1904
+ /**
1905
+ * Check if a filename is a run file (JSON but not dispatch).
1906
+ */
1907
+ private isRunFile;
1908
+ /**
1909
+ * Check if a run file represents an active (running) run.
1910
+ */
1911
+ private isRunning;
1851
1912
  }
1852
1913
 
1853
1914
  interface WebhookServerOptions {