@hasna/infinity 0.1.0

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 (112) hide show
  1. package/LICENSE +3 -0
  2. package/README.md +331 -0
  3. package/dist/cli.js +2965 -0
  4. package/dist/http-api.js +6448 -0
  5. package/dist/index.js +28536 -0
  6. package/dist/migrate.js +346 -0
  7. package/dist/self-hosted-migrate.js +2064 -0
  8. package/dist/self-hosted.js +13180 -0
  9. package/dist/types/authcapsules/codewith-local.d.ts +109 -0
  10. package/dist/types/authcapsules/infinity-agent-policy.d.ts +57 -0
  11. package/dist/types/authcapsules/os-isolated-runner.d.ts +87 -0
  12. package/dist/types/authority/authority.d.ts +342 -0
  13. package/dist/types/authority/effect-journal.d.ts +205 -0
  14. package/dist/types/authority/mutation-journal.d.ts +163 -0
  15. package/dist/types/authority/mutation-tuple.d.ts +26 -0
  16. package/dist/types/authority/state.d.ts +75 -0
  17. package/dist/types/authority/store.d.ts +15 -0
  18. package/dist/types/brokers/checkpoint/archive.d.ts +21 -0
  19. package/dist/types/brokers/checkpoint/bundle.d.ts +22 -0
  20. package/dist/types/brokers/checkpoint/bytes.d.ts +4 -0
  21. package/dist/types/brokers/checkpoint/clean-verifier-finalization.d.ts +62 -0
  22. package/dist/types/brokers/checkpoint/clean-verifier.d.ts +145 -0
  23. package/dist/types/brokers/checkpoint/final-trust-authority.d.ts +55 -0
  24. package/dist/types/brokers/checkpoint/idempotency.d.ts +25 -0
  25. package/dist/types/brokers/checkpoint/journaled-store.d.ts +9 -0
  26. package/dist/types/brokers/checkpoint/manifest-signature.d.ts +135 -0
  27. package/dist/types/brokers/checkpoint/manifest.d.ts +57 -0
  28. package/dist/types/brokers/checkpoint/s3-store.d.ts +215 -0
  29. package/dist/types/brokers/checkpoint/seal-authority.d.ts +86 -0
  30. package/dist/types/brokers/checkpoint/service.d.ts +198 -0
  31. package/dist/types/brokers/checkpoint/signing-message.d.ts +22 -0
  32. package/dist/types/brokers/checkpoint/store.d.ts +76 -0
  33. package/dist/types/brokers/checkpoint/verifier-cleanup-authority.d.ts +108 -0
  34. package/dist/types/brokers/checkpoint/verifier-cleanup.d.ts +391 -0
  35. package/dist/types/brokers/checkpoint/verifier.d.ts +225 -0
  36. package/dist/types/brokers/composition.d.ts +86 -0
  37. package/dist/types/brokers/git/github-app.d.ts +216 -0
  38. package/dist/types/brokers/git/promotion.d.ts +418 -0
  39. package/dist/types/brokers/persistence/contracts.d.ts +77 -0
  40. package/dist/types/brokers/persistence/memory.d.ts +5 -0
  41. package/dist/types/brokers/persistence/migration.d.ts +6 -0
  42. package/dist/types/brokers/persistence/postgres.d.ts +74 -0
  43. package/dist/types/cli/main.d.ts +2 -0
  44. package/dist/types/cli/operation-journal.d.ts +47 -0
  45. package/dist/types/cli/run.d.ts +15 -0
  46. package/dist/types/client/operator-client.d.ts +100 -0
  47. package/dist/types/contracts/dtos.d.ts +198 -0
  48. package/dist/types/contracts/events.d.ts +45 -0
  49. package/dist/types/contracts/fence.d.ts +39 -0
  50. package/dist/types/contracts/operations.d.ts +91 -0
  51. package/dist/types/contracts/runspec.d.ts +75 -0
  52. package/dist/types/contracts/validators.d.ts +8 -0
  53. package/dist/types/core/clock.d.ts +12 -0
  54. package/dist/types/core/errors.d.ts +18 -0
  55. package/dist/types/core/ids.d.ts +10 -0
  56. package/dist/types/core/int64.d.ts +7 -0
  57. package/dist/types/core/strict-json.d.ts +8 -0
  58. package/dist/types/core/validation.d.ts +25 -0
  59. package/dist/types/golden/disposable-task.d.ts +108 -0
  60. package/dist/types/golden/source-pins.d.ts +77 -0
  61. package/dist/types/http/api.d.ts +52 -0
  62. package/dist/types/http/bearer-auth.d.ts +8 -0
  63. package/dist/types/http/main.d.ts +3 -0
  64. package/dist/types/http/self-hosted-main.d.ts +17 -0
  65. package/dist/types/index.d.ts +65 -0
  66. package/dist/types/mcp/schema.d.ts +7 -0
  67. package/dist/types/node-agent/agent.d.ts +174 -0
  68. package/dist/types/node-agent/contracts.d.ts +119 -0
  69. package/dist/types/node-agent/macos-service.d.ts +33 -0
  70. package/dist/types/node-agent/service-cli.d.ts +26 -0
  71. package/dist/types/persistence/composition.d.ts +49 -0
  72. package/dist/types/persistence/migrate-main.d.ts +2 -0
  73. package/dist/types/persistence/migrations.d.ts +30 -0
  74. package/dist/types/persistence/postgres-accounts-operation.d.ts +26 -0
  75. package/dist/types/persistence/postgres-authority.d.ts +69 -0
  76. package/dist/types/persistence/postgres-external-mutation-journal.d.ts +22 -0
  77. package/dist/types/persistence/postgres-json.d.ts +1 -0
  78. package/dist/types/persistence/postgres-mutation-journal.d.ts +31 -0
  79. package/dist/types/persistence/postgres-reconciler.d.ts +34 -0
  80. package/dist/types/persistence/postgres-sandbox-dispatch-authority.d.ts +9 -0
  81. package/dist/types/persistence/self-hosted-migrate-main.d.ts +2 -0
  82. package/dist/types/ports/accounts-operation.d.ts +336 -0
  83. package/dist/types/ports/accounts.d.ts +293 -0
  84. package/dist/types/ports/sandbox-dispatch-authority.d.ts +154 -0
  85. package/dist/types/ports/sandboxes.d.ts +40 -0
  86. package/dist/types/providers/sandbox-dispatch.d.ts +143 -0
  87. package/dist/types/runtime/config.d.ts +61 -0
  88. package/dist/types/runtime/postgres.d.ts +18 -0
  89. package/dist/types/runtime/provider-activation.d.ts +45 -0
  90. package/dist/types/runtime/server.d.ts +68 -0
  91. package/dist/types/testing/accounts-fake.d.ts +31 -0
  92. package/dist/types/testing/fakes.d.ts +2 -0
  93. package/dist/types/testing/node-control-plane-fake.d.ts +20 -0
  94. package/dist/types/testing/reference.d.ts +27 -0
  95. package/dist/types/testing/sandboxes-fake.d.ts +22 -0
  96. package/evidence/provider-live-daytona-v3.json +1 -0
  97. package/evidence/provider-live-e2b-v3.json +1 -0
  98. package/evidence/provider-production-route-daytona-v1.json +1 -0
  99. package/evidence/provider-production-route-e2b-v1.json +1 -0
  100. package/migrations/0001_authority.sql +689 -0
  101. package/migrations/0002_effect_step_global_owner.sql +2 -0
  102. package/migrations/0003_effect_journal_observed_head.sql +34 -0
  103. package/migrations/0004_authority_mutation_journal_binding.sql +15 -0
  104. package/migrations/20260710_checkpoint_broker_v1.sql +163 -0
  105. package/migrations/20260711_accounts_operation_v1.sql +137 -0
  106. package/migrations/20260711_checkpoint_trust_v2.sql +17 -0
  107. package/migrations/20260711_verifier_cleanup_v2.sql +169 -0
  108. package/migrations/20260711_z_accounts_claim_authority_v2.sql +172 -0
  109. package/migrations/20260711_zz_sandbox_dispatch_authority_v1.sql +143 -0
  110. package/migrations/20260712_sandbox_dispatch_authority_v2.sql +58 -0
  111. package/migrations/external-journal/0001_external_authority_mutation_journal.sql +175 -0
  112. package/package.json +47 -0
