@hasna/loops 0.4.14 → 0.4.23

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 (48) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/README.md +119 -29
  3. package/dist/api/index.d.ts +1 -0
  4. package/dist/api/index.js +825 -7
  5. package/dist/cli/index.js +5423 -2619
  6. package/dist/daemon/index.js +478 -84
  7. package/dist/generated/storage-kit/index.d.ts +1 -1
  8. package/dist/index.js +2521 -226
  9. package/dist/lib/cloud/mode.d.ts +17 -0
  10. package/dist/lib/cloud/resolve.d.ts +16 -0
  11. package/dist/lib/cloud/storage.d.ts +82 -0
  12. package/dist/lib/cloud/transport.d.ts +148 -0
  13. package/dist/lib/format.d.ts +2 -1
  14. package/dist/lib/migration.d.ts +40 -0
  15. package/dist/lib/mode.js +3 -3
  16. package/dist/lib/route/index.d.ts +2 -0
  17. package/dist/lib/route/policies.d.ts +51 -0
  18. package/dist/lib/route/provider-admission.d.ts +37 -0
  19. package/dist/lib/route/throttle.d.ts +4 -0
  20. package/dist/lib/route/types.d.ts +8 -0
  21. package/dist/lib/run-receipts.d.ts +14 -0
  22. package/dist/lib/storage/contract.d.ts +7 -1
  23. package/dist/lib/storage/index.js +710 -31
  24. package/dist/lib/storage/postgres-loop-storage.d.ts +6 -0
  25. package/dist/lib/storage/postgres-schema.js +29 -0
  26. package/dist/lib/storage/postgres.js +29 -0
  27. package/dist/lib/storage/sqlite.d.ts +6 -0
  28. package/dist/lib/storage/sqlite.js +412 -18
  29. package/dist/lib/store/index.d.ts +268 -0
  30. package/dist/lib/store.d.ts +48 -1
  31. package/dist/lib/store.js +396 -18
  32. package/dist/lib/template-kit.d.ts +25 -0
  33. package/dist/lib/templates.d.ts +16 -1
  34. package/dist/mcp/http.d.ts +16 -0
  35. package/dist/mcp/index.js +1658 -168
  36. package/dist/runner/index.js +76 -9
  37. package/dist/sdk/http.d.ts +67 -0
  38. package/dist/sdk/http.js +21 -0
  39. package/dist/sdk/index.d.ts +50 -17
  40. package/dist/sdk/index.js +1509 -132
  41. package/dist/serve/index.js +1598 -122
  42. package/dist/types.d.ts +49 -0
  43. package/docs/AUTOMATION_RUNTIME_DESIGN.md +442 -1
  44. package/docs/CUTOVER-RUNBOOK.md +73 -56
  45. package/docs/DEPLOYMENT_MODES.md +35 -18
  46. package/docs/RUNTIME_BOUNDARY.md +203 -0
  47. package/docs/USAGE.md +145 -27
  48. package/package.json +3 -3
