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

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
@@ -38,6 +38,7 @@ declare const agentConfigSchema: z.ZodObject<{
38
38
  name: z.ZodString;
39
39
  extends: z.ZodOptional<z.ZodString>;
40
40
  description: z.ZodOptional<z.ZodString>;
41
+ version: z.ZodOptional<z.ZodString>;
41
42
  model: z.ZodOptional<z.ZodEnum<{
42
43
  opus: "opus";
43
44
  sonnet: "sonnet";
@@ -62,7 +63,29 @@ declare const agentConfigSchema: z.ZodObject<{
62
63
  writable: "writable";
63
64
  }>>;
64
65
  maxTurns: z.ZodOptional<z.ZodNumber>;
66
+ maxCost: z.ZodOptional<z.ZodNumber>;
65
67
  mcpServers: z.ZodOptional<z.ZodArray<z.ZodString>>;
68
+ agents: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
69
+ description: z.ZodString;
70
+ prompt: z.ZodString;
71
+ tools: z.ZodOptional<z.ZodArray<z.ZodEnum<{
72
+ Read: "Read";
73
+ Write: "Write";
74
+ Edit: "Edit";
75
+ Bash: "Bash";
76
+ Glob: "Glob";
77
+ Grep: "Grep";
78
+ Agent: "Agent";
79
+ WebSearch: "WebSearch";
80
+ WebFetch: "WebFetch";
81
+ NotebookEdit: "NotebookEdit";
82
+ }>>>;
83
+ model: z.ZodOptional<z.ZodEnum<{
84
+ opus: "opus";
85
+ sonnet: "sonnet";
86
+ haiku: "haiku";
87
+ }>>;
88
+ }, z.core.$strip>>>;
66
89
  }, z.core.$strip>;
67
90
  type AgentConfig = z.infer<typeof agentConfigSchema>;
68
91
  type AgentModel = z.infer<typeof agentModelSchema>;
@@ -132,6 +155,10 @@ declare const globalConfigSchema: z.ZodObject<{
132
155
  maxDurationMs: z.ZodDefault<z.ZodNumber>;
133
156
  dir: z.ZodDefault<z.ZodString>;
134
157
  }, z.core.$strip>>;
