@hasna/loops 0.4.13 → 0.4.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.
Files changed (62) hide show
  1. package/CHANGELOG.md +99 -3
  2. package/README.md +171 -39
  3. package/dist/api/index.d.ts +36 -0
  4. package/dist/api/index.js +1518 -15
  5. package/dist/cli/index.js +7280 -3213
  6. package/dist/cli/ui.d.ts +44 -0
  7. package/dist/daemon/index.js +1433 -303
  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 +2 -2
  16. package/dist/index.js +8689 -4837
  17. package/dist/lib/cloud/mode.d.ts +17 -0
  18. package/dist/lib/cloud/resolve.d.ts +16 -0
  19. package/dist/lib/cloud/storage.d.ts +82 -0
  20. package/dist/lib/cloud/transport.d.ts +148 -0
  21. package/dist/lib/format.d.ts +2 -1
  22. package/dist/lib/health.d.ts +83 -3
  23. package/dist/lib/migration.d.ts +40 -0
  24. package/dist/lib/mode.js +15 -3
  25. package/dist/lib/route/index.d.ts +2 -0
  26. package/dist/lib/route/policies.d.ts +51 -0
  27. package/dist/lib/route/provider-admission.d.ts +37 -0
  28. package/dist/lib/route/throttle.d.ts +4 -0
  29. package/dist/lib/route/types.d.ts +8 -0
  30. package/dist/lib/run-receipts.d.ts +14 -0
  31. package/dist/lib/scheduler.d.ts +5 -2
  32. package/dist/lib/storage/contract.d.ts +7 -1
  33. package/dist/lib/storage/index.d.ts +1 -0
  34. package/dist/lib/storage/index.js +2028 -231
  35. package/dist/lib/storage/pg-executor.d.ts +27 -0
  36. package/dist/lib/storage/pg-runner-claim.d.ts +40 -0
  37. package/dist/lib/storage/postgres-loop-storage.d.ts +120 -0
  38. package/dist/lib/storage/postgres-schema.js +29 -0
  39. package/dist/lib/storage/postgres.js +29 -0
  40. package/dist/lib/storage/sqlite.d.ts +6 -0
  41. package/dist/lib/storage/sqlite.js +748 -26
  42. package/dist/lib/store/index.d.ts +268 -0
  43. package/dist/lib/store.d.ts +282 -1
  44. package/dist/lib/store.js +746 -26
  45. package/dist/lib/template-kit.d.ts +25 -0
  46. package/dist/lib/templates.d.ts +16 -1
  47. package/dist/mcp/http.d.ts +16 -0
  48. package/dist/mcp/index.js +2885 -634
  49. package/dist/runner/index.js +198 -32
  50. package/dist/sdk/http.d.ts +182 -0
  51. package/dist/sdk/http.js +166 -0
  52. package/dist/sdk/index.d.ts +55 -18
  53. package/dist/sdk/index.js +2734 -617
  54. package/dist/serve/index.d.ts +4 -0
  55. package/dist/serve/index.js +9095 -0
  56. package/dist/types.d.ts +52 -0
  57. package/docs/AUTOMATION_RUNTIME_DESIGN.md +442 -1
  58. package/docs/CUTOVER-RUNBOOK.md +78 -0
  59. package/docs/DEPLOYMENT_MODES.md +35 -18
  60. package/docs/RUNTIME_BOUNDARY.md +203 -0
  61. package/docs/USAGE.md +195 -38
  62. package/package.json +15 -3
