@hasna/loops 0.4.28 → 0.4.29

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 (77) hide show
  1. package/CHANGELOG.md +84 -1
  2. package/README.md +226 -49
  3. package/dist/api/index.d.ts +20 -19
  4. package/dist/api/index.js +6846 -1087
  5. package/dist/cli/index.js +2471 -885
  6. package/dist/cli/safe-error-context.d.ts +1 -0
  7. package/dist/daemon/daemon.d.ts +1 -0
  8. package/dist/daemon/index.js +1786 -493
  9. package/dist/generated/storage-kit/index.d.ts +1 -1
  10. package/dist/generated/storage-kit/mode.d.ts +6 -12
  11. package/dist/index.d.ts +3 -3
  12. package/dist/index.js +4778 -1016
  13. package/dist/lib/advancement.d.ts +52 -0
  14. package/dist/lib/agent-adapter.d.ts +20 -2
  15. package/dist/lib/auth/route-policy.d.ts +14 -0
  16. package/dist/lib/auth/tenant-auth.d.ts +38 -0
  17. package/dist/lib/cloud/mode.d.ts +2 -8
  18. package/dist/lib/cloud/storage.d.ts +1 -2
  19. package/dist/lib/cloud/transport.d.ts +4 -18
  20. package/dist/lib/errors.d.ts +43 -1
  21. package/dist/lib/format.d.ts +2 -2
  22. package/dist/lib/goal/runner.d.ts +36 -3
  23. package/dist/lib/health.d.ts +1 -1
  24. package/dist/lib/labels.d.ts +4 -0
  25. package/dist/lib/loop-status.d.ts +4 -0
  26. package/dist/lib/migration.d.ts +4 -17
  27. package/dist/lib/mode.d.ts +2 -5
  28. package/dist/lib/mode.js +27 -36
  29. package/dist/lib/route/index.d.ts +2 -2
  30. package/dist/lib/route/throttle.d.ts +7 -0
  31. package/dist/lib/route/types.d.ts +3 -0
  32. package/dist/lib/run-completion.d.ts +18 -0
  33. package/dist/lib/scheduler.d.ts +5 -11
  34. package/dist/lib/storage/contract.d.ts +15 -1
  35. package/dist/lib/storage/index.d.ts +1 -1
  36. package/dist/lib/storage/index.js +3864 -457
  37. package/dist/lib/storage/pg-executor.d.ts +10 -5
  38. package/dist/lib/storage/postgres-loop-storage.d.ts +50 -24
  39. package/dist/lib/storage/postgres-schema.d.ts +8 -0
  40. package/dist/lib/storage/postgres-schema.js +1323 -1
  41. package/dist/lib/storage/postgres.d.ts +3 -1
  42. package/dist/lib/storage/postgres.js +1353 -27
  43. package/dist/lib/storage/provider-credentials.d.ts +84 -0
  44. package/dist/lib/storage/shared-database-transfer.d.ts +136 -0
  45. package/dist/lib/storage/sqlite.d.ts +15 -2
  46. package/dist/lib/storage/sqlite.js +1299 -217
  47. package/dist/lib/storage/tenant-backfill-s3.d.ts +53 -0
  48. package/dist/lib/storage/tenant-backfill.d.ts +40 -0
  49. package/dist/lib/store/index.d.ts +11 -8
  50. package/dist/lib/store.d.ts +52 -7
  51. package/dist/lib/store.js +1266 -217
  52. package/dist/lib/templates.d.ts +11 -0
  53. package/dist/lib/workflow-events.d.ts +6 -0
  54. package/dist/lib/workflow-provenance.d.ts +8 -0
  55. package/dist/lib/workflow-runner.d.ts +52 -4
  56. package/dist/mcp/index.js +1961 -651
  57. package/dist/runner/index.d.ts +20 -2
  58. package/dist/runner/index.js +2113 -177
  59. package/dist/sdk/http.d.ts +211 -3
  60. package/dist/sdk/http.js +301 -0
  61. package/dist/sdk/index.d.ts +7 -2
  62. package/dist/sdk/index.js +1959 -711
  63. package/dist/serve/index.d.ts +14 -0
  64. package/dist/serve/index.js +12323 -1743
  65. package/dist/types.d.ts +64 -3
  66. package/docs/AUTOMATION_RUNTIME_DESIGN.md +32 -32
  67. package/docs/CUTOVER-RUNBOOK.md +158 -31
  68. package/docs/DEPLOYMENT_MODES.md +78 -56
  69. package/docs/RUNTIME_BOUNDARY.md +26 -26
  70. package/docs/SHARED-DATABASE-TRANSFER.md +95 -0
  71. package/docs/SHARED_KIT_EXTRACTION_INVENTORY.md +631 -0
  72. package/docs/TRANSCRIPT_LOOP_PATTERNS.md +3 -3
  73. package/docs/UNIFIED_PRODUCT_CONTRACT.md +365 -0
  74. package/docs/USAGE.md +143 -52
  75. package/docs/workflows/transcript-feedback-to-loops.json +2 -2
  76. package/package.json +7 -3
  77. package/dist/lib/storage/pg-runner-claim.d.ts +0 -40
