@hasna/loops 0.4.12 → 0.4.14

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 (41) hide show
  1. package/CHANGELOG.md +106 -3
  2. package/README.md +70 -17
  3. package/dist/api/index.d.ts +35 -0
  4. package/dist/api/index.js +750 -10
  5. package/dist/cli/index.js +1744 -361
  6. package/dist/cli/ui.d.ts +44 -0
  7. package/dist/daemon/index.js +948 -212
  8. package/dist/generated/storage-kit/health.d.ts +19 -0
  9. package/dist/generated/storage-kit/index.d.ts +7 -0
  10. package/dist/generated/storage-kit/migrations.d.ts +47 -0
  11. package/dist/generated/storage-kit/mode.d.ts +47 -0
  12. package/dist/generated/storage-kit/pool.d.ts +33 -0
  13. package/dist/generated/storage-kit/query.d.ts +35 -0
  14. package/dist/generated/storage-kit/tls.d.ts +25 -0
  15. package/dist/index.d.ts +3 -3
  16. package/dist/index.js +6513 -4840
  17. package/dist/lib/health.d.ts +83 -3
  18. package/dist/lib/mode.d.ts +27 -0
  19. package/dist/lib/mode.js +69 -2
  20. package/dist/lib/scheduler.d.ts +5 -2
  21. package/dist/lib/storage/index.d.ts +1 -0
  22. package/dist/lib/storage/index.js +1329 -211
  23. package/dist/lib/storage/pg-executor.d.ts +27 -0
  24. package/dist/lib/storage/pg-runner-claim.d.ts +40 -0
  25. package/dist/lib/storage/postgres-loop-storage.d.ts +114 -0
  26. package/dist/lib/storage/sqlite.js +336 -8
  27. package/dist/lib/store.d.ts +234 -0
  28. package/dist/lib/store.js +350 -8
  29. package/dist/mcp/index.js +1447 -479
  30. package/dist/runner/index.js +179 -25
  31. package/dist/sdk/http.d.ts +115 -0
  32. package/dist/sdk/http.js +145 -0
  33. package/dist/sdk/index.d.ts +5 -1
  34. package/dist/sdk/index.js +1106 -296
  35. package/dist/serve/index.d.ts +4 -0
  36. package/dist/serve/index.js +7619 -0
  37. package/dist/types.d.ts +3 -0
  38. package/docs/CUTOVER-RUNBOOK.md +61 -0
  39. package/docs/DEPLOYMENT_MODES.md +23 -1
  40. package/docs/USAGE.md +66 -16
  41. package/package.json +14 -2
@@ -4,6 +4,211 @@ interface DaemonLeaseFence {
4
4
  now?: Date;
5
5
  claimToken?: string;
6
6
  }