@@ -0,0 +1,14 @@
1
+ import type { Loop, LoopRun, RunReceipt, RunReceiptMachine, WriteRunReceiptInput } from "../types.js";
2
+ export declare const RUN_RECEIPT_SUMMARY_TEXT_CHARS = 4096;
3
+ export declare const RUN_RECEIPT_MAX_IDS = 100;
4
+ export declare const RUN_RECEIPT_MAX_EVIDENCE_PATHS = 100;
5
+ export declare const RUN_RECEIPT_MAX_PATH_CHARS = 1024;
6
+ export interface NormalizeRunReceiptOptions {
7
+ now?: Date;
8
+ loop?: Loop;
9
+ run?: LoopRun;
10
+ defaultMachine?: RunReceiptMachine;
11
+ defaultRepo?: string;
12
+ existing?: RunReceipt;
13
+ }
14
+ export declare function normalizeRunReceipt(input: WriteRunReceiptInput, opts?: NormalizeRunReceiptOptions): RunReceipt;
@@ -97,8 +97,8 @@ export declare const MAX_SKIPS_PER_LOOP_PER_TICK = 10;
97
97
  /**
98
98
  * Exponential retry backoff with jitter:
99
99
  * delay = retryDelayMs * 2^(attempt-1) * (0.5 + random), capped at 6h.
100
- * Failures classified as rate_limit/auth back off 4x harder, since hammering
101
- * a throttled or misconfigured provider only makes things worse.
100
+ * Failures classified as provider-gated back off 4x harder, since hammering
101
+ * a throttled, misconfigured, or unavailable provider only makes things worse.
102
102
  */
103
103
  export declare function retryBackoffDelayMs(loop: Loop, run: LoopRun, random?: () => number): number;