@@ -0,0 +1,100 @@
1
+ import type { Int64 } from "../core/int64";
2
+ export interface OperatorEnvelope {
3
+ schema_version: "infinity.operator/v1";
4
+ ok: boolean;
5
+ request_id: string;
6
+ command: string;
7
+ server_time: string;
8
+ operation_id?: string;
9
+ data?: unknown;
10
+ error?: {
11
+ code: string;
12
+ message: string;
13
+ retryable: boolean;
14
+ retry_after_ms: number | null;
15
+ details: Record<string, unknown>;
16
+ remediation: string;
17
+ };
18
+ warnings: unknown[];
19
+ next_actions: unknown[];
20
+ }
21
+ export declare function operatorEnvelopeHttpStatus(envelope: OperatorEnvelope): number | undefined;
22
+ export declare function inheritOperatorEnvelopeHttpStatus(source: OperatorEnvelope, target: OperatorEnvelope): OperatorEnvelope;
23
+ export interface SubmitRequest {
24
+ spec: unknown;
25
+ idempotencyKey: string;
26
+ operationId: string;
27
+ authorityEpoch: Int64;
28
+ routeLineageId: string;
29
+ routeId: string;
30
+ routeEpoch: Int64;
31
+ }
32
+ export interface ExistingRunRequest {
33
+ runId: string;
34
+ idempotencyKey: string;
35
+ operationId: string;
36
+ authorityEpoch: Int64;
37
+ ifRevision: number;
38
+ attemptId: string;
39
+ expectedAttemptNumber: number;
40
+ expectedAttemptRevision: number;
41
+ attemptLeaseId?: string;
42
+ leaseEpoch?: Int64;
43
+ }
44
+ export interface OperatorClient {
45
+ version(): Promise<OperatorEnvelope>;
46
+ doctor(): Promise<OperatorEnvelope>;
47
+ listCapabilities(): Promise<OperatorEnvelope>;
48
+ validateRun(spec: unknown): Promise<OperatorEnvelope>;
49
+ planRun(spec: unknown): Promise<OperatorEnvelope>;
50
+ submitRun(request: SubmitRequest): Promise<OperatorEnvelope>;
51
+ getRun(runId: string): Promise<OperatorEnvelope>;
52
+ listRuns(options: {
53
+ limit?: number;
54
+ cursor?: string;
55
+ }): Promise<OperatorEnvelope>;
56
+ waitRun(runId: string, timeoutMs: number): Promise<OperatorEnvelope>;
57
+ readRunEvents(runId: string, options: {
58
+ cursor: string;
59
+ limit: number;
60
+ waitMs: number;
61
+ }): Promise<OperatorEnvelope>;
62
+ cancelRun(request: ExistingRunRequest & {
63
+ reasonCode: string;
64
+ }): Promise<OperatorEnvelope>;
65
+ retryRun(request: ExistingRunRequest): Promise<OperatorEnvelope>;
66
+ authorizeSandboxDispatch(request: unknown): Promise<OperatorEnvelope>;
67
+ dispatchProductionSandbox(request: unknown): Promise<OperatorEnvelope>;
68
+ resolveOperation(operationId: string): Promise<OperatorEnvelope>;
69
+ }
70
+ export declare class OperatorHttpClient implements OperatorClient {
71
+ private readonly fetchImpl;
72
+ private readonly endpoint;
73
+ constructor(endpoint: string, fetchImpl?: typeof fetch);
74
+ version(): Promise<OperatorEnvelope>;
75
+ doctor(): Promise<OperatorEnvelope>;
76
+ listCapabilities(): Promise<OperatorEnvelope>;
77
+ validateRun(spec: unknown): Promise<OperatorEnvelope>;
78
+ planRun(spec: unknown): Promise<OperatorEnvelope>;
79
+ submitRun(request: SubmitRequest): Promise<OperatorEnvelope>;
80
+ getRun(runId: string): Promise<OperatorEnvelope>;
81
+ listRuns(options: {
82
+ limit?: number;
83
+ cursor?: string;
84
+ }): Promise<OperatorEnvelope>;
85
+ waitRun(runId: string, timeoutMs: number): Promise<OperatorEnvelope>;
86
+ readRunEvents(runId: string, options: {
87
+ cursor: string;
88
+ limit: number;
89
+ waitMs: number;
90
+ }): Promise<OperatorEnvelope>;
91
+ cancelRun(request: ExistingRunRequest & {
92
+ reasonCode: string;
93
+ }): Promise<OperatorEnvelope>;
94
+ retryRun(request: ExistingRunRequest): Promise<OperatorEnvelope>;
95
+ authorizeSandboxDispatch(request: unknown): Promise<OperatorEnvelope>;
96
+ dispatchProductionSandbox(request: unknown): Promise<OperatorEnvelope>;
97
+ resolveOperation(operationId: string): Promise<OperatorEnvelope>;
98
+ private request;
99
+ }
100
+ export declare function isOperatorPreReservationFailure(envelope: OperatorEnvelope): boolean;
@@ -0,0 +1,198 @@
1
+ import type { RunSpec } from "./runspec";
2
+ import type { Int64 } from "../core/int64";
3
+ export type RunState = "admitted" | "active" | "cancel_requested" | "finalizing" | "succeeded" | "failed" | "canceled" | "lost_uncheckpointed" | "discarded_uncheckpointed";
4
+ export type AttemptPhase = "queued" | "lane_leased" | "sandbox_allocating" | "running" | "checkpointed" | "verifying" | "finalizing" | "terminal";
5
+ export type AttemptOutcome = "succeeded" | "failed_retryable" | "failed_permanent" | "canceled" | "lost_uncheckpointed" | "discarded_uncheckpointed" | "policy_denied" | "budget_exhausted";
6
+ export type CancellationState = "none" | "requested" | "fenced" | "cleanup_pending" | "complete";
7
+ export interface RunSpecRecord {
8
+ id: string;
9
+ digest: string;
10
+ canonical_spec: RunSpec;
11
+ schema_version: string;
12
+ canonicalization_version: string;
13
+ admitted_at: string;
14
+ }
15
+ export interface RunRecord {
16
+ id: string;
17
+ run_spec_id: string;
18
+ run_spec_digest: string;
19
+ route_lineage_id: string;
20
+ route_id: string;
21
+ route_epoch: Int64;
22
+ admitted_authority_epoch: Int64;
23
+ logical_work_key: string;
24
+ owner_principal: string;
25
+ project_id: string;
26
+ repository_id: string;
27
+ current_attempt_id: string;
28
+ state: RunState;
29
+ terminal_outcome: AttemptOutcome | null;
30
+ revision: number;
31
+ next_event_sequence: number;
32
+ created_at: string;
33
+ updated_at: string;
34
+ }
35
+ export interface AttemptRecord {
36
+ id: string;
37
+ run_id: string;
38
+ attempt_number: number;
39
+ phase: AttemptPhase;
40
+ outcome: AttemptOutcome | null;
41
+ pending_outcome: AttemptOutcome | null;
42
+ runner_principal: string | null;
43
+ attempt_lease_id?: string;
44
+ lease_epoch?: Int64;
45
+ lease_holder_principal?: string;
46
+ lease_expires_at?: string;
47
+ cancellation_state: CancellationState;
48
+ retry_cause: string | null;
49
+ terminal_reason: string | null;
50
+ revision: number;
51
+ created_at: string;
52
+ updated_at: string;
53
+ }
54
+ export interface AttemptLeaseGrant {
55
+ attempt_lease_id: string;
56
+ attempt_id: string;
57
+ run_id: string;
58
+ lease_epoch: Int64;
59
+ lease_holder_principal: string;
60
+ audience: string;
61
+ issued_at: string;
62
+ lease_expires_at: string;
63
+ grant_digest: string;
64
+ kind: "worker" | "cancel_recovery";
65
+ }
66
+ export interface AttemptLeaseEvent {
67
+ id: string;
68
+ attempt_lease_id: string;
69
+ attempt_id: string;
70
+ lease_epoch: Int64;
71
+ kind: "granted" | "renewed" | "fenced" | "released" | "expired";
72
+ actor_principal: string;
73
+ database_time: string;
74
+ detail_digest: string;
75
+ }
76
+ export interface QueueEntry {
77
+ attempt_id: string;
78
+ run_id: string;
79
+ project_id: string;
80
+ lane_pool_id: string;
81
+ enqueue_sequence: number;
82
+ admitted_at: string;
83
+ state: "queued" | "reserved" | "removed";
84
+ }
85
+ export interface LaneSlot {
86
+ lane_pool_id: string;
87
+ capacity_generation: Int64;
88
+ slot_index: number;
89
+ slot_id: string;
90
+ }
91
+ export interface LaneReservation {
92
+ id: string;
93
+ resource_id: string;
94
+ resource_lifecycle_generation: Int64;
95
+ slot_id: string;
96
+ attempt_id: string;
97
+ run_id: string;
98
+ route_epoch: Int64;
99
+ lease_epoch: Int64;
100
+ acquisition_operation_id: string;
101
+ slot_eligibility_request_digest: string;
102
+ slot_eligibility_id: string;
103
+ slot_eligibility_jcs_base64url: string;
104
+ slot_eligibility_digest: string;
105
+ access_target_digest: string;
106
+ effect_namespace_id: string;
107
+ provider_account_id: string;
108
+ owner_ref: string;
109
+ account_lane_id: string;
110
+ capacity_pool_id: string;
111
+ capacity_domain_ref: string;
112
+ serialization_key: string;
113
+ serialization_key_digest: string;
114
+ credential_family_id: string;
115
+ max_concurrency: Int64;
116
+ capacity_generation: Int64;
117
+ deny_generation: Int64;
118
+ credential_generation: Int64;
119
+ state: "reserved" | "released" | "fenced";
120
+ created_at: string;
121
+ updated_at: string;
122
+ }
123
+ export interface AdmissionKeyRecord {
124
+ route_lineage_id: string;
125
+ logical_work_key: string;
126
+ run_spec_digest: string;
127
+ run_id: string;
128
+ disposition: "admitted" | "tombstone";
129
+ created_at: string;
130
+ }
131
+ export interface IdempotencyRecord {
132
+ operation_id: string;
133
+ actor_principal: string;
134
+ command: string;
135
+ scope: string;
136
+ idempotency_key: string;
137
+ request_hash: string;
138
+ state: "in_flight" | "committed" | "aborted";
139
+ result: unknown;
140
+ created_at: string;
141
+ updated_at: string;
142
+ }
143
+ export type ApprovalState = "pending" | "approved" | "denied" | "consumed" | "expired" | "revoked";
144
+ export type ApprovalDecisionVerb = "approve" | "deny";
145
+ export interface ApprovalRequestRecord {
146
+ id: string;
147
+ run_id: string;
148
+ run_revision: number;
149
+ run_spec_digest: string;
150
+ route_lineage_id: string;
151
+ route_id: string;
152
+ route_epoch: Int64;
153
+ attempt_id: string;
154
+ attempt_lease_id?: string;
155
+ lease_epoch?: Int64;
156
+ expected_base_sha: string;
157
+ operation_digest: string;
158
+ proposal_digest: string;
159
+ action: "create_broker_branch_and_pr";
160
+ evidence_digests: string[];
161
+ maximum_effect: "draft_pull_request";
162
+ requester_principal: string;
163
+ required_human_role: "repository_approver";
164
+ expires_at: string;
165
+ state: ApprovalState;
166
+ decision_verb: ApprovalDecisionVerb | null;
167
+ decision_principal: string | null;
168
+ decision_operation_id: string | null;
169
+ revision: number;
170
+ created_at: string;
171
+ updated_at: string;
172
+ }
173
+ export interface AuthorizationUseRecord {
174
+ id: string;
175
+ approval_id: string;
176
+ operation_id: string;
177
+ operation_digest: string;
178
+ actor_principal: string;
179
+ run_id: string;
180
+ attempt_id: string;
181
+ attempt_lease_id?: string;
182
+ lease_epoch?: Int64;
183
+ authority_epoch: Int64;
184
+ used_at: string;
185
+ }
186
+ export interface CheckpointRecord {
187
+ id: string;
188
+ run_id: string;
189
+ attempt_id: string;
190
+ seal_digest: string;
191
+ state: "sealed" | "integrity_failed";
192
+ }
193
+ export interface BudgetState {
194
+ limit_units: number;
195
+ reserved_units: number;
196
+ charged_units: number;
197
+ released_units: number;
198
+ }
@@ -0,0 +1,45 @@
1
+ import type { Int64 } from "../core/int64";
2
+ export interface AuthorityEvent {
3
+ event_id: string;
4
+ authority_commit_sequence: Int64;
5
+ operation_id: string;
6
+ operation_digest: string;
7
+ aggregate_type: "run" | "approval" | "lane";
8
+ aggregate_id: string;
9
+ aggregate_sequence: number;
10
+ run_id: string | null;
11
+ run_sequence: number | null;
12
+ actor_principal: string;
13
+ authority_epoch: Int64;
14
+ route_lineage_id: string | null;
15
+ route_id: string | null;
16
+ route_epoch: Int64 | null;
17
+ attempt_id: string | null;
18
+ lease_epoch: Int64 | null;
19
+ attempt_lease_id: string | null;
20
+ lease_holder_principal: string | null;
21
+ audience: string | null;
22
+ resource_lease_id: string | null;
23
+ resource_id: string | null;
24
+ resource_lifecycle_generation: Int64 | null;
25
+ operation_executor_principal: string | null;
26
+ event_schema: "infinity.event/v1";
27
+ event_type: string;
28
+ payload: Record<string, unknown>;
29
+ payload_digest: string;
30
+ prior_event_digest: string | null;
31
+ event_digest: string;
32
+ database_time: string;
33
+ }
34
+ export interface OutboxRow {
35
+ id: string;
36
+ event_id: string;
37
+ destination: "projection";
38
+ projection_version: "v1";
39
+ outbox_identity_digest: string;
40
+ payload_digest: string;
41
+ state: "held" | "pending" | "leased" | "delivered" | "blocked";
42
+ authority_commit_sequence: Int64;
43
+ created_at: string;
44
+ }
45
+ export declare function eventDigest(event: AuthorityEvent): string;
@@ -0,0 +1,39 @@
1
+ import { type Int64 } from "../core/int64";
2
+ export declare const BROKER_FENCE_FIELDS: readonly ["authority_epoch", "route_lineage_id", "route_id", "route_epoch", "run_id", "attempt_id", "attempt_lease_id", "lease_epoch", "lease_holder_principal", "resource_lease_id", "resource_id", "resource_lifecycle_generation", "operation_id", "operation_digest", "operation_execution_epoch", "actor_principal", "operation_executor_principal", "audience", "issued_at", "lease_expires_at", "operation_execution_expires_at"];
3
+ export declare const BROKER_FENCE_SCHEMA_VERSION: "infinity.broker-fence.v1";
4
+ export declare const BROKER_FENCE_WIRE_FIELDS: readonly ["schema_version", "authority_epoch", "route_lineage_id", "route_id", "route_epoch", "run_id", "attempt_id", "attempt_lease_id", "lease_epoch", "lease_holder_principal", "resource_lease_id", "resource_id", "resource_lifecycle_generation", "operation_id", "operation_digest", "operation_execution_epoch", "actor_principal", "operation_executor_principal", "audience", "issued_at", "lease_expires_at", "operation_execution_expires_at"];
5
+ export declare const REJECTED_FENCE_ALIASES: readonly ["authority_generation", "authority_incarnation", "route_authority_epoch", "producer_epoch", "attempt_lease_epoch", "cancellation_generation", "allocation_generation", "lifecycle_revision"];
6
+ export interface BrokerFenceInput {
7
+ schema_version: typeof BROKER_FENCE_SCHEMA_VERSION;
8
+ authority_epoch: Int64;
9
+ route_lineage_id: string;
10
+ route_id: string;
11
+ route_epoch: Int64;
12
+ run_id: string;
13
+ attempt_id: string;
14
+ attempt_lease_id: string;
15
+ lease_epoch: Int64;
16
+ lease_holder_principal: string;
17
+ resource_lease_id: string;
18
+ resource_id: string;
19
+ resource_lifecycle_generation: Int64;
20
+ operation_id: string;
21
+ operation_digest: string;
22
+ operation_execution_epoch: Int64;
23
+ actor_principal: string;
24
+ operation_executor_principal: string;
25
+ audience: string;
26
+ issued_at: string;
27
+ lease_expires_at: string;
28
+ operation_execution_expires_at: string;
29
+ }
30
+ export type BrokerFence = Readonly<BrokerFenceInput>;
31
+ export declare function parseBrokerFence(value: unknown): BrokerFence;
32
+ export interface AuthenticatedFenceContext {
33
+ databaseTime: Date;
34
+ actorPrincipal: string;
35
+ leaseHolderPrincipal: string;
36
+ operationExecutorPrincipal: string;
37
+ audience: string;
38
+ }
39
+ export declare function assertFenceCurrent(candidate: BrokerFence, current: BrokerFence, authenticated: AuthenticatedFenceContext): void;
@@ -0,0 +1,91 @@
1
+ import { type Int64 } from "../core/int64";
2
+ import type { BrokerFence } from "./fence";
3
+ export type ExternalOperationState = "planned" | "intent_committed" | "prepared" | "dispatched" | "succeeded" | "failed_effect" | "failed_no_effect" | "unknown" | "suppressed" | "quarantined";
4
+ export interface ExternalOperation {
5
+ id: string;
6
+ kind: "sandbox_create_inert" | "sandbox_activate" | "checkpoint_seal" | "verification" | "promotion" | "typed_cleanup";
7
+ digest: string;
8
+ fence: BrokerFence;
9
+ broker_audience: string;
10
+ provider_idempotency_token: string;
11
+ operation_execution_epoch: Int64;
12
+ operation_executor_principal: string;
13
+ operation_execution_expires_at: string;
14
+ state: ExternalOperationState;
15
+ attempt_count: number;
16
+ not_after: string;
17
+ receipt_digests: string[];
18
+ reconciliation_result: "not_started" | "definitive" | "unknown_requires_review";
19
+ }
20
+ export type PublicMutationCommand = "run.submit" | "run.cancel" | "run.retry";
21
+ export declare const MAX_POSTGRES_INTEGER = 2147483647;
22
+ export declare const MAX_REVISION = 2147483647;
23
+ export declare const MAX_MUTABLE_IF_REVISION: number;
24
+ export declare const CANCEL_RECOVERY_LEASE_DURATION_MS = 300000;
25
+ export type PublicMutationResultExpectation = {
26
+ command: "run.submit";
27
+ run_spec_digest: string;
28
+ authority_epoch: Int64;
29
+ route_epoch: Int64;
30
+ } | {
31
+ command: "run.cancel";
32
+ run_id: string;
33
+ attempt_id: string;
34
+ attempt_number: number;
35
+ expected_run_revision: number;
36
+ expected_attempt_revision: number;
37
+ recovery_lease_duration_ms: typeof CANCEL_RECOVERY_LEASE_DURATION_MS;
38
+ prior_lease: {
39
+ state: "none";
40
+ } | {
41
+ state: "selected";
42
+ attempt_lease_id: string;
43
+ lease_epoch: Int64;
44
+ };
45
+ } | {
46
+ command: "run.retry";
47
+ run_id: string;
48
+ predecessor_attempt_id: string;
49
+ expected_attempt_number: number;
50
+ expected_run_revision: number;
51
+ };
52
+ export interface OperationBinding {
53
+ command: string;
54
+ idempotency_key: string;
55
+ scope_digest: string;
56
+ request_hash: string;
57
+ }
58
+ export type OperationResolution = {
59
+ operation_id: string;
60
+ status: "unknown";
61
+ } | {
62
+ operation_id: string;
63
+ status: "in_flight" | "aborted";
64
+ operation_binding: OperationBinding;
65
+ } | {
66
+ operation_id: string;
67
+ status: "committed";
68
+ operation_binding: OperationBinding;
69
+ result: unknown;
70
+ };
71
+ export interface PublicOperationBinding extends OperationBinding {
72
+ command: PublicMutationCommand;
73
+ }
74
+ export type PublicOperationResolution = {
75
+ operation_id: string;
76
+ status: "unknown";
77
+ } | {
78
+ operation_id: string;
79
+ status: "in_flight" | "aborted";
80
+ operation_binding: PublicOperationBinding;
81
+ } | {
82
+ operation_id: string;
83
+ status: "committed";
84
+ operation_binding: PublicOperationBinding;
85
+ result: Readonly<Record<string, unknown>>;
86
+ };
87
+ export declare function isPublicMutationCommand(value: unknown): value is PublicMutationCommand;
88
+ export declare function parsePublicMutationResultExpectation(value: unknown): Readonly<PublicMutationResultExpectation>;
89
+ export declare function parsePublicMutationResult(command: PublicMutationCommand, value: unknown, expectedOperationId: string, expectation?: PublicMutationResultExpectation): Readonly<Record<string, unknown>>;
90
+ export declare function assertStoredMutationResult(command: string, value: unknown, expectedOperationId: string, expectation?: PublicMutationResultExpectation): void;
91
+ export declare function parsePublicOperationResolution(value: unknown, expectedOperationId: string, expectation?: PublicMutationResultExpectation): Readonly<PublicOperationResolution>;
@@ -0,0 +1,75 @@
1
+ export interface RunSpecInput {
2
+ api_version: string;
3
+ kind: string;
4
+ canonicalization_version: string;
5
+ metadata: {
6
+ project_id: string;
7
+ logical_work_key: string;
8
+ };
9
+ source: {
10
+ repository_id: string;
11
+ object_format: string;
12
+ commit_sha: string;
13
+ expected_base_sha: string;
14
+ };
15
+ environment: {
16
+ image_digest: string;
17
+ };
18
+ policy: {
19
+ data_class: string;
20
+ capabilities?: string[];
21
+ network_policy_digest: string;
22
+ lane_policy_class: string;
23
+ budget: {
24
+ wall_time_ms: number;
25
+ resource_units: number;
26
+ cost_minor_units: number;
27
+ };
28
+ approval_policy_id: string;
29
+ retry_policy?: {
30
+ max_attempts: number;
31
+ retryable_reasons: string[];
32
+ };
33
+ cancellation_policy_id: string;
34
+ checkpoint_policy_id: string;
35
+ verification_policy_id: string;
36
+ cleanup_policy_id: string;
37
+ steering: {
38
+ allowed_media_types: string[];
39
+ max_bytes: number;
40
+ };
41
+ policy_decision_digest: string;
42
+ repository_automation_policy_digest: string;
43
+ };
44
+ task: {
45
+ input_artifacts?: Array<{
46
+ artifact_id: string;
47
+ digest: string;
48
+ }>;
49
+ expected_outputs: string[];
50
+ expected_evidence: string[];
51
+ };
52
+ }
53
+ export interface RunSpec extends Omit<RunSpecInput, "policy" | "task"> {
54
+ policy: Omit<RunSpecInput["policy"], "capabilities" | "retry_policy"> & {
55
+ capabilities: string[];
56
+ retry_policy: {
57
+ max_attempts: number;
58
+ retryable_reasons: string[];
59
+ };
60
+ };
61
+ task: Omit<RunSpecInput["task"], "input_artifacts"> & {
62
+ input_artifacts: Array<{
63
+ artifact_id: string;
64
+ digest: string;
65
+ }>;
66
+ };
67
+ }
68
+ /**
69
+ * Closed transport schema for tools that accept a RunSpec. Runtime admission
70
+ * still passes through strict JSON provenance and parseRunSpec; this schema is
71
+ * the fail-closed discovery contract, not a replacement for those checks.
72
+ */
73
+ export declare const RUN_SPEC_INPUT_SCHEMA: Readonly<Record<string, unknown>>;
74
+ export declare function parseRunSpec(value: unknown): Readonly<RunSpec>;
75
+ export declare function runSpecDigest(spec: RunSpec): string;
@@ -0,0 +1,8 @@
1
+ import type { AttemptRecord, RunRecord } from "./dtos";
2
+ import { type AuthorityEvent, type OutboxRow } from "./events";
3
+ import { type ExternalOperation } from "./operations";
4
+ export declare function parseRunRecord(value: unknown): Readonly<RunRecord>;
5
+ export declare function parseAttemptRecord(value: unknown): Readonly<AttemptRecord>;
6
+ export declare function parseExternalOperation(value: unknown): Readonly<ExternalOperation>;
7
+ export declare function parseAuthorityEvent(value: unknown): Readonly<AuthorityEvent>;
8
+ export declare function parseOutboxRow(value: unknown): Readonly<OutboxRow>;
@@ -0,0 +1,12 @@
1
+ export interface Clock {
2
+ now(): Date;
3
+ }
4
+ export declare class SystemClock implements Clock {
5
+ now(): Date;
6
+ }
7
+ export declare class FakeClock implements Clock {
8
+ private current;
9
+ constructor(current?: Date);
10
+ now(): Date;
11
+ advance(milliseconds: number): void;
12
+ }
@@ -0,0 +1,18 @@
1
+ export type InfinityErrorCode = "invalid_input" | "not_found" | "idempotency_key_reused" | "operation_id_conflict" | "logical_work_conflict" | "authority_epoch_mismatch" | "stale_revision" | "stale_lease_epoch" | "state_conflict" | "policy_denied" | "approval_required" | "approval_digest_mismatch" | "capability_denied" | "integrity_failure" | "capacity_unavailable" | "protocol_incompatible" | "internal_error";
2
+ export declare class InfinityError extends Error {
3
+ readonly code: InfinityErrorCode;
4
+ readonly status: number;
5
+ readonly retryable: boolean;
6
+ readonly details: Readonly<Record<string, unknown>>;
7
+ constructor(code: InfinityErrorCode, message: string, options?: {
8
+ status?: number;
9
+ retryable?: boolean;
10
+ details?: Record<string, unknown>;
11
+ cause?: unknown;
12
+ });
13
+ }
14
+ export declare class SimulatedCrashError extends Error {
15
+ readonly stage: "before_commit" | "after_commit";
16
+ constructor(stage: "before_commit" | "after_commit");
17
+ }
18
+ export declare function invariant(condition: unknown, message: string): asserts condition;
@@ -0,0 +1,10 @@
1
+ export interface IdFactory {
2
+ next(prefix: string): string;
3
+ }
4
+ export declare class RandomIdFactory implements IdFactory {
5
+ next(prefix: string): string;
6
+ }
7
+ export declare class DeterministicIdFactory implements IdFactory {
8
+ private sequence;
9
+ next(prefix: string): string;
10
+ }
@@ -0,0 +1,7 @@
1
+ export type Int64 = number | bigint;
2
+ export declare const INT64_MAX = 9223372036854775807n;
3
+ export declare function positiveInt64(value: unknown, label: string): Int64;
4
+ export declare function nonnegativeInt64(value: unknown, label: string): Int64;
5
+ export declare function incrementInt64(value: Int64, label: string): Int64;
6
+ export declare function int64Compare(left: Int64, right: Int64): -1 | 0 | 1;
7
+ export declare function int64Equal(left: Int64, right: Int64): boolean;
@@ -0,0 +1,8 @@
1
+ export type JsonPrimitive = null | boolean | number | bigint | string;
2
+ export type JsonValue = JsonPrimitive | JsonValue[] | {
3
+ [key: string]: JsonValue;
4
+ };
5
+ export declare function parseStrictJson(source: string): JsonValue;
6
+ export declare function assertStrictJsonDocument(value: unknown): asserts value is JsonValue;
7
+ export declare function canonicalJson(value: unknown): string;
8
+ export declare function digestCanonical(value: unknown): string;
@@ -0,0 +1,25 @@
1
+ import { InfinityError } from "./errors";
2
+ export declare function isPlainObject(value: unknown): value is Record<string, unknown>;
3
+ export declare function closedObject(value: unknown, label: string, required: readonly string[], optional?: readonly string[]): Record<string, unknown>;
4
+ export declare function stringValue(value: unknown, label: string, options?: {
5
+ min?: number;
6
+ max?: number;
7
+ pattern?: RegExp;
8
+ }): string;
9
+ export declare const IDENTIFIER_PATTERN: RegExp;
10
+ export declare const DIGEST_PATTERN: RegExp;
11
+ export declare const CREDENTIAL_CARRIER_PATTERN_SOURCE = "^(?:[sS][kK]-[A-Za-z0-9]|[gG][hH][pPoOuUsSrR]_|[gG][iI][tT][hH][uU][bB]_[pP][aA][tT]_|[xX][oO][xX][bBaApPrRsS]-|[aA][kKsS][iI][aA][0-9A-Za-z]|[aA][iI][zZ][aA]|[nN][pP][mM]_|[xX][aA][iI]-|[cC][tT][xX]7[sS][kK]-)";
12
+ export declare function identifier(value: unknown, label: string): string;
13
+ export declare function digest(value: unknown, label: string): string;
14
+ export declare function positiveInteger(value: unknown, label: string, maximum?: number): number;
15
+ export declare function nonnegativeInteger(value: unknown, label: string, maximum?: number): number;
16
+ export declare function enumValue<T extends string>(value: unknown, label: string, values: readonly T[]): T;
17
+ export declare function stringArray(value: unknown, label: string, options?: {
18
+ maxItems?: number;
19
+ item?: (entry: unknown, label: string) => string;
20
+ allowEmpty?: boolean;
21
+ }): string[];
22
+ export declare function timestamp(value: unknown, label: string): string;
23
+ export declare function invalid(message: string): InfinityError;
24
+ export declare function deepClone<T>(value: T): T;
25
+ export declare function deepFreeze<T>(value: T): T;