7
+ export interface LoopRow {
8
+ id: string;
9
+ name: string;
10
+ description: string | null;
11
+ status: string;
12
+ archived_at: string | null;
13
+ archived_from_status: string | null;
14
+ schedule_json: string;
15
+ target_json: string;
16
+ goal_json: string | null;
17
+ machine_json: string | null;
18
+ next_run_at: string | null;
19
+ retry_scheduled_for: string | null;
20
+ catch_up: string;
21
+ catch_up_limit: number;
22
+ overlap: string;
23
+ max_attempts: number;
24
+ retry_delay_ms: number;
25
+ lease_ms: number;
26
+ expires_at: string | null;
27
+ created_at: string;
28
+ updated_at: string;
29
+ }
30
+ export interface RunRow {
31
+ id: string;
32
+ loop_id: string;
33
+ loop_name: string;
34
+ scheduled_for: string;
35
+ attempt: number;
36
+ status: string;
37
+ started_at: string | null;
38
+ finished_at: string | null;
39
+ claimed_by: string | null;
40
+ claim_token: string | null;
41
+ lease_expires_at: string | null;
42
+ pid: number | null;
43
+ pgid: number | null;
44
+ process_started_at: string | null;
45
+ exit_code: number | null;
46
+ duration_ms: number | null;
47
+ stdout: string | null;
48
+ stderr: string | null;
49
+ error: string | null;
50
+ goal_run_id: string | null;
51
+ created_at: string;
52
+ updated_at: string;
53
+ }
54
+ export interface WorkflowRow {
55
+ id: string;
56
+ name: string;
57
+ description: string | null;
58
+ version: number;
59
+ status: string;
60
+ goal_json: string | null;
61
+ steps_json: string;
62
+ created_at: string;
63
+ updated_at: string;
64
+ }
65
+ export interface WorkflowRunRow {
66
+ id: string;
67
+ workflow_id: string;
68
+ workflow_name: string;
69
+ loop_id: string | null;
70
+ loop_run_id: string | null;
71
+ invocation_id: string | null;
72
+ work_item_id: string | null;
73
+ scheduled_for: string | null;
74
+ idempotency_key: string | null;
75
+ manifest_path: string | null;
76
+ status: string;
77
+ started_at: string | null;
78
+ finished_at: string | null;
79
+ duration_ms: number | null;
80
+ error: string | null;
81
+ goal_run_id: string | null;
82
+ created_at: string;
83
+ updated_at: string;
84
+ }
85
+ export interface WorkflowInvocationRow {
86
+ id: string;
87
+ workflow_id: string | null;
88
+ template_id: string | null;
89
+ source_kind: string;
90
+ source_id: string | null;
91
+ source_dedupe_key: string | null;
92
+ source_json: string;
93
+ subject_kind: string;
94
+ subject_id: string | null;
95
+ subject_path: string | null;
96
+ subject_url: string | null;
97
+ subject_json: string;
98
+ intent: string;
99
+ scope_json: string | null;
100
+ output_policy_json: string | null;
101
+ created_at: string;
102
+ updated_at: string;
103
+ }
104
+ export interface WorkflowWorkItemRow {
105
+ id: string;
106
+ route_key: string;
107
+ idempotency_key: string;
108
+ invocation_id: string;
109
+ source_type: string;
110
+ source_ref: string;
111
+ subject_ref: string;
112
+ project_key: string | null;
113
+ project_group: string | null;
114
+ route_scope: string | null;
115
+ priority: number;
116
+ status: string;
117
+ attempts: number;
118
+ next_attempt_at: string | null;
119
+ lease_expires_at: string | null;
120
+ workflow_id: string | null;
121
+ loop_id: string | null;
122
+ workflow_run_id: string | null;
123
+ last_reason: string | null;
124
+ created_at: string;
125
+ updated_at: string;
126
+ }
127
+ export interface WorkflowStepRunRow {
128
+ id: string;
129
+ workflow_run_id: string;
130
+ step_id: string;
131
+ sequence: number;
132
+ status: string;
133
+ started_at: string | null;
134
+ finished_at: string | null;
135
+ exit_code: number | null;
136
+ pid: number | null;
137
+ duration_ms: number | null;
138
+ stdout: string | null;
139
+ stderr: string | null;
140
+ error: string | null;
141
+ account_profile: string | null;
142
+ account_tool: string | null;
143
+ goal_run_id: string | null;
144
+ created_at: string;
145
+ updated_at: string;
146
+ }
147
+ export interface WorkflowEventRow {
148
+ id: string;
149
+ workflow_run_id: string;
150
+ sequence: number;
151
+ event_type: string;
152
+ step_id: string | null;
153
+ payload_json: string | null;
154
+ created_at: string;
155
+ }
156
+ export interface GoalRow {
157
+ id: string;
158
+ plan_id: string;
159
+ objective: string;
160
+ status: string;
161
+ token_budget: number | null;
162
+ tokens_used: number;
163
+ time_used_seconds: number;
164
+ auto_execute: string;
165
+ max_tokens: number | null;
166
+ source_type: string | null;
167
+ source_id: string | null;
168
+ loop_id: string | null;
169
+ loop_run_id: string | null;
170
+ workflow_id: string | null;
171
+ workflow_run_id: string | null;
172
+ workflow_step_id: string | null;
173
+ created_at: string;
174
+ updated_at: string;
175
+ }
176
+ export interface GoalPlanNodeRow {
177
+ id: string;
178
+ goal_id: string;
179
+ plan_id: string;
180
+ key: string;
181
+ sequence: number;
182
+ priority: number;
183
+ objective: string;
184
+ status: string;
185
+ ready: number;
186
+ token_budget: number | null;
187
+ tokens_used: number;
188
+ time_used_seconds: number;
189
+ depends_on_json: string;
190
+ created_at: string;
191
+ updated_at: string;
192
+ }
193
+ export interface GoalRunRow {
194
+ id: string;
195
+ goal_id: string;
196
+ plan_id: string;
197
+ loop_id: string | null;
198
+ loop_run_id: string | null;
199
+ workflow_id: string | null;
200
+ workflow_run_id: string | null;
201
+ workflow_step_id: string | null;
202
+ turn: number;
203
+ phase: string;
204
+ status: string;
205
+ node_key: string | null;
206
+ tokens_used: number;
207
+ evidence_json: string | null;
208
+ raw_response_json: string | null;
209
+ created_at: string;
210
+ updated_at: string;
211
+ }
7
212
  export interface DaemonLease {
8
213
  id: string;
9
214
  pid: number;
@@ -13,6 +218,27 @@ export interface DaemonLease {
13
218
  createdAt: string;
14
219
  updatedAt: string;
15
220
  }
221
+ export interface LeaseRow {
222
+ id: string;
223
+ pid: number;
224
+ hostname: string;
225
+ heartbeat_at: string;
226
+ expires_at: string;
227
+ created_at: string;
228
+ updated_at: string;
229
+ }
230
+ export declare function rowToLoop(row: LoopRow): Loop;
231
+ export declare function rowToRun(row: RunRow): LoopRun;
232
+ export declare function rowToWorkflow(row: WorkflowRow): WorkflowSpec;
233
+ export declare function rowToWorkflowRun(row: WorkflowRunRow): WorkflowRun;
234
+ export declare function rowToWorkflowInvocation(row: WorkflowInvocationRow): WorkflowInvocation;
235
+ export declare function rowToWorkflowWorkItem(row: WorkflowWorkItemRow): WorkflowWorkItem;
236
+ export declare function rowToWorkflowStepRun(row: WorkflowStepRunRow): WorkflowStepRun;
237
+ export declare function rowToGoal(row: GoalRow): Goal;
238
+ export declare function rowToGoalPlanNode(row: GoalPlanNodeRow): GoalPlanNode;
239
+ export declare function rowToGoalRun(row: GoalRunRow): GoalRun;
240
+ export declare function rowToWorkflowEvent(row: WorkflowEventRow): WorkflowEvent;
241
+ export declare function rowToLease(row: LeaseRow): DaemonLease;
16
242
  export interface ClaimRunResult {
17
243
  run: LoopRun;
18
244
  loop: Loop;
@@ -122,6 +348,9 @@ export interface RecordGoalEventInput {
122
348
  evidence?: Record<string, unknown>;
123
349
  rawResponse?: unknown;
124
350
  }
351
+ export declare function workItemStatusForLoopRun(status: RunStatus, attempt: number, maxAttempts: number | undefined): WorkflowWorkItemStatus | undefined;
352
+ /** Scrub secrets then bound size before persisting run stdout/stderr. */
353
+ export declare function persistedRunOutput(value: string | undefined | null): string | null;
125
354
  export declare class Store {
126
355
  private db;
127
356
  private rootDir;
@@ -155,6 +384,7 @@ export declare class Store {
155
384
  archived?: boolean;
156
385
  includeArchived?: boolean;
157
386
  }): Loop[];
387
+ private withLatestRunSummaries;
158
388
  dueLoops(now: Date, limit?: number): Loop[];
159
389
  updateLoop(id: string, patch: Partial<Pick<Loop, "status" | "nextRunAt" | "retryScheduledFor" | "expiresAt">>, opts?: DaemonLeaseFence): Loop;
160
390
  private activeLoopReferenceCount;
@@ -162,6 +392,7 @@ export declare class Store {
162
392
  retargetWorkflowLoop(idOrName: string, workflowId: string, opts?: DaemonLeaseFence & {
163
393
  workflowTimeoutMs?: TimeoutMs;
164
394
  }): Loop;
395
+ updateAgentLoopTimeout(idOrName: string, timeoutMs: TimeoutMs, opts?: DaemonLeaseFence): Loop;
165
396
  createAndRetargetWorkflowLoop(idOrName: string, workflowInput: CreateWorkflowInput, opts?: DaemonLeaseFence & {
166
397
  workflowTimeoutMs?: TimeoutMs;
167
398
  archiveOld?: boolean;
@@ -201,6 +432,8 @@ export declare class Store {
201
432
  private generatedRouteArchiveContext;
202
433
  private maybeArchiveGeneratedRouteWorkflow;
203
434
  private maybeArchiveTerminalGeneratedRouteWorkflow;
435
+ private taskLifecycleTodosPointerContext;
436
+ private syncSuccessfulTaskLifecycleTodosPointers;
204
437
  createWorkflowInvocation(input: CreateWorkflowInvocationInput): WorkflowInvocation;
205
438
  refreshWorkflowInvocationForWorkItem(workItemId: string, input: CreateWorkflowInvocationInput): WorkflowInvocation;
206
439
  getWorkflowInvocation(id: string): WorkflowInvocation | undefined;
@@ -309,6 +542,7 @@ export declare class Store {
309
542
  listWorkflowEvents(workflowRunId: string, limit?: number): WorkflowEvent[];
310
543
  hasRunningRun(loopId: string): boolean;
311
544
  hasRunningRunForSlot(loopId: string, scheduledFor: string): boolean;
545
+ private hasBlockingRunningRunForOtherSlot;
312
546
  markRunPid(id: string, pid: number, claimedBy?: string, opts?: DaemonLeaseFence): LoopRun | undefined;
313
547
  /**
314
548
  * Record the spawned child's process identity (pid, process group id, start