104
104
  export interface AdvanceLoopOptions {
@@ -129,6 +129,9 @@ export declare function executeClaimedRun(deps: {
129
129
  beforeFinalize?: (loop: Loop, run: LoopRun) => void;
130
130
  daemonLeaseId?: string;
131
131
  execute?: (loop: Loop, run: LoopRun) => Promise<ExecutorResult>;
132
+ finalizeResult?: (result: ExecutorResult, loop: Loop, run: LoopRun) => Omit<ExecutorResult, "status"> & {
133
+ status: LoopRun["status"];
134
+ };
132
135
  onError?: (loop: Loop, error: unknown) => void;
133
136
  }): Promise<LoopRun>;
134
137
  export declare function claimDueRuns(deps: SchedulerDeps & {
@@ -1,6 +1,6 @@
1
1
  import type { Store } from "../store.js";
2
2
  export type LoopStorageBackend = "sqlite" | "postgres";
3
- export type LoopStorageMethodName = "createLoop" | "getLoop" | "findLoopByName" | "requireLoop" | "listLoops" | "dueLoops" | "updateLoop" | "renameLoop" | "archiveLoop" | "unarchiveLoop" | "deleteLoop" | "createWorkflow" | "getWorkflow" | "listWorkflows" | "countWorkflows" | "archiveWorkflow" | "createWorkflowInvocation" | "getWorkflowInvocation" | "listWorkflowInvocations" | "upsertWorkflowWorkItem" | "getWorkflowWorkItem" | "listWorkflowWorkItems" | "countActiveWorkflowWorkItems" | "admitWorkflowWorkItem" | "createGoal" | "getGoal" | "listGoals" | "createGoalPlanNodes" | "listGoalPlanNodes" | "updateGoalStatus" | "updateGoalPlanNode" | "recordGoalEvent" | "listGoalRuns" | "createWorkflowRun" | "getWorkflowRun" | "listWorkflowRuns" | "listWorkflowStepRuns" | "getWorkflowStepRun" | "startWorkflowStepRun" | "recoverWorkflowRun" | "finalizeWorkflowStepRun" | "finalizeWorkflowRun" | "appendWorkflowEvent" | "listWorkflowEvents" | "recordRunProcess" | "createSkippedRun" | "getRun" | "getRunBySlot" | "claimRun" | "finalizeRun" | "heartbeatRunLease" | "listRuns" | "recoverExpiredRunLeases" | "recoverExpiredRunLeasesDetailed" | "countLoops" | "countRuns" | "pruneHistory" | "acquireDaemonLease" | "heartbeatDaemonLease" | "releaseDaemonLease" | "getDaemonLease";
3
+ export type LoopStorageMethodName = "createLoop" | "getLoop" | "findLoopByName" | "requireLoop" | "listLoops" | "dueLoops" | "updateLoop" | "renameLoop" | "archiveLoop" | "unarchiveLoop" | "deleteLoop" | "upsertMigrationLoop" | "upsertMigrationRun" | "upsertMigrationWorkflow" | "createWorkflow" | "getWorkflow" | "listWorkflows" | "countWorkflows" | "archiveWorkflow" | "createWorkflowInvocation" | "getWorkflowInvocation" | "listWorkflowInvocations" | "upsertWorkflowWorkItem" | "getWorkflowWorkItem" | "listWorkflowWorkItems" | "countActiveWorkflowWorkItems" | "admitWorkflowWorkItem" | "createGoal" | "getGoal" | "listGoals" | "createGoalPlanNodes" | "listGoalPlanNodes" | "updateGoalStatus" | "updateGoalPlanNode" | "recordGoalEvent" | "listGoalRuns" | "createWorkflowRun" | "getWorkflowRun" | "listWorkflowRuns" | "listWorkflowStepRuns" | "getWorkflowStepRun" | "startWorkflowStepRun" | "recoverWorkflowRun" | "finalizeWorkflowStepRun" | "finalizeWorkflowRun" | "appendWorkflowEvent" | "listWorkflowEvents" | "recordRunProcess" | "createSkippedRun" | "getRun" | "getRunBySlot" | "claimRun" | "finalizeRun" | "heartbeatRunLease" | "listRuns" | "writeRunReceipt" | "getRunReceipt" | "listRunReceipts" | "recoverExpiredRunLeases" | "recoverExpiredRunLeasesDetailed" | "countLoops" | "countRuns" | "pruneHistory" | "acquireDaemonLease" | "heartbeatDaemonLease" | "releaseDaemonLease" | "getDaemonLease";
4
4
  type AsyncStoreMethod<K extends LoopStorageMethodName> = Store[K] extends (...args: infer Args) => infer Result ? (...args: Args) => Promise<Result> : never;
5
5
  export interface LoopStorageContract extends Record<LoopStorageMethodName, (...args: never[]) => Promise<unknown>> {
6
6
  readonly backend: LoopStorageBackend;
@@ -17,6 +17,9 @@ export interface LoopStorageContract extends Record<LoopStorageMethodName, (...a
17
17
  archiveLoop: AsyncStoreMethod<"archiveLoop">;
18
18
  unarchiveLoop: AsyncStoreMethod<"unarchiveLoop">;
19
19
  deleteLoop: AsyncStoreMethod<"deleteLoop">;
20
+ upsertMigrationLoop: AsyncStoreMethod<"upsertMigrationLoop">;
21
+ upsertMigrationRun: AsyncStoreMethod<"upsertMigrationRun">;
22
+ upsertMigrationWorkflow: AsyncStoreMethod<"upsertMigrationWorkflow">;
20
23
  createWorkflow: AsyncStoreMethod<"createWorkflow">;
21
24
  getWorkflow: AsyncStoreMethod<"getWorkflow">;
22
25
  listWorkflows: AsyncStoreMethod<"listWorkflows">;
@@ -58,6 +61,9 @@ export interface LoopStorageContract extends Record<LoopStorageMethodName, (...a
58
61
  finalizeRun: AsyncStoreMethod<"finalizeRun">;
59
62
  heartbeatRunLease: AsyncStoreMethod<"heartbeatRunLease">;
60
63
  listRuns: AsyncStoreMethod<"listRuns">;
64
+ writeRunReceipt: AsyncStoreMethod<"writeRunReceipt">;
65
+ getRunReceipt: AsyncStoreMethod<"getRunReceipt">;
66
+ listRunReceipts: AsyncStoreMethod<"listRunReceipts">;
61
67
  recoverExpiredRunLeases: AsyncStoreMethod<"recoverExpiredRunLeases">;
62
68
  recoverExpiredRunLeasesDetailed: AsyncStoreMethod<"recoverExpiredRunLeasesDetailed">;
63
69
  countLoops: AsyncStoreMethod<"countLoops">;
@@ -2,5 +2,6 @@ export type { AppliedStorageMigration, AuditEventRecord, LoopStorageBackend, Loo
2
2
  export { SqliteLoopStorage, createSqliteLoopStorage } from "./sqlite.js";
3
3
  export { PostgresStorage, createPostgresStorage } from "./postgres.js";
4
4
  export type { PostgresQueryExecutor } from "./postgres.js";
5
+ export { PostgresLoopStorage, createPostgresLoopStorage, NotImplementedError, } from "./postgres-loop-storage.js";
5
6
  export { POSTGRES_MIGRATION_LEDGER_TABLE, POSTGRES_STORAGE_MIGRATIONS, checksumStorageSql, } from "./postgres-schema.js";
6
7
  export { Store } from "../store.js";