@@ -1,5 +1,8 @@
1
1
  #!/usr/bin/env bun
2
+ import { type CircuitBreakerThreshold } from "../lib/advancement.js";
2
3
  import type { LoopStorageContract } from "../lib/storage/contract.js";
4
+ import { type RoutePolicy } from "../lib/auth/route-policy.js";
5
+ import type { TenantAuthContext, TenantAuthDecision } from "../lib/auth/tenant-auth.js";
3
6
  /** The serve OpenAPI document (source of the generated SDK), version-synced. */
4
7
  export declare function openApiDocument(): Record<string, unknown>;
5
8
  export declare function apiStatus(): {
@@ -7,23 +10,12 @@ export declare function apiStatus(): {
7
10
  service: string;
8
11
  status: import("../index.js").LoopDeploymentStatus;
9
12
  };
10
- /**
11
- * Framework-agnostic API-key verifier shape (matches
12
- * `@hasna/contracts/auth` `ApiKeyVerifier`). Kept structural so the api module
13
- * has no hard dependency on the auth package: the serve entry injects the real
14
- * verifier built from the vendored kit's client + the HMAC signing secret.
15
- */
16
13
  export interface ApiAuthenticator {
17
- authenticate(headers: Headers, context?: {
18
- method?: string | null;
19
- path?: string | null;
20
- requiredScopes?: readonly string[];
21
- }): Promise<{
22
- ok: boolean;
23
- status: number;
24
- reason?: string;
25
- message?: string;
26
- }>;
14
+ authenticate(headers: Headers, context: {
15
+ method: string;
16
+ path: string;
17
+ policy: RoutePolicy;
18
+ }): Promise<TenantAuthDecision>;
27
19
  }
28
20
  export interface LoopsApiServerOptions {
29
21
  host?: string;
@@ -33,21 +25,30 @@ export interface LoopsApiServerOptions {
33
25
  evidenceLimitBytes?: number;
34
26
  importLimitBytes?: number;
35
27
  now?: () => Date;
28
+ random?: () => number;
29
+ circuitBreakerThreshold?: CircuitBreakerThreshold;
36
30
  /**
37
31
  * API-key verifier (from `@hasna/contracts/auth`). When present, every
38
32
  * request outside the open foundation probes (`/health`, `/ready`,
39
- * `/version`, `/status`) must present a valid `loops:*` scoped key. This is
33
+ * `/version`, `/openapi.json`) must present a valid `loops:*` scoped key. This is
40
34
  * the internet-facing auth path (no bearer token, no loopback bypass).
41
35
  */
42
36
  authenticator?: ApiAuthenticator;
37
+ withTenantStorage?: <T>(principal: TenantAuthContext, fn: (storage: LoopStorageContract) => Promise<T>) => Promise<T>;
43
38
  /**
44
39
  * Readiness probe. Should prove the storage backend is reachable AND fully
45
- * migrated. Returns `{ ready, detail? }`. Defaults to a storage list probe.
40
+ * migrated. Returns a stable public code only. Defaults to a storage list probe.
46
41
  */
47
42
  readyCheck?: () => Promise<{
48
43
  ready: boolean;
49
- detail?: string;
44
+ code?: "storage_unconfigured" | "storage_unreachable" | "auth_unreachable" | "unsafe_database_role" | "pending_migrations" | "unknown_migrations" | "migration_checksum_mismatch";
50
45
  }>;
51
46
  }
47
+ export declare function contractHealthResponse(env?: Record<string, string | undefined>): {
48
+ status: "ok";
49
+ version: string;
50
+ mode: "local" | "cloud";
51
+ };
52
52
  export declare function createLoopsApiServer(opts?: LoopsApiServerOptions): Bun.Server<undefined>;
53
+ export declare function logApiCommandFailure(error: unknown): void;
53
54
  export declare function main(argv?: string[]): Promise<void>;