@@ -38,6 +38,9 @@ export declare class PostgresLoopStorage implements LoopStorageContract {
38
38
  deleteLoop(...args: M<"deleteLoop">["args"]): Promise<M<"deleteLoop">["result"]>;
39
39
  private requireLoopIn;
40
40
  countLoops(...args: M<"countLoops">["args"]): Promise<M<"countLoops">["result"]>;
41
+ upsertMigrationWorkflow(...args: M<"upsertMigrationWorkflow">["args"]): Promise<M<"upsertMigrationWorkflow">["result"]>;
42
+ upsertMigrationLoop(...args: M<"upsertMigrationLoop">["args"]): Promise<M<"upsertMigrationLoop">["result"]>;
43
+ upsertMigrationRun(...args: M<"upsertMigrationRun">["args"]): Promise<M<"upsertMigrationRun">["result"]>;
41
44
  createSkippedRun(...args: M<"createSkippedRun">["args"]): Promise<M<"createSkippedRun">["result"]>;
42
45
  getRun(...args: M<"getRun">["args"]): Promise<M<"getRun">["result"]>;
43
46
  getRunBySlot(...args: M<"getRunBySlot">["args"]): Promise<M<"getRunBySlot">["result"]>;
@@ -59,6 +62,9 @@ export declare class PostgresLoopStorage implements LoopStorageContract {
59
62
  heartbeatRunLease(...args: M<"heartbeatRunLease">["args"]): Promise<M<"heartbeatRunLease">["result"]>;
60
63
  recordRunProcess(...args: M<"recordRunProcess">["args"]): Promise<M<"recordRunProcess">["result"]>;
61
64
  listRuns(...args: M<"listRuns">["args"]): Promise<M<"listRuns">["result"]>;
65
+ writeRunReceipt(...args: M<"writeRunReceipt">["args"]): Promise<M<"writeRunReceipt">["result"]>;
66
+ getRunReceipt(...args: M<"getRunReceipt">["args"]): Promise<M<"getRunReceipt">["result"]>;
67
+ listRunReceipts(...args: M<"listRunReceipts">["args"]): Promise<M<"listRunReceipts">["result"]>;
62
68
  countRuns(...args: M<"countRuns">["args"]): Promise<M<"countRuns">["result"]>;
63
69
  recoverExpiredRunLeases(...args: M<"recoverExpiredRunLeases">["args"]): Promise<M<"recoverExpiredRunLeases">["result"]>;
64
70
  /**
@@ -323,6 +323,35 @@ CREATE INDEX IF NOT EXISTS idx_audit_events_action ON audit_events(action, creat
323
323
  migration("0004_work_item_route_scope", `
324
324
  ALTER TABLE workflow_work_items ADD COLUMN IF NOT EXISTS route_scope TEXT;
325
325
  CREATE INDEX IF NOT EXISTS idx_workflow_work_items_scope ON workflow_work_items(route_scope, status);
326
+ `),
327
+ migration("0005_run_receipts", `
328
+ CREATE TABLE IF NOT EXISTS run_receipts (
329
+ run_id TEXT PRIMARY KEY,
330
+ loop_id TEXT NOT NULL,
331
+ machine_json JSONB NOT NULL,
332
+ repo TEXT NOT NULL,
333
+ task_ids_json JSONB NOT NULL,
334
+ knowledge_ids_json JSONB NOT NULL,
335
+ digest_id TEXT NOT NULL,
336
+ started_at TIMESTAMPTZ,
337
+ finished_at TIMESTAMPTZ,
338
+ status TEXT NOT NULL,
339
+ exit_code INTEGER,
340
+ summary_json JSONB NOT NULL,
341
+ evidence_paths_json JSONB NOT NULL,
342
+ created_at TIMESTAMPTZ NOT NULL,
343
+ updated_at TIMESTAMPTZ NOT NULL
344
+ );
345
+ CREATE INDEX IF NOT EXISTS idx_run_receipts_loop ON run_receipts(loop_id, created_at DESC);
346
+ CREATE INDEX IF NOT EXISTS idx_run_receipts_repo ON run_receipts(repo, created_at DESC);
347
+ CREATE INDEX IF NOT EXISTS idx_run_receipts_digest ON run_receipts(digest_id);
348
+ CREATE INDEX IF NOT EXISTS idx_run_receipts_status ON run_receipts(status, created_at DESC);
349
+ CREATE INDEX IF NOT EXISTS idx_run_receipts_task_ids ON run_receipts USING GIN (task_ids_json);
350
+ CREATE INDEX IF NOT EXISTS idx_run_receipts_knowledge_ids ON run_receipts USING GIN (knowledge_ids_json);
351
+ `),
352
+ migration("0006_work_item_machine_id", `
353
+ ALTER TABLE workflow_work_items ADD COLUMN IF NOT EXISTS machine_id TEXT;
354
+ CREATE INDEX IF NOT EXISTS idx_workflow_work_items_machine ON workflow_work_items(machine_id, status);
326
355
  `)
327
356
  ]);
328
357
  export {
@@ -323,6 +323,35 @@ CREATE INDEX IF NOT EXISTS idx_audit_events_action ON audit_events(action, creat
323
323
  migration("0004_work_item_route_scope", `
324
324
  ALTER TABLE workflow_work_items ADD COLUMN IF NOT EXISTS route_scope TEXT;
325
325
  CREATE INDEX IF NOT EXISTS idx_workflow_work_items_scope ON workflow_work_items(route_scope, status);
326
+ `),
327
+ migration("0005_run_receipts", `
328
+ CREATE TABLE IF NOT EXISTS run_receipts (
329
+ run_id TEXT PRIMARY KEY,
330
+ loop_id TEXT NOT NULL,
331
+ machine_json JSONB NOT NULL,
332
+ repo TEXT NOT NULL,
333
+ task_ids_json JSONB NOT NULL,
334
+ knowledge_ids_json JSONB NOT NULL,
335
+ digest_id TEXT NOT NULL,
336
+ started_at TIMESTAMPTZ,
337
+ finished_at TIMESTAMPTZ,
338
+ status TEXT NOT NULL,
339
+ exit_code INTEGER,
340
+ summary_json JSONB NOT NULL,
341
+ evidence_paths_json JSONB NOT NULL,
342
+ created_at TIMESTAMPTZ NOT NULL,
343
+ updated_at TIMESTAMPTZ NOT NULL
344
+ );
345
+ CREATE INDEX IF NOT EXISTS idx_run_receipts_loop ON run_receipts(loop_id, created_at DESC);
346
+ CREATE INDEX IF NOT EXISTS idx_run_receipts_repo ON run_receipts(repo, created_at DESC);
347
+ CREATE INDEX IF NOT EXISTS idx_run_receipts_digest ON run_receipts(digest_id);
348
+ CREATE INDEX IF NOT EXISTS idx_run_receipts_status ON run_receipts(status, created_at DESC);
349
+ CREATE INDEX IF NOT EXISTS idx_run_receipts_task_ids ON run_receipts USING GIN (task_ids_json);
350
+ CREATE INDEX IF NOT EXISTS idx_run_receipts_knowledge_ids ON run_receipts USING GIN (knowledge_ids_json);
351
+ `),
352
+ migration("0006_work_item_machine_id", `
353
+ ALTER TABLE workflow_work_items ADD COLUMN IF NOT EXISTS machine_id TEXT;
354
+ CREATE INDEX IF NOT EXISTS idx_workflow_work_items_machine ON workflow_work_items(machine_id, status);
326
355
  `)
327
356
  ]);
328
357
 
@@ -22,6 +22,9 @@ export declare class SqliteLoopStorage implements LoopStorageContract {
22
22
  archiveLoop(...args: StoreMethod<"archiveLoop">["args"]): Promise<import("../../types.js").Loop>;
23
23
  unarchiveLoop(...args: StoreMethod<"unarchiveLoop">["args"]): Promise<import("../../types.js").Loop>;
24
24
  deleteLoop(...args: StoreMethod<"deleteLoop">["args"]): Promise<boolean>;
25
+ upsertMigrationLoop(...args: StoreMethod<"upsertMigrationLoop">["args"]): Promise<import("../../types.js").Loop>;
26
+ upsertMigrationRun(...args: StoreMethod<"upsertMigrationRun">["args"]): Promise<import("../../types.js").LoopRun>;
27
+ upsertMigrationWorkflow(...args: StoreMethod<"upsertMigrationWorkflow">["args"]): Promise<import("../../types.js").WorkflowSpec>;
25
28
  createWorkflow(...args: StoreMethod<"createWorkflow">["args"]): Promise<import("../../types.js").WorkflowSpec>;
26
29
  getWorkflow(...args: StoreMethod<"getWorkflow">["args"]): Promise<import("../../types.js").WorkflowSpec | undefined>;
27
30
  listWorkflows(...args: StoreMethod<"listWorkflows">["args"]): Promise<import("../../types.js").WorkflowSpec[]>;
@@ -70,6 +73,9 @@ export declare class SqliteLoopStorage implements LoopStorageContract {
70
73
  finalizeRun(...args: StoreMethod<"finalizeRun">["args"]): Promise<import("../../types.js").LoopRun>;
71
74
  heartbeatRunLease(...args: StoreMethod<"heartbeatRunLease">["args"]): Promise<import("../../types.js").LoopRun | undefined>;
72
75
  listRuns(...args: StoreMethod<"listRuns">["args"]): Promise<import("../../types.js").LoopRun[]>;
76
+ writeRunReceipt(...args: StoreMethod<"writeRunReceipt">["args"]): Promise<import("../../types.js").RunReceipt>;
77
+ getRunReceipt(...args: StoreMethod<"getRunReceipt">["args"]): Promise<import("../../types.js").RunReceipt | undefined>;
78
+ listRunReceipts(...args: StoreMethod<"listRunReceipts">["args"]): Promise<import("../../types.js").RunReceipt[]>;
73
79
  recoverExpiredRunLeases(...args: StoreMethod<"recoverExpiredRunLeases">["args"]): Promise<import("../../types.js").LoopRun[]>;
74
80
  recoverExpiredRunLeasesDetailed(...args: StoreMethod<"recoverExpiredRunLeasesDetailed">["args"]): Promise<import("../store.js").RecoverExpiredRunLeasesResult>;
75
81
  countLoops(...args: StoreMethod<"countLoops">["args"]): Promise<number>;