158
+ journal: z.ZodOptional<z.ZodDefault<z.ZodObject<{
159
+ maxCostJournalSizeBytes: z.ZodDefault<z.ZodNumber>;
160
+ maxEventJournalSizeBytes: z.ZodDefault<z.ZodNumber>;
161
+ }, z.core.$strip>>>;
135
162
  webhooks: z.ZodDefault<z.ZodArray<z.ZodObject<{
136
163
  url: z.ZodString;
137
164
  events: z.ZodOptional<z.ZodArray<z.ZodString>>;
@@ -206,6 +233,10 @@ declare const neoConfigSchema: z.ZodObject<{
206
233
  maxDurationMs: z.ZodDefault<z.ZodNumber>;
207
234
  dir: z.ZodDefault<z.ZodString>;
208
235
  }, z.core.$strip>>;
236
+ journal: z.ZodOptional<z.ZodDefault<z.ZodObject<{
237
+ maxCostJournalSizeBytes: z.ZodDefault<z.ZodNumber>;
238
+ maxEventJournalSizeBytes: z.ZodDefault<z.ZodNumber>;
239
+ }, z.core.$strip>>>;
209
240
  webhooks: z.ZodDefault<z.ZodArray<z.ZodObject<{
210
241
  url: z.ZodString;
211
242
  events: z.ZodOptional<z.ZodArray<z.ZodString>>;
@@ -360,18 +391,31 @@ declare function removeRepoFromGlobalConfig(pathOrName: string): Promise<boolean
360
391
  */
361
392
  declare function listReposFromGlobalConfig(): Promise<RepoConfig[]>;
362
393
 
394
+ interface SubagentDefinition {
395
+ description: string;
396
+ prompt: string;
397
+ tools?: string[] | undefined;
398
+ model?: string | undefined;
399
+ }
363
400
  interface AgentDefinition {
364
401
  description: string;
365
402
  prompt: string;
366
403
  tools: string[];
367
404
  model: string;
368
405
  mcpServers?: string[] | undefined;
406
+ agents?: Record<string, SubagentDefinition> | undefined;
369
407
  }
370
408
  interface ResolvedAgent {
371
409
  name: string;
372
410
  definition: AgentDefinition;
373
411
  sandbox: "writable" | "readonly";
374
412
  maxTurns?: number | undefined;
413
+ /**
414
+ * Maximum cost in USD for this agent session.
415
+ * Checked post-session; if session cost >= maxCost, budget_exceeded error is thrown.
416
+ */
417
+ maxCost?: number | undefined;
418
+ version?: string | undefined;
375
419
  source: "built-in" | "custom" | "extended";
376
420
  }
377
421
  interface PersistedRun {
@@ -451,6 +495,7 @@ interface ActiveSession {
451
495
  interface OrchestratorStatus {
452
496
  paused: boolean;
453
497
  activeSessions: ActiveSession[];
498
+ activeRunCount: number;
454
499
  queueDepth: number;
455
500
  costToday: number;
456
501
  budgetCapUsd: number;
@@ -699,8 +744,10 @@ declare class CostJournal {
699
744
  private readonly dir;
700
745
  private readonly dirCache;
701
746
  private dayCache;
747
+ private readonly maxFileSizeBytes;
702
748
  constructor(options: {
703
749
  dir: string;
750
+ maxFileSizeBytes?: number;
704
751
  });
705
752
  append(entry: CostEntry): Promise<void>;
706
753
  getDayTotal(date?: Date): Promise<number>;
@@ -731,8 +778,10 @@ declare class NeoEventEmitter {
731
778
  declare class EventJournal {
732
779
  private readonly dir;
733
780
  private readonly dirCache;
781
+ private readonly maxFileSizeBytes;
734
782
  constructor(options: {
735
783
  dir: string;
784
+ maxFileSizeBytes?: number;
736
785
  });
737
786
  append(event: NeoEvent): Promise<void>;
738
787
  }
@@ -836,9 +885,11 @@ declare function buildSandboxConfig(agent: ResolvedAgent, sessionPath?: string):
836
885
  * File per session. Uses `{ decision: "async" }` so it never blocks the chain.
837
886
  *
838
887
  * Call `flush()` to force-write remaining entries (e.g. on shutdown).
888
+ * Call `cleanup()` to stop the internal timer (e.g. on shutdown or before GC).
839
889
  */
840
890
  interface AuditLogMiddleware extends Middleware {
841
891
  flush: () => Promise<void>;
892
+ cleanup: () => void;
842
893
  }
843
894
  declare function auditLog(options: {
844
895
  dir: string;
@@ -925,6 +976,7 @@ declare class Orchestrator extends NeoEventEmitter {
925
976
  drain(): Promise<void>;
926
977
  get status(): OrchestratorStatus;
927
978
  get activeSessions(): ActiveSession[];
979
+ get activeRunCount(): number;
928
980
  start(): Promise<void>;
929
981
  shutdown(): Promise<void>;
930
982
  emit(event: NeoEvent): void;
@@ -1042,7 +1094,9 @@ interface SessionOptions {
1042
1094
  env?: Record<string, string>;
1043
1095
  initTimeoutMs: number;
1044
1096
  maxDurationMs: number;
1097
+ maxTurns?: number | undefined;
1045
1098
  resumeSessionId?: string | undefined;
1099
+ agents?: Record<string, unknown> | undefined;
1046
1100
  onEvent?: ((event: SessionEvent) => void) | undefined;
1047
1101
  }
1048
1102
  interface SessionResult {
@@ -1178,12 +1232,12 @@ declare const decisionSchema: z.ZodObject<{
1178
1232
  type: z.ZodDefault<z.ZodString>;
1179
1233
  source: z.ZodString;
1180
1234
  metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
1181
- createdAt: z.ZodString;
1182
- expiresAt: z.ZodOptional<z.ZodString>;
1235
+ createdAt: z.ZodCoercedString<unknown>;
1236
+ expiresAt: z.ZodOptional<z.ZodCoercedString<unknown>>;
1183
1237
  defaultAnswer: z.ZodOptional<z.ZodString>;
1184
- answeredAt: z.ZodOptional<z.ZodString>;
1238
+ answeredAt: z.ZodOptional<z.ZodCoercedString<unknown>>;
1185
1239
  answer: z.ZodOptional<z.ZodString>;
1186
- expiredAt: z.ZodOptional<z.ZodString>;
1240
+ expiredAt: z.ZodOptional<z.ZodCoercedString<unknown>>;
1187
1241
  }, z.core.$strip>;
1188
1242
  type DecisionOption = z.infer<typeof decisionOptionSchema>;
1189
1243
  type Decision = z.infer<typeof decisionSchema>;
@@ -1191,12 +1245,32 @@ type DecisionInput = Omit<Decision, "id" | "createdAt" | "answeredAt" | "answer"
1191
1245
  /**
1192
1246
  * JSONL-backed store for decisions.
1193
1247
  * Append-only with in-place updates for answers and expiration.
1248
+ * Uses an in-memory mutex to serialize write operations.
1249
+ *
1250
+ * Compaction Strategy:
1251
+ * - Threshold-based compaction triggers on either:
1252
+ * 1. Tombstone ratio exceeds 30% of total valid entries (tombstones / (valid decisions + tombstones), excluding malformed lines)
1253
+ * 2. File size exceeds 10MB (prevents unbounded growth)
1254
+ * - Compaction rebuilds the file, filtering out tombstoned entries and preserving active decisions
1255
+ * - In-memory index maintains O(1) lookup without full file scans
1256
+ * - Compaction runs synchronously within the write lock to maintain consistency
1257
+ * - During compaction: all write operations are blocked until compaction completes, preventing race conditions
1258
+ * - Concurrent reads during compaction may return stale data from before compaction started
1194
1259
  */
1195
1260
  declare class DecisionStore {
1196
1261
  private readonly filePath;
1197
1262
  private readonly dir;
1198
1263
  private readonly dirCache;
1264
+ /** Promise-based mutex to serialize write operations */
1265
+ private writeLock;
1266
+ /** Maximum file size in bytes before validation fails (default: 10MB) */
1267
+ private readonly maxFileSizeBytes;
1199
1268
  constructor(filePath: string);
1269
+ /**
1270
+ * Acquire the write lock and execute a callback.
1271
+ * Serializes all write operations to prevent race conditions.
1272
+ */
1273
+ private withWriteLock;
1200
1274
  /**
1201
1275
  * Create a new decision and persist it.
1202
1276
  * @returns The generated decision ID
@@ -1205,6 +1279,7 @@ declare class DecisionStore {
1205
1279
  /**
1206
1280
  * Answer a decision by ID.
1207
1281
  * Reads all entries, updates the matching one, and rewrites the file.
1282
+ * Uses a mutex to serialize concurrent calls and prevent race conditions.
1208
1283
  */
1209
1284
  answer(id: string, answer: string): Promise<void>;
1210
1285
  /**
@@ -1223,6 +1298,7 @@ declare class DecisionStore {
1223
1298
  /**
1224
1299
  * Auto-answer expired decisions with their defaultAnswer.
1225
1300
  * Decisions without defaultAnswer are marked as expired (expiredAt).
1301
+ * Uses a mutex to serialize concurrent calls and prevent race conditions.
1226
1302
  * @returns The decisions that were auto-answered or marked expired
1227
1303
  */
1228
1304
  expire(): Promise<Decision[]>;
@@ -1288,9 +1364,9 @@ declare const activityEntrySchema: z.ZodObject<{
1288
1364
  message: "message";
1289
1365
  decision: "decision";
1290
1366
  tool_use: "tool_use";
1367
+ action: "action";
1291
1368
  event: "event";
1292
1369
  heartbeat: "heartbeat";
1293
- action: "action";
1294
1370
  warning: "warning";
1295
1371
  thinking: "thinking";
1296
1372
  plan: "plan";
@@ -1353,8 +1429,8 @@ declare const activityQueryOptionsSchema: z.ZodObject<{
1353
1429
  error: "error";
1354
1430
  message: "message";
1355
1431
  decision: "decision";
1356
- event: "event";
1357
1432
  action: "action";
1433
+ event: "event";
1358
1434
  plan: "plan";
1359
1435
  dispatch: "dispatch";
1360
1436
  }>>;
@@ -1639,6 +1715,23 @@ declare class HeartbeatLoop {
1639
1715
  * Check if supervisor daily budget is exceeded.
1640
1716
  */
1641
1717
  private checkBudgetExceeded;
1718
+ /**
1719
+ * Process decision answers from inbox and expire old decisions.
1720
+ * Returns pending, answered, and expiry status for prompt context.
1721
+ */
1722
+ private processDecisions;
1723
+ /**
1724
+ * Gather event context: drain queue, fetch active runs, memories, and recent actions.
1725
+ */
1726
+ private gatherEventContext;
1727
+ /**
1728
+ * Handle post-SDK processing: mark events as processed, consolidate log buffer.
1729
+ */
1730
+ private handlePostSdkProcessing;
1731
+ /**
1732
+ * Emit completion webhook events: heartbeat completed and run completed events.
1733
+ */
1734
+ private emitCompletionEvents;
1642
1735
  /**
1643
1736
  * Handle skip logic for idle and active-work scenarios.
1644
1737
  * Uses IdleDetector to make skip decisions based on context.
@@ -1848,6 +1941,24 @@ declare class StatusReader {
1848
1941
  * Returns empty array if the activity file doesn't exist or is empty.
1849
1942
  */
1850
1943
  queryActivity(options?: ActivityQueryOptions): ActivityEntry[];
1944
+ /**
1945
+ * Count runs with status "running" from .neo/runs/.
1946
+ * Fails silently — returns 0 if the runs directory doesn't exist.
1947
+ */
1948
+ private countActiveRuns;
1949
+ /**
1950
+ * Collect all run JSON files from the runs directory tree.
1951
+ * Searches both top-level and repo subdirectories.
1952
+ */
1953
+ private collectRunFiles;
1954
+ /**
1955
+ * Check if a filename is a run file (JSON but not dispatch).
1956
+ */
1957
+ private isRunFile;
1958
+ /**
1959
+ * Check if a run file represents an active (running) run.
1960
+ */
1961
+ private isRunning;
1851
1962
  }
1852
1963
 
1853
1964
  interface WebhookServerOptions {
@@ -1927,4 +2038,4 @@ declare function testWebhooks(): Promise<WebhookTestResult[]>;
1927
2038
 
1928
2039
  declare const VERSION = "0.1.0";
1929
2040
 
1930
- export { type ActiveSession, type ActivityEntry, ActivityLog, type ActivityQueryOptions, type AgentConfig, type AgentDefinition, type AgentMessageEvent, type AgentModel, AgentRegistry, type AgentTool, type AgentToolEntry, type AgentToolUseEvent, type AuditLogMiddleware, type BudgetAlertEvent, ConfigStore, type CostEntry, CostJournal, type CostUpdateEvent, type Decision, type DecisionInput, type DecisionOption, DecisionStore, type DispatchInput, type Embedder, EventJournal, EventQueue, type GateWaitingEvent, type GitStrategy, type GlobalConfig, HeartbeatLoop, type HeartbeatLoopOptions, type HookEvent, type InboxMessage, LocalEmbedder, type LoopDetectionMiddleware, type McpServerConfig, type MemoryEntry, type MemoryQuery, type MemoryStats, MemoryStore, type MemoryType, type MemoryWriteInput, type Middleware, type MiddlewareChain, type MiddlewareContext, type MiddlewareContextMap, type MiddlewareEvent, type MiddlewareHandler, type MiddlewareResult, type NeoConfig, type NeoEvent, NeoEventEmitter, Orchestrator, type OrchestratorOptions, type OrchestratorShutdownEvent, type OrchestratorStatus, type ParsedOutput, type PersistedRun, type Priority, type QueueDequeueEvent, type QueueEnqueueEvent, type QueuedEvent, type RecoveryOptions, type RepoConfig, type RepoConfigInput, type ResolvedAgent, type RunContext, type SDKHooks, type SandboxConfig, Semaphore, type SemaphoreCallbacks, type SemaphoreConfig, type SessionCloneInfo, type SessionCompleteEvent, SessionError, type SessionEvent, type SessionExecutionConfig, type SessionExecutionDeps, type SessionExecutionInput, type SessionExecutionResult, SessionExecutor, type SessionFailEvent, type SessionOptions, type SessionResult, type SessionStartEvent, StatusReader, type StepCompleteEvent, type StepResult, type StepStartEvent, SupervisorDaemon, type SupervisorDaemonOptions, type SupervisorDaemonState, type SupervisorDaemonState as SupervisorState, type SupervisorStatus, type TaskResult, VERSION, WebhookDispatcher, type WebhookEntry, type WebhookEntryInput, type WebhookIncomingEvent, WebhookServer, type WebhookTestPayload, type WebhookTestResult, activityEntrySchema, addRepoToGlobalConfig, addWebhook, agentConfigSchema, agentModelSchema, agentSandboxSchema, agentToolEntrySchema, agentToolSchema, appendLogBuffer, auditLog, budgetGuard, buildFullPrompt, buildGitStrategyInstructions, buildMiddlewareChain, buildReportingInstructions, buildSDKHooks, buildSandboxConfig, createBranch, createSessionClone, decisionOptionSchema, decisionSchema, deleteBranch, fetchRemote, getBranchName, getCurrentBranch, getDataDir, getJournalsDir, getRepoRunsDir, getRunDispatchPath, getRunLogPath, getRunsDir, getSupervisorActivityPath, getSupervisorDecisionsPath, getSupervisorDir, getSupervisorEventsPath, getSupervisorInboxPath, getSupervisorLockPath, getSupervisorStatePath, getSupervisorsDir, globalConfigSchema, inboxMessageSchema, isProcessAlive, listReposFromGlobalConfig, listSessionClones, listWebhooks, loadAgentFile, loadConfig, loadGlobalConfig, loadRepoInstructions, loopDetection, matchesFilter, mcpServerConfigSchema, neoConfigSchema, parseOutput, pushBranch, pushSessionBranch, removeRepoFromGlobalConfig, removeSessionClone, removeWebhook, repoConfigSchema, repoOverrideConfigSchema, resolveAgent, runSession, runWithRecovery, supervisorDaemonStateSchema, supervisorDaemonStateSchema as supervisorStateSchema, supervisorStatusSchema, testWebhooks, toRepoSlug, webhookEntrySchema, webhookIncomingEventSchema };
2041
+ export { type ActiveSession, type ActivityEntry, ActivityLog, type ActivityQueryOptions, type AgentConfig, type AgentDefinition, type AgentMessageEvent, type AgentModel, AgentRegistry, type AgentTool, type AgentToolEntry, type AgentToolUseEvent, type AuditLogMiddleware, type BudgetAlertEvent, ConfigStore, type CostEntry, CostJournal, type CostUpdateEvent, type Decision, type DecisionInput, type DecisionOption, DecisionStore, type DispatchInput, type Embedder, EventJournal, EventQueue, type GateWaitingEvent, type GitStrategy, type GlobalConfig, HeartbeatLoop, type HeartbeatLoopOptions, type HookEvent, type InboxMessage, LocalEmbedder, type LoopDetectionMiddleware, type McpServerConfig, type MemoryEntry, type MemoryQuery, type MemoryStats, MemoryStore, type MemoryType, type MemoryWriteInput, type Middleware, type MiddlewareChain, type MiddlewareContext, type MiddlewareContextMap, type MiddlewareEvent, type MiddlewareHandler, type MiddlewareResult, type NeoConfig, type NeoEvent, NeoEventEmitter, Orchestrator, type OrchestratorOptions, type OrchestratorShutdownEvent, type OrchestratorStatus, type ParsedOutput, type PersistedRun, type Priority, type QueueDequeueEvent, type QueueEnqueueEvent, type QueuedEvent, type RecoveryOptions, type RepoConfig, type RepoConfigInput, type ResolvedAgent, type RunContext, type SDKHooks, type SandboxConfig, Semaphore, type SemaphoreCallbacks, type SemaphoreConfig, type SessionCloneInfo, type SessionCompleteEvent, SessionError, type SessionEvent, type SessionExecutionConfig, type SessionExecutionDeps, type SessionExecutionInput, type SessionExecutionResult, SessionExecutor, type SessionFailEvent, type SessionOptions, type SessionResult, type SessionStartEvent, StatusReader, type StepCompleteEvent, type StepResult, type StepStartEvent, type SubagentDefinition, SupervisorDaemon, type SupervisorDaemonOptions, type SupervisorDaemonState, type SupervisorDaemonState as SupervisorState, type SupervisorStatus, type TaskResult, VERSION, WebhookDispatcher, type WebhookEntry, type WebhookEntryInput, type WebhookIncomingEvent, WebhookServer, type WebhookTestPayload, type WebhookTestResult, activityEntrySchema, addRepoToGlobalConfig, addWebhook, agentConfigSchema, agentModelSchema, agentSandboxSchema, agentToolEntrySchema, agentToolSchema, appendLogBuffer, auditLog, budgetGuard, buildFullPrompt, buildGitStrategyInstructions, buildMiddlewareChain, buildReportingInstructions, buildSDKHooks, buildSandboxConfig, createBranch, createSessionClone, decisionOptionSchema, decisionSchema, deleteBranch, fetchRemote, getBranchName, getCurrentBranch, getDataDir, getJournalsDir, getRepoRunsDir, getRunDispatchPath, getRunLogPath, getRunsDir, getSupervisorActivityPath, getSupervisorDecisionsPath, getSupervisorDir, getSupervisorEventsPath, getSupervisorInboxPath, getSupervisorLockPath, getSupervisorStatePath, getSupervisorsDir, globalConfigSchema, inboxMessageSchema, isProcessAlive, listReposFromGlobalConfig, listSessionClones, listWebhooks, loadAgentFile, loadConfig, loadGlobalConfig, loadRepoInstructions, loopDetection, matchesFilter, mcpServerConfigSchema, neoConfigSchema, parseOutput, pushBranch, pushSessionBranch, removeRepoFromGlobalConfig, removeSessionClone, removeWebhook, repoConfigSchema, repoOverrideConfigSchema, resolveAgent, runSession, runWithRecovery, supervisorDaemonStateSchema, supervisorDaemonStateSchema as supervisorStateSchema, supervisorStatusSchema, testWebhooks, toRepoSlug, webhookEntrySchema, webhookIncomingEventSchema };