@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,109 @@
1
+ import { type InfinityAgentPolicy } from "./infinity-agent-policy";
2
+ import { type BrokerFence } from "../contracts/fence";
3
+ import type { SlotEligibility } from "../ports/accounts";
4
+ export declare const AUTH_CAPSULE_DESCRIPTOR_SCHEMA_VERSION: "infinity.auth-capsule-descriptor.v2";
5
+ export declare const CAPSULE_REMOTE_TOOL_BINDING_SCHEMA_VERSION: "infinity.capsule-remote-tool-binding.v1";
6
+ export interface AuthCapsuleDescriptor {
7
+ readonly schema_version: typeof AUTH_CAPSULE_DESCRIPTOR_SCHEMA_VERSION;
8
+ readonly auth_capsule_id: string;
9
+ readonly owner_ref: string;
10
+ readonly provider_key: string;
11
+ readonly provider_subject_ref: string;
12
+ readonly capacity_domain_ref: string;
13
+ readonly account_lane_id: string;
14
+ readonly canonical_node_id: string;
15
+ readonly node_key_thumbprint: string;
16
+ readonly node_generation: string;
17
+ readonly placement_generation: string;
18
+ readonly auth_generation: string;
19
+ readonly auth_state_revision: string;
20
+ readonly accounts_revision_set_digest: string;
21
+ readonly capsule_attestation_digest: string;
22
+ /** Opaque lookup key for a trusted host-local registry; never an auth path or credential. */
23
+ readonly local_profile_ref: string;
24
+ readonly codewith_binary_sha256: string;
25
+ readonly runtime_policy_sha256: string;
26
+ readonly infinity_agent_policy_sha256: string;
27
+ }
28
+ export interface AuthCapsuleLocalProfileReference {
29
+ readonly local_profile_ref: string;
30
+ readonly codewith_binary_sha256: string;
31
+ readonly runtime_policy_sha256: string;
32
+ readonly infinity_agent_policy_sha256: string;
33
+ }
34
+ export interface CapsuleRemoteToolBinding {
35
+ readonly schema_version: typeof CAPSULE_REMOTE_TOOL_BINDING_SCHEMA_VERSION;
36
+ readonly dispatch_id: string;
37
+ readonly canonical_intent_sha256: string;
38
+ readonly sandbox_prepare_anchor_sha256: string;
39
+ readonly authority_envelope_sha256: string;
40
+ readonly effect_claim_sha256: string;
41
+ readonly operation_digest: string;
42
+ readonly provider: "e2b" | "daytona";
43
+ readonly source_manifest_sha256: string;
44
+ readonly input_manifest_sha256: string;
45
+ readonly checkpoint_policy_sha256: string;
46
+ readonly fence: BrokerFence;
47
+ }
48
+ export interface CodewithLocalProfile {
49
+ readonly executable_path: string;
50
+ readonly codewith_home: string;
51
+ readonly empty_workspace_path: string;
52
+ readonly auth_profile_name: string;
53
+ readonly runtime_profile_name: "infinity-agent";
54
+ readonly infinity_agent_policy_path: string;
55
+ /** Expected values are checked against actual bytes; registry claims are not trusted. */
56
+ readonly codewith_binary_sha256?: string;
57
+ readonly runtime_policy_sha256?: string;
58
+ readonly infinity_agent_policy_sha256?: string;
59
+ }
60
+ export interface CodewithLocalProfileRegistry {
61
+ resolve(descriptor: AuthCapsuleDescriptor): Promise<CodewithLocalProfile>;
62
+ }
63
+ export interface AuthCapsuleLaunchAuthorityPort {
64
+ /** Must perform final online run-fence and Accounts deny/generation checks. */
65
+ assertCurrent(input: Readonly<{
66
+ descriptor: AuthCapsuleDescriptor;
67
+ binding: CapsuleRemoteToolBinding;
68
+ }>): Promise<void>;
69
+ }
70
+ export interface CapsuleRemoteToolBridgeSession {
71
+ close(): Promise<void>;
72
+ }
73
+ export interface CapsuleRemoteToolBridgePort {
74
+ /**
75
+ * Opens a protected, no-secret bridge outside the Codewith PID/UID/mount domain.
76
+ * The static infinity-agent profile can reach only this bridge; it receives no
77
+ * bearer, endpoint, credential, or caller-selected command from this method.
78
+ */
79
+ open(input: Readonly<{
80
+ descriptor: AuthCapsuleDescriptor;
81
+ binding: CapsuleRemoteToolBinding;
82
+ policy: InfinityAgentPolicy;
83
+ }>): Promise<CapsuleRemoteToolBridgeSession>;
84
+ }
85
+ export interface CodewithAuthCapsuleLaunchRequest {
86
+ readonly descriptor: AuthCapsuleDescriptor;
87
+ readonly binding: CapsuleRemoteToolBinding;
88
+ readonly prompt: string;
89
+ }
90
+ export interface CodewithAuthCapsuleLaunchResult {
91
+ readonly schema_version: "infinity.codewith-auth-capsule-result.v1";
92
+ readonly exit_code: number;
93
+ readonly stdout: string;
94
+ readonly stderr: string;
95
+ readonly descriptor_sha256: string;
96
+ readonly binding_sha256: string;
97
+ }
98
+ export declare function parseAuthCapsuleDescriptor(value: unknown): AuthCapsuleDescriptor;
99
+ export declare function authCapsuleDescriptorFromEligibility(eligibility: SlotEligibility, local: AuthCapsuleLocalProfileReference): AuthCapsuleDescriptor;
100
+ export declare function parseCapsuleRemoteToolBinding(value: unknown): CapsuleRemoteToolBinding;
101
+ export declare class LocalCodewithAuthCapsuleLauncher {
102
+ #private;
103
+ constructor(dependencies: {
104
+ registry: CodewithLocalProfileRegistry;
105
+ authority: AuthCapsuleLaunchAuthorityPort;
106
+ bridge: CapsuleRemoteToolBridgePort;
107
+ });
108
+ launch(request: CodewithAuthCapsuleLaunchRequest): Promise<CodewithAuthCapsuleLaunchResult>;
109
+ }
@@ -0,0 +1,57 @@
1
+ import type { AuthCapsuleDescriptor, CapsuleRemoteToolBinding } from "./codewith-local";
2
+ export declare const INFINITY_AGENT_POLICY_SCHEMA_VERSION: "infinity.codewith-agent-policy.v1";
3
+ export declare const CAPSULE_REMOTE_CAPABILITIES: readonly ["sandbox.checkpoint.request", "sandbox.exec", "sandbox.file.read", "sandbox.file.write"];
4
+ export type CapsuleRemoteCapability = typeof CAPSULE_REMOTE_CAPABILITIES[number];
5
+ export interface InfinityAgentPolicy {
6
+ readonly schema_version: typeof INFINITY_AGENT_POLICY_SCHEMA_VERSION;
7
+ readonly profile: "infinity-agent";
8
+ readonly enforcement: "codewith-native-v1";
9
+ readonly environment_inherit: "none";
10
+ readonly history_persistence: "none";
11
+ readonly ephemeral: true;
12
+ readonly host_filesystem_access: false;
13
+ readonly host_shell_access: false;
14
+ readonly direct_network_access: false;
15
+ readonly auth_profile_control: false;
16
+ readonly allowed_capabilities: readonly CapsuleRemoteCapability[];
17
+ }
18
+ export declare function parseInfinityAgentPolicy(value: unknown): InfinityAgentPolicy;
19
+ export declare function infinityAgentPolicyDigest(value: unknown): string;
20
+ export interface CapsuleRemoteToolCall {
21
+ readonly request_id: string;
22
+ readonly capability: CapsuleRemoteCapability;
23
+ readonly input: Readonly<Record<string, unknown>>;
24
+ }
25
+ export interface CapsuleRemoteToolAuthorityPort {
26
+ assertCurrent(input: Readonly<{
27
+ descriptor: AuthCapsuleDescriptor;
28
+ binding: CapsuleRemoteToolBinding;
29
+ policy: InfinityAgentPolicy;
30
+ capability?: CapsuleRemoteCapability;
31
+ }>): Promise<void>;
32
+ }
33
+ export interface CapsuleRemoteToolBackendPort {
34
+ invoke(input: Readonly<{
35
+ descriptor: AuthCapsuleDescriptor;
36
+ binding: CapsuleRemoteToolBinding;
37
+ capability: CapsuleRemoteCapability;
38
+ request_id: string;
39
+ input: Readonly<Record<string, unknown>>;
40
+ }>): Promise<unknown>;
41
+ }
42
+ export interface ProtectedCapsuleRemoteToolSession {
43
+ invoke(call: CapsuleRemoteToolCall): Promise<unknown>;
44
+ close(): Promise<void>;
45
+ }
46
+ export declare class ProtectedCapsuleRemoteToolBridge {
47
+ #private;
48
+ constructor(dependencies: {
49
+ authority: CapsuleRemoteToolAuthorityPort;
50
+ backend: CapsuleRemoteToolBackendPort;
51
+ });
52
+ open(input: Readonly<{
53
+ descriptor: AuthCapsuleDescriptor;
54
+ binding: CapsuleRemoteToolBinding;
55
+ policy: unknown;
56
+ }>): Promise<ProtectedCapsuleRemoteToolSession>;
57
+ }
@@ -0,0 +1,87 @@
1
+ import type { AuthCapsuleDescriptor, AuthCapsuleLaunchAuthorityPort, CapsuleRemoteToolBinding, CapsuleRemoteToolBridgePort } from "./codewith-local";
2
+ export declare const SUBSCRIPTION_CAPSULE_ATTESTATION_SCHEMA_VERSION: "infinity.subscription-capsule-attestation.v1";
3
+ export type MacOsVmDriver = "tart" | "lume" | "virtualization-framework";
4
+ export interface SubscriptionCapsuleAttestation {
5
+ readonly schema_version: typeof SUBSCRIPTION_CAPSULE_ATTESTATION_SCHEMA_VERSION;
6
+ readonly provider: "linux-bubblewrap" | "macos-vm";
7
+ readonly driver: "bubblewrap" | MacOsVmDriver;
8
+ readonly capsule_id: string;
9
+ readonly canonical_node_id: string;
10
+ readonly node_generation: string;
11
+ readonly placement_generation: string;
12
+ readonly auth_generation: string;
13
+ readonly image_sha256: string;
14
+ readonly codewith_binary_sha256: string;
15
+ readonly managed_requirements_sha256: string;
16
+ readonly containment: "linux-user-mount-pid-net-namespace" | "macos-hypervisor-vm";
17
+ readonly persistent_credential_store: true;
18
+ readonly host_filesystem_mounted: false;
19
+ readonly repository_mounted: false;
20
+ readonly tool_credential_store_readable: false;
21
+ readonly broker_route: "protected-preprovisioned";
22
+ }
23
+ export interface SubscriptionCapsuleLaunchResult {
24
+ readonly exit_code: number;
25
+ readonly stdout: string;
26
+ readonly stderr: string;
27
+ }
28
+ export interface SubscriptionCapsuleProvider {
29
+ inspect(): Promise<SubscriptionCapsuleAttestation>;
30
+ launch(input: Readonly<{
31
+ prompt: string;
32
+ }>): Promise<SubscriptionCapsuleLaunchResult>;
33
+ }
34
+ export declare function parseSubscriptionCapsuleAttestation(value: unknown): SubscriptionCapsuleAttestation;
35
+ export declare class IsolatedSubscriptionCapsuleRunner {
36
+ #private;
37
+ constructor(dependencies: {
38
+ provider: SubscriptionCapsuleProvider;
39
+ authority: AuthCapsuleLaunchAuthorityPort;
40
+ bridge: CapsuleRemoteToolBridgePort;
41
+ });
42
+ launch(input: Readonly<{
43
+ descriptor: AuthCapsuleDescriptor;
44
+ binding: CapsuleRemoteToolBinding;
45
+ policy: unknown;
46
+ prompt: string;
47
+ }>): Promise<SubscriptionCapsuleLaunchResult>;
48
+ }
49
+ export interface MacOsVmCapsuleAdapter {
50
+ readonly driver: MacOsVmDriver;
51
+ inspect(): Promise<unknown>;
52
+ /** The guest launch route is preprovisioned; no caller argv, env, path, mount, endpoint, or credential is accepted. */
53
+ launch(input: Readonly<{
54
+ prompt: string;
55
+ }>): Promise<SubscriptionCapsuleLaunchResult>;
56
+ }
57
+ export declare class MacOsVmSubscriptionCapsuleProvider implements SubscriptionCapsuleProvider {
58
+ #private;
59
+ constructor(adapter: MacOsVmCapsuleAdapter);
60
+ inspect(): Promise<SubscriptionCapsuleAttestation>;
61
+ launch(input: Readonly<{
62
+ prompt: string;
63
+ }>): Promise<SubscriptionCapsuleLaunchResult>;
64
+ }
65
+ export interface LinuxBubblewrapCapsuleOptions {
66
+ readonly bubblewrap_path: string;
67
+ readonly capsule_root: string;
68
+ /** Provisioning-owned fixed command. It is never sourced from a model or task request. */
69
+ readonly guest_command: readonly string[];
70
+ readonly capsule_id: string;
71
+ readonly canonical_node_id: string;
72
+ readonly node_generation: string;
73
+ readonly placement_generation: string;
74
+ readonly auth_generation: string;
75
+ readonly image_sha256: string;
76
+ readonly codewith_binary_sha256: string;
77
+ readonly managed_requirements_path: string;
78
+ readonly managed_requirements_sha256: string;
79
+ }
80
+ export declare class LinuxBubblewrapCapsuleProvider implements SubscriptionCapsuleProvider {
81
+ #private;
82
+ constructor(options: LinuxBubblewrapCapsuleOptions);
83
+ inspect(): Promise<SubscriptionCapsuleAttestation>;
84
+ launch(input: Readonly<{
85
+ prompt: string;
86
+ }>): Promise<SubscriptionCapsuleLaunchResult>;
87
+ }
@@ -0,0 +1,342 @@
1
+ import type { Clock } from "../core/clock";
2
+ import type { IdFactory } from "../core/ids";
3
+ import { type Int64 } from "../core/int64";
4
+ import type { ApprovalDecisionVerb, ApprovalRequestRecord, AttemptOutcome, AttemptRecord, RunRecord } from "../contracts/dtos";
5
+ import { type AuthorityEvent } from "../contracts/events";
6
+ import { type OperationResolution } from "../contracts/operations";
7
+ import { type RunSpec } from "../contracts/runspec";
8
+ import { type AccountsSlotEligibilityPort, type SlotEligibilityRequest } from "../ports/accounts";
9
+ import { type InMemoryAccountsOperationSignerHistory } from "../ports/accounts-operation";
10
+ import type { AuthoritySnapshot } from "./state";
11
+ import { InMemoryAuthorityStore } from "./store";
12
+ import { type AuthorityMutationJournalReceiptVerifier, type SynchronousAuthorityMutationJournalPort } from "./mutation-journal";
13
+ export { mutationRequestHash } from "./mutation-tuple";
14
+ export interface SubmitRunContext {
15
+ actorPrincipal: string;
16
+ operationId: string;
17
+ idempotencyKey: string;
18
+ authorityEpoch: Int64;
19
+ routeLineageId: string;
20
+ routeId: string;
21
+ routeEpoch: Int64;
22
+ }
23
+ export interface SubmitRunResult {
24
+ operation_id: string;
25
+ run_spec_id: string;
26
+ run_spec_digest: string;
27
+ run_id: string;
28
+ attempt_id: string;
29
+ attempt_number: number;
30
+ attempt_phase: string;
31
+ state: string;
32
+ run_revision: number;
33
+ attempt_revision: number;
34
+ authority_epoch: Int64;
35
+ route_epoch: Int64;
36
+ idempotency: {
37
+ replayed: boolean;
38
+ };
39
+ }
40
+ export interface ClaimAttemptInput {
41
+ schedulerPrincipal: string;
42
+ leaseHolderPrincipal: string;
43
+ audience: string;
44
+ lanePoolId: string;
45
+ leaseDurationMs: number;
46
+ operationId: string;
47
+ idempotencyKey: string;
48
+ authorityEpoch: Int64;
49
+ /** Exact Accounts v11 eligibility request carried into the claim authority decision. */
50
+ accountsEligibilityRequest: SlotEligibilityRequest;
51
+ }
52
+ export interface ClaimAttemptResult {
53
+ operation_id: string;
54
+ run_id: string;
55
+ project_id: string;
56
+ attempt_id: string;
57
+ attempt_number: number;
58
+ attempt_lease_id: string;
59
+ lease_epoch: Int64;
60
+ lease_holder_principal: string;
61
+ lease_expires_at: string;
62
+ run_revision: number;
63
+ attempt_revision: number;
64
+ eligibility_id: string;
65
+ lane_reservation_id: string;
66
+ idempotency: {
67
+ replayed: boolean;
68
+ };
69
+ }
70
+ export interface ExistingRunMutationContext {
71
+ actorPrincipal: string;
72
+ operationId: string;
73
+ idempotencyKey: string;
74
+ authorityEpoch: Int64;
75
+ expectedRunRevision: number;
76
+ attemptId: string;
77
+ attemptLeaseId?: string;
78
+ leaseEpoch?: Int64;
79
+ }
80
+ export interface PublicRunMutationContext extends ExistingRunMutationContext {
81
+ expectedAttemptNumber: number;
82
+ expectedAttemptRevision: number;
83
+ }
84
+ export interface AttemptTerminalContext extends ExistingRunMutationContext {
85
+ attemptLeaseId: string;
86
+ leaseEpoch: Int64;
87
+ outcome: AttemptOutcome;
88
+ reasonCode: string;
89
+ }
90
+ export interface RunMutationResult {
91
+ operation_id: string;
92
+ run_id: string;
93
+ attempt_id: string;
94
+ attempt_number: number;
95
+ state: string;
96
+ outcome: AttemptOutcome | null;
97
+ run_revision: number;
98
+ attempt_revision: number;
99
+ attempt_lease_id?: string;
100
+ lease_epoch?: Int64;
101
+ lease_holder_principal?: string;
102
+ lease_issued_at?: string;
103
+ lease_expires_at?: string;
104
+ lease_duration_ms?: number;
105
+ idempotency: {
106
+ replayed: boolean;
107
+ };
108
+ }
109
+ export interface HumanDiscardPresence {
110
+ verified: boolean;
111
+ decisionVerb: "discard_uncheckpointed";
112
+ challengeOperationId: string;
113
+ challengeRunId: string;
114
+ challengeAttemptId: string;
115
+ challengeConsequenceDigest: string;
116
+ expiresAt: string;
117
+ }
118
+ export interface DiscardConsequenceInput {
119
+ actorPrincipal: string;
120
+ operationId: string;
121
+ authorityEpoch: Int64;
122
+ routeLineageId: string;
123
+ routeId: string;
124
+ routeEpoch: Int64;
125
+ runId: string;
126
+ runRevision: number;
127
+ attemptId: string;
128
+ attemptLeaseId: string;
129
+ leaseEpoch: Int64;
130
+ abandonedArtifactDigests: string[];
131
+ }
132
+ export declare function computeDiscardConsequenceDigest(input: DiscardConsequenceInput): string;
133
+ export interface DiscardContext extends ExistingRunMutationContext {
134
+ attemptLeaseId: string;
135
+ leaseEpoch: Int64;
136
+ abandonedArtifactDigests: string[];
137
+ humanPresence: HumanDiscardPresence;
138
+ }
139
+ export interface ApprovalProposalInput {
140
+ runId: string;
141
+ action: "create_broker_branch_and_pr";
142
+ operationDigest: string;
143
+ evidenceDigests: string[];
144
+ maximumEffect: "draft_pull_request";
145
+ requiredHumanRole: "repository_approver";
146
+ expiresAt: string;
147
+ }
148
+ export interface ApprovalRequestContext extends ExistingRunMutationContext {
149
+ }
150
+ export interface ApprovalDecisionPresence {
151
+ verified: boolean;
152
+ challengeVerb: ApprovalDecisionVerb;
153
+ challengeApprovalId: string;
154
+ challengeRevision: number;
155
+ challengeOperationId: string;
156
+ challengeOperationDigest: string;
157
+ challengeProposalDigest: string;
158
+ expiresAt: string;
159
+ }
160
+ export interface ApprovalDecisionContext {
161
+ actorPrincipal: string;
162
+ operationId: string;
163
+ idempotencyKey: string;
164
+ authorityEpoch: Int64;
165
+ expectedApprovalRevision: number;
166
+ humanPresence: ApprovalDecisionPresence;
167
+ }
168
+ export interface ApprovalResult {
169
+ operation_id: string;
170
+ approval_id: string;
171
+ run_id: string;
172
+ state: string;
173
+ decision_verb: ApprovalDecisionVerb | null;
174
+ proposal_digest: string;
175
+ revision: number;
176
+ idempotency: {
177
+ replayed: boolean;
178
+ };
179
+ }
180
+ export interface ConsumeApprovalContext {
181
+ actorPrincipal: string;
182
+ operationId: string;
183
+ idempotencyKey: string;
184
+ exactOperationDigest: string;
185
+ runId: string;
186
+ authorityEpoch: Int64;
187
+ attemptId: string;
188
+ attemptLeaseId?: string;
189
+ leaseEpoch?: Int64;
190
+ approvalRevision: number;
191
+ }
192
+ export interface ConsumeApprovalResult {
193
+ operation_id: string;
194
+ approval_id: string;
195
+ authorization_use_id: string;
196
+ idempotency: {
197
+ replayed: boolean;
198
+ };
199
+ }
200
+ export interface RunProjection {
201
+ run: RunRecord;
202
+ attempt: AttemptRecord;
203
+ run_spec: RunSpec;
204
+ }
205
+ export interface CapabilityProjection {
206
+ authority_epoch: Int64;
207
+ principal: string;
208
+ grants: readonly [];
209
+ capabilities: string[];
210
+ }
211
+ export interface RunWaitProjection extends RunProjection {
212
+ cursor: string;
213
+ terminal: boolean;
214
+ timed_out: boolean;
215
+ }
216
+ export interface RunEventPage {
217
+ items: AuthorityEvent[];
218
+ next_cursor: string;
219
+ has_more: boolean;
220
+ terminal: boolean;
221
+ timed_out: boolean;
222
+ }
223
+ export interface MaintenanceQuiescenceBlockers {
224
+ queued_attempt_ids: string[];
225
+ live_attempt_ids: string[];
226
+ live_lane_reservation_ids: string[];
227
+ reserved_budget_run_ids: string[];
228
+ budget_accounting_anomaly_codes: string[];
229
+ undelivered_outbox_ids: string[];
230
+ actionable_approval_ids: string[];
231
+ active_accounts_model_operation_ids: string[];
232
+ }
233
+ export interface MaintenanceQuiescenceReport {
234
+ schema_version: "infinity.maintenance-quiescence-report/v1";
235
+ checked_at: string;
236
+ quiescent: boolean;
237
+ blockers: MaintenanceQuiescenceBlockers;
238
+ }
239
+ export interface HumanApprovalAuthorizer {
240
+ isAuthorized(input: {
241
+ principal: string;
242
+ projectId: string;
243
+ role: "repository_approver";
244
+ }): boolean;
245
+ }
246
+ export declare class InMemoryRunAuthority {
247
+ private readonly store;
248
+ private readonly accounts;
249
+ private readonly clock;
250
+ private readonly ids;
251
+ private readonly humanApprovalAuthorizer;
252
+ private readonly mutationJournal;
253
+ private readonly mutationJournalVerifier;
254
+ private readonly authorityRestoreDomainId;
255
+ private readonly accountsOperationSignerHistory;
256
+ private readonly expectedMutationJournalProtection;
257
+ constructor(store: InMemoryAuthorityStore, accounts: AccountsSlotEligibilityPort, clock: Clock, ids: IdFactory, humanApprovalAuthorizer: HumanApprovalAuthorizer, mutationJournal: SynchronousAuthorityMutationJournalPort, mutationJournalVerifier: AuthorityMutationJournalReceiptVerifier, authorityRestoreDomainId: string, accountsOperationSignerHistory: InMemoryAccountsOperationSignerHistory);
258
+ validateRunSpec(input: unknown): {
259
+ valid: true;
260
+ authority_epoch: Int64;
261
+ run_spec: RunSpec;
262
+ run_spec_digest: string;
263
+ };
264
+ planRun(input: unknown): {
265
+ authority_epoch: Int64;
266
+ run_spec: RunSpec;
267
+ run_spec_digest: string;
268
+ budget_ceiling_minor_units: number;
269
+ required_approvals: string[];
270
+ denials: string[];
271
+ };
272
+ submitRun(input: unknown, context: SubmitRunContext): SubmitRunResult;
273
+ getRun(runIdInput: string, actorPrincipalInput: string): RunProjection;
274
+ listRuns(actorPrincipalInput: string, options?: {
275
+ limit?: number;
276
+ cursor?: string;
277
+ }): {
278
+ items: RunProjection[];
279
+ next_cursor: string | null;
280
+ };
281
+ listCapabilities(actorPrincipalInput: string): CapabilityProjection;
282
+ waitRun(runIdInput: string, actorPrincipalInput: string, timeoutMsInput: number): Promise<RunWaitProjection>;
283
+ readRunEvents(runIdInput: string, actorPrincipalInput: string, options: {
284
+ cursor: string;
285
+ limit: number;
286
+ waitMs: number;
287
+ }): Promise<RunEventPage>;
288
+ claimNextAttempt(input: ClaimAttemptInput): Promise<ClaimAttemptResult | null>;
289
+ recordAttemptTerminal(runIdInput: string, context: AttemptTerminalContext): RunMutationResult;
290
+ cancelRun(runIdInput: string, context: PublicRunMutationContext & {
291
+ reasonCode: string;
292
+ }): RunMutationResult;
293
+ retryRun(runIdInput: string, context: PublicRunMutationContext): RunMutationResult;
294
+ discardUncheckpointed(runIdInput: string, context: DiscardContext): RunMutationResult;
295
+ requestApproval(input: ApprovalProposalInput, context: ApprovalRequestContext): ApprovalResult;
296
+ decideApproval(approvalIdInput: string, decisionVerbInput: ApprovalDecisionVerb, context: ApprovalDecisionContext): ApprovalResult;
297
+ consumeApproval(approvalIdInput: string, context: ConsumeApprovalContext): ConsumeApprovalResult;
298
+ getApproval(approvalIdInput: string, actorPrincipalInput: string): {
299
+ approval: ApprovalRequestRecord;
300
+ };
301
+ listApprovals(runIdInput: string, actorPrincipalInput: string): {
302
+ items: ApprovalRequestRecord[];
303
+ };
304
+ resolveOperation(operationIdInput: string, actorPrincipalInput: string): OperationResolution;
305
+ snapshot(): AuthoritySnapshot;
306
+ maintenanceQuiescenceReport(): MaintenanceQuiescenceReport;
307
+ reconcileMutationJournal(): number;
308
+ private mutate;
309
+ private ensureMutationAcknowledged;
310
+ private assertMutationEnvelopeExternallyStored;
311
+ private assertExpectedMutationJournalProtection;
312
+ private guardedMutationJournalCall;
313
+ private assertExpectedMutationJournalAcknowledgement;
314
+ private readMutationJournalHead;
315
+ private readMutationJournalRange;
316
+ private appendMutationJournalEnvelope;
317
+ private withReplay;
318
+ private replayKnownMutation;
319
+ private appendEvent;
320
+ private parseExistingRunContext;
321
+ private requireCurrentRunAttempt;
322
+ private assertOwner;
323
+ private assertRunRevision;
324
+ private assertAttemptObservation;
325
+ private assertAttemptLease;
326
+ private assertLeaseSelector;
327
+ private hasAttemptLease;
328
+ private requiredLeaseEpoch;
329
+ private requiredAttemptLeaseId;
330
+ private staleLease;
331
+ private assertRouteCurrentInState;
332
+ private assertRunRouteCurrent;
333
+ private assertApprovalProposalCurrent;
334
+ private selectQueueCandidate;
335
+ private selectQueueCandidateInState;
336
+ private findFreeSlot;
337
+ private hasFreeSlot;
338
+ private validateEligibility;
339
+ private releaseLaneReservation;
340
+ private releaseBudget;
341
+ private runMutationResult;
342
+ }