@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.
- package/LICENSE +3 -0
- package/README.md +331 -0
- package/dist/cli.js +2965 -0
- package/dist/http-api.js +6448 -0
- package/dist/index.js +28536 -0
- package/dist/migrate.js +346 -0
- package/dist/self-hosted-migrate.js +2064 -0
- package/dist/self-hosted.js +13180 -0
- package/dist/types/authcapsules/codewith-local.d.ts +109 -0
- package/dist/types/authcapsules/infinity-agent-policy.d.ts +57 -0
- package/dist/types/authcapsules/os-isolated-runner.d.ts +87 -0
- package/dist/types/authority/authority.d.ts +342 -0
- package/dist/types/authority/effect-journal.d.ts +205 -0
- package/dist/types/authority/mutation-journal.d.ts +163 -0
- package/dist/types/authority/mutation-tuple.d.ts +26 -0
- package/dist/types/authority/state.d.ts +75 -0
- package/dist/types/authority/store.d.ts +15 -0
- package/dist/types/brokers/checkpoint/archive.d.ts +21 -0
- package/dist/types/brokers/checkpoint/bundle.d.ts +22 -0
- package/dist/types/brokers/checkpoint/bytes.d.ts +4 -0
- package/dist/types/brokers/checkpoint/clean-verifier-finalization.d.ts +62 -0
- package/dist/types/brokers/checkpoint/clean-verifier.d.ts +145 -0
- package/dist/types/brokers/checkpoint/final-trust-authority.d.ts +55 -0
- package/dist/types/brokers/checkpoint/idempotency.d.ts +25 -0
- package/dist/types/brokers/checkpoint/journaled-store.d.ts +9 -0
- package/dist/types/brokers/checkpoint/manifest-signature.d.ts +135 -0
- package/dist/types/brokers/checkpoint/manifest.d.ts +57 -0
- package/dist/types/brokers/checkpoint/s3-store.d.ts +215 -0
- package/dist/types/brokers/checkpoint/seal-authority.d.ts +86 -0
- package/dist/types/brokers/checkpoint/service.d.ts +198 -0
- package/dist/types/brokers/checkpoint/signing-message.d.ts +22 -0
- package/dist/types/brokers/checkpoint/store.d.ts +76 -0
- package/dist/types/brokers/checkpoint/verifier-cleanup-authority.d.ts +108 -0
- package/dist/types/brokers/checkpoint/verifier-cleanup.d.ts +391 -0
- package/dist/types/brokers/checkpoint/verifier.d.ts +225 -0
- package/dist/types/brokers/composition.d.ts +86 -0
- package/dist/types/brokers/git/github-app.d.ts +216 -0
- package/dist/types/brokers/git/promotion.d.ts +418 -0
- package/dist/types/brokers/persistence/contracts.d.ts +77 -0
- package/dist/types/brokers/persistence/memory.d.ts +5 -0
- package/dist/types/brokers/persistence/migration.d.ts +6 -0
- package/dist/types/brokers/persistence/postgres.d.ts +74 -0
- package/dist/types/cli/main.d.ts +2 -0
- package/dist/types/cli/operation-journal.d.ts +47 -0
- package/dist/types/cli/run.d.ts +15 -0
- package/dist/types/client/operator-client.d.ts +100 -0
- package/dist/types/contracts/dtos.d.ts +198 -0
- package/dist/types/contracts/events.d.ts +45 -0
- package/dist/types/contracts/fence.d.ts +39 -0
- package/dist/types/contracts/operations.d.ts +91 -0
- package/dist/types/contracts/runspec.d.ts +75 -0
- package/dist/types/contracts/validators.d.ts +8 -0
- package/dist/types/core/clock.d.ts +12 -0
- package/dist/types/core/errors.d.ts +18 -0
- package/dist/types/core/ids.d.ts +10 -0
- package/dist/types/core/int64.d.ts +7 -0
- package/dist/types/core/strict-json.d.ts +8 -0
- package/dist/types/core/validation.d.ts +25 -0
- package/dist/types/golden/disposable-task.d.ts +108 -0
- package/dist/types/golden/source-pins.d.ts +77 -0
- package/dist/types/http/api.d.ts +52 -0
- package/dist/types/http/bearer-auth.d.ts +8 -0
- package/dist/types/http/main.d.ts +3 -0
- package/dist/types/http/self-hosted-main.d.ts +17 -0
- package/dist/types/index.d.ts +65 -0
- package/dist/types/mcp/schema.d.ts +7 -0
- package/dist/types/node-agent/agent.d.ts +174 -0
- package/dist/types/node-agent/contracts.d.ts +119 -0
- package/dist/types/node-agent/macos-service.d.ts +33 -0
- package/dist/types/node-agent/service-cli.d.ts +26 -0
- package/dist/types/persistence/composition.d.ts +49 -0
- package/dist/types/persistence/migrate-main.d.ts +2 -0
- package/dist/types/persistence/migrations.d.ts +30 -0
- package/dist/types/persistence/postgres-accounts-operation.d.ts +26 -0
- package/dist/types/persistence/postgres-authority.d.ts +69 -0
- package/dist/types/persistence/postgres-external-mutation-journal.d.ts +22 -0
- package/dist/types/persistence/postgres-json.d.ts +1 -0
- package/dist/types/persistence/postgres-mutation-journal.d.ts +31 -0
- package/dist/types/persistence/postgres-reconciler.d.ts +34 -0
- package/dist/types/persistence/postgres-sandbox-dispatch-authority.d.ts +9 -0
- package/dist/types/persistence/self-hosted-migrate-main.d.ts +2 -0
- package/dist/types/ports/accounts-operation.d.ts +336 -0
- package/dist/types/ports/accounts.d.ts +293 -0
- package/dist/types/ports/sandbox-dispatch-authority.d.ts +154 -0
- package/dist/types/ports/sandboxes.d.ts +40 -0
- package/dist/types/providers/sandbox-dispatch.d.ts +143 -0
- package/dist/types/runtime/config.d.ts +61 -0
- package/dist/types/runtime/postgres.d.ts +18 -0
- package/dist/types/runtime/provider-activation.d.ts +45 -0
- package/dist/types/runtime/server.d.ts +68 -0
- package/dist/types/testing/accounts-fake.d.ts +31 -0
- package/dist/types/testing/fakes.d.ts +2 -0
- package/dist/types/testing/node-control-plane-fake.d.ts +20 -0
- package/dist/types/testing/reference.d.ts +27 -0
- package/dist/types/testing/sandboxes-fake.d.ts +22 -0
- package/evidence/provider-live-daytona-v3.json +1 -0
- package/evidence/provider-live-e2b-v3.json +1 -0
- package/evidence/provider-production-route-daytona-v1.json +1 -0
- package/evidence/provider-production-route-e2b-v1.json +1 -0
- package/migrations/0001_authority.sql +689 -0
- package/migrations/0002_effect_step_global_owner.sql +2 -0
- package/migrations/0003_effect_journal_observed_head.sql +34 -0
- package/migrations/0004_authority_mutation_journal_binding.sql +15 -0
- package/migrations/20260710_checkpoint_broker_v1.sql +163 -0
- package/migrations/20260711_accounts_operation_v1.sql +137 -0
- package/migrations/20260711_checkpoint_trust_v2.sql +17 -0
- package/migrations/20260711_verifier_cleanup_v2.sql +169 -0
- package/migrations/20260711_z_accounts_claim_authority_v2.sql +172 -0
- package/migrations/20260711_zz_sandbox_dispatch_authority_v1.sql +143 -0
- package/migrations/20260712_sandbox_dispatch_authority_v2.sql +58 -0
- package/migrations/external-journal/0001_external_authority_mutation_journal.sql +175 -0
- package/package.json +47 -0
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import type { KeyObject } from "node:crypto";
|
|
2
|
+
import { type AuthCapsuleDescriptor, type CapsuleRemoteToolBinding } from "../authcapsules/codewith-local";
|
|
3
|
+
import { type InfinityAgentPolicy } from "../authcapsules/infinity-agent-policy";
|
|
4
|
+
import { type SubscriptionCapsuleAttestation } from "../authcapsules/os-isolated-runner";
|
|
5
|
+
export declare const NODE_AGENT_COMMAND_SCHEMA_VERSION: "infinity.node-agent-command.v1";
|
|
6
|
+
export declare const NODE_AGENT_REGISTRATION_SCHEMA_VERSION: "infinity.node-agent-registration.v1";
|
|
7
|
+
export declare const NODE_AGENT_HEARTBEAT_SCHEMA_VERSION: "infinity.node-agent-heartbeat.v1";
|
|
8
|
+
export declare const NODE_AGENT_RECEIPT_SCHEMA_VERSION: "infinity.node-agent-receipt.v1";
|
|
9
|
+
export declare const MAX_NODE_AGENT_COMMAND_LIFETIME_MS: number;
|
|
10
|
+
export interface NodeAgentTransportPolicy {
|
|
11
|
+
readonly endpoint_origin: string;
|
|
12
|
+
readonly server_spki_sha256: string;
|
|
13
|
+
readonly client_certificate_ref: string;
|
|
14
|
+
readonly client_private_key_ref: string;
|
|
15
|
+
readonly command_signing_key_id: string;
|
|
16
|
+
readonly command_signing_key_thumbprint: string;
|
|
17
|
+
}
|
|
18
|
+
export interface NodeAgentLaunchPayload {
|
|
19
|
+
readonly schema_version: "infinity.node-agent-launch.v1";
|
|
20
|
+
readonly credential_transport: "none";
|
|
21
|
+
readonly repository_transport: "none";
|
|
22
|
+
readonly descriptor: AuthCapsuleDescriptor;
|
|
23
|
+
readonly binding: CapsuleRemoteToolBinding;
|
|
24
|
+
readonly policy: InfinityAgentPolicy;
|
|
25
|
+
readonly prompt: string;
|
|
26
|
+
}
|
|
27
|
+
export interface NodeAgentRevokePayload {
|
|
28
|
+
readonly schema_version: "infinity.node-agent-revoke.v1";
|
|
29
|
+
readonly credential_transport: "none";
|
|
30
|
+
readonly repository_transport: "none";
|
|
31
|
+
readonly reason_code: string;
|
|
32
|
+
}
|
|
33
|
+
export type NodeAgentCommandPayload = NodeAgentLaunchPayload | NodeAgentRevokePayload;
|
|
34
|
+
export interface NodeAgentCommandCore {
|
|
35
|
+
readonly schema_version: typeof NODE_AGENT_COMMAND_SCHEMA_VERSION;
|
|
36
|
+
readonly command_id: string;
|
|
37
|
+
readonly sequence: string;
|
|
38
|
+
readonly kind: "launch" | "revoke";
|
|
39
|
+
readonly canonical_node_id: string;
|
|
40
|
+
readonly node_generation: string;
|
|
41
|
+
readonly owner_ref: string;
|
|
42
|
+
readonly capsule_id: string;
|
|
43
|
+
readonly placement_generation: string;
|
|
44
|
+
readonly auth_generation: string;
|
|
45
|
+
readonly lease_id: string;
|
|
46
|
+
readonly lease_epoch: string;
|
|
47
|
+
readonly issued_at: string;
|
|
48
|
+
readonly expires_at: string;
|
|
49
|
+
readonly payload_sha256: string;
|
|
50
|
+
readonly payload: NodeAgentCommandPayload;
|
|
51
|
+
readonly signer_key_id: string;
|
|
52
|
+
}
|
|
53
|
+
export interface SignedNodeAgentCommand extends NodeAgentCommandCore {
|
|
54
|
+
readonly signature_base64url: string;
|
|
55
|
+
}
|
|
56
|
+
export interface NodeAgentRegistration {
|
|
57
|
+
readonly schema_version: typeof NODE_AGENT_REGISTRATION_SCHEMA_VERSION;
|
|
58
|
+
readonly registration_nonce: string;
|
|
59
|
+
readonly canonical_node_id: string;
|
|
60
|
+
readonly node_key_thumbprint: string;
|
|
61
|
+
readonly node_generation: string;
|
|
62
|
+
readonly agent_version: string;
|
|
63
|
+
readonly agent_started_at: string;
|
|
64
|
+
readonly capabilities: readonly ["auth-capsule.launch", "auth-capsule.revoke"];
|
|
65
|
+
readonly outbound_only: true;
|
|
66
|
+
readonly credential_transport: "none";
|
|
67
|
+
readonly repository_transport: "none";
|
|
68
|
+
readonly capsules: readonly SubscriptionCapsuleAttestation[];
|
|
69
|
+
}
|
|
70
|
+
export interface NodeAgentHeartbeat {
|
|
71
|
+
readonly schema_version: typeof NODE_AGENT_HEARTBEAT_SCHEMA_VERSION;
|
|
72
|
+
readonly session_id: string;
|
|
73
|
+
readonly canonical_node_id: string;
|
|
74
|
+
readonly node_generation: string;
|
|
75
|
+
readonly observed_at: string;
|
|
76
|
+
readonly last_command_sequence: string;
|
|
77
|
+
readonly capsules: readonly SubscriptionCapsuleAttestation[];
|
|
78
|
+
}
|
|
79
|
+
export interface NodeAgentReceipt {
|
|
80
|
+
readonly schema_version: typeof NODE_AGENT_RECEIPT_SCHEMA_VERSION;
|
|
81
|
+
readonly session_id: string;
|
|
82
|
+
readonly command_id: string;
|
|
83
|
+
readonly command_sha256: string;
|
|
84
|
+
readonly canonical_node_id: string;
|
|
85
|
+
readonly capsule_id: string;
|
|
86
|
+
readonly lease_epoch: string;
|
|
87
|
+
readonly outcome: "succeeded" | "failed";
|
|
88
|
+
readonly reconciled: boolean;
|
|
89
|
+
readonly exit_code?: number;
|
|
90
|
+
readonly result_sha256?: string;
|
|
91
|
+
readonly completed_at: string;
|
|
92
|
+
}
|
|
93
|
+
export interface NodeControlPlanePeerEvidence {
|
|
94
|
+
readonly session_id: string;
|
|
95
|
+
readonly mutual_tls: true;
|
|
96
|
+
readonly server_spki_sha256: string;
|
|
97
|
+
readonly command_signing_key_id: string;
|
|
98
|
+
readonly command_signing_key_thumbprint: string;
|
|
99
|
+
}
|
|
100
|
+
export interface NodeControlPlaneSession {
|
|
101
|
+
readonly peer: NodeControlPlanePeerEvidence;
|
|
102
|
+
heartbeat(value: NodeAgentHeartbeat): Promise<void>;
|
|
103
|
+
nextCommand(): Promise<unknown | undefined>;
|
|
104
|
+
receipt(value: NodeAgentReceipt): Promise<void>;
|
|
105
|
+
close(): Promise<void>;
|
|
106
|
+
}
|
|
107
|
+
/** Implementations may only originate a connection to endpoint_origin; no inbound listener is part of this port. */
|
|
108
|
+
export interface NodeControlPlaneTransport {
|
|
109
|
+
connect(input: Readonly<{
|
|
110
|
+
transport_policy: NodeAgentTransportPolicy;
|
|
111
|
+
registration: NodeAgentRegistration;
|
|
112
|
+
}>): Promise<NodeControlPlaneSession>;
|
|
113
|
+
}
|
|
114
|
+
export declare function parseNodeAgentTransportPolicy(value: unknown): NodeAgentTransportPolicy;
|
|
115
|
+
export declare function parseNodeAgentCommandCore(value: unknown): NodeAgentCommandCore;
|
|
116
|
+
export declare function parseSignedNodeAgentCommand(value: unknown): SignedNodeAgentCommand;
|
|
117
|
+
export declare function nodeAgentCommandSigningBytes(command: NodeAgentCommandCore): Uint8Array;
|
|
118
|
+
export declare function nodeAgentCommandDigest(command: SignedNodeAgentCommand): string;
|
|
119
|
+
export type NodeCommandPublicKey = KeyObject;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export declare const INFINITY_AGENT_LAUNCHD_LABEL: "com.hasna.infinity-agent";
|
|
2
|
+
export interface MacOsLaunchdOptions {
|
|
3
|
+
readonly scope: "user" | "system";
|
|
4
|
+
readonly program_path: string;
|
|
5
|
+
readonly config_path: string;
|
|
6
|
+
readonly stdout_path: string;
|
|
7
|
+
readonly stderr_path: string;
|
|
8
|
+
}
|
|
9
|
+
export interface MacOsLaunchdHostPort {
|
|
10
|
+
writeAtomic(path: string, contents: string, mode: number): Promise<void>;
|
|
11
|
+
remove(path: string): Promise<void>;
|
|
12
|
+
launchctl(args: readonly string[]): Promise<Readonly<{
|
|
13
|
+
exit_code: number;
|
|
14
|
+
stdout: string;
|
|
15
|
+
stderr: string;
|
|
16
|
+
}>>;
|
|
17
|
+
}
|
|
18
|
+
export interface MacOsServiceStatus {
|
|
19
|
+
readonly installed: boolean;
|
|
20
|
+
readonly running: boolean;
|
|
21
|
+
readonly details: string;
|
|
22
|
+
}
|
|
23
|
+
export declare function renderMacOsLaunchdPlist(options: MacOsLaunchdOptions): string;
|
|
24
|
+
export declare class MacOsLaunchdService {
|
|
25
|
+
#private;
|
|
26
|
+
constructor(host: MacOsLaunchdHostPort, environment: Readonly<{
|
|
27
|
+
home_directory: string;
|
|
28
|
+
uid: number;
|
|
29
|
+
}>);
|
|
30
|
+
install(options: MacOsLaunchdOptions): Promise<void>;
|
|
31
|
+
status(scope: "user" | "system"): Promise<MacOsServiceStatus>;
|
|
32
|
+
uninstall(scope: "user" | "system"): Promise<void>;
|
|
33
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { MacOsLaunchdOptions, MacOsServiceStatus } from "./macos-service";
|
|
2
|
+
import type { MacOsLaunchdService } from "./macos-service";
|
|
3
|
+
import type { NodeAgentDaemon } from "./agent";
|
|
4
|
+
export interface NodeAgentServiceCliRuntime {
|
|
5
|
+
/** Runs a fully composed NodeAgentDaemon until its process signal is aborted. */
|
|
6
|
+
run(): Promise<void>;
|
|
7
|
+
install(options: MacOsLaunchdOptions): Promise<void>;
|
|
8
|
+
status(scope: "user" | "system"): Promise<MacOsServiceStatus>;
|
|
9
|
+
uninstall(scope: "user" | "system"): Promise<void>;
|
|
10
|
+
writeStdout(value: string): void;
|
|
11
|
+
}
|
|
12
|
+
export declare class ComposedNodeAgentServiceCliRuntime implements NodeAgentServiceCliRuntime {
|
|
13
|
+
#private;
|
|
14
|
+
constructor(input: Readonly<{
|
|
15
|
+
daemon: Pick<NodeAgentDaemon, "run">;
|
|
16
|
+
launchd: Pick<MacOsLaunchdService, "install" | "status" | "uninstall">;
|
|
17
|
+
signal: AbortSignal;
|
|
18
|
+
write_stdout: (value: string) => void;
|
|
19
|
+
}>);
|
|
20
|
+
run(): Promise<void>;
|
|
21
|
+
install(options: MacOsLaunchdOptions): Promise<void>;
|
|
22
|
+
status(scope: "user" | "system"): Promise<MacOsServiceStatus>;
|
|
23
|
+
uninstall(scope: "user" | "system"): Promise<void>;
|
|
24
|
+
writeStdout(value: string): void;
|
|
25
|
+
}
|
|
26
|
+
export declare function runNodeAgentServiceCli(argv: readonly string[], runtime: NodeAgentServiceCliRuntime): Promise<number>;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { SQL } from "bun";
|
|
2
|
+
import { PostgresRunAuthority } from "./postgres-authority";
|
|
3
|
+
import { PostgresReconciler, type EffectJournalAnchorVerifier } from "./postgres-reconciler";
|
|
4
|
+
import { type OperatorAuthenticator } from "../http/api";
|
|
5
|
+
import type { Clock } from "../core/clock";
|
|
6
|
+
import type { IdFactory } from "../core/ids";
|
|
7
|
+
import { type AuthorityMutationJournalSigner, type AuthorityMutationJournalPort, type AuthorityMutationJournalReceiptVerifier } from "../authority/mutation-journal";
|
|
8
|
+
import type { EffectJournalPort } from "../authority/effect-journal";
|
|
9
|
+
import { PostgresMutationJournalCoordinator } from "./postgres-mutation-journal";
|
|
10
|
+
import type { InfinityAccountsOperationPort, InMemoryAccountsOperationSignerHistory } from "../ports/accounts-operation";
|
|
11
|
+
import type { AccountsSlotEligibilityPort } from "../ports/accounts";
|
|
12
|
+
import { type AccountsSchedulerClaimPort } from "./postgres-accounts-operation";
|
|
13
|
+
import type { InfinityProductionSandboxDispatchService } from "../providers/sandbox-dispatch";
|
|
14
|
+
export declare function createPostgresAuthorityComposition(input: {
|
|
15
|
+
runtimeSql: SQL;
|
|
16
|
+
reconcilerSql: SQL;
|
|
17
|
+
journalAckerSql: SQL;
|
|
18
|
+
clock: Clock;
|
|
19
|
+
ids: IdFactory;
|
|
20
|
+
authenticator: OperatorAuthenticator;
|
|
21
|
+
mutationJournal?: AuthorityMutationJournalPort;
|
|
22
|
+
mutationJournalVerifier?: AuthorityMutationJournalReceiptVerifier;
|
|
23
|
+
externalJournalDatabase?: {
|
|
24
|
+
readonly sql: SQL;
|
|
25
|
+
readonly signer: AuthorityMutationJournalSigner;
|
|
26
|
+
readonly verifier: AuthorityMutationJournalReceiptVerifier;
|
|
27
|
+
readonly journalId: string;
|
|
28
|
+
readonly restoreDomainId: string;
|
|
29
|
+
readonly encryptedAtRest: true;
|
|
30
|
+
readonly requiredRole?: string;
|
|
31
|
+
};
|
|
32
|
+
authorityRestoreDomainId: string;
|
|
33
|
+
effectJournal: EffectJournalPort;
|
|
34
|
+
effectVerifier: EffectJournalAnchorVerifier;
|
|
35
|
+
runtimeRole?: string;
|
|
36
|
+
reconcilerRole?: string;
|
|
37
|
+
journalAckerRole?: string;
|
|
38
|
+
accountsOperationSignerHistory?: InMemoryAccountsOperationSignerHistory;
|
|
39
|
+
accounts?: AccountsSlotEligibilityPort;
|
|
40
|
+
productionSandboxDispatch?: InfinityProductionSandboxDispatchService;
|
|
41
|
+
}): Promise<{
|
|
42
|
+
readonly authority: PostgresRunAuthority;
|
|
43
|
+
readonly accountsOperation: InfinityAccountsOperationPort | null;
|
|
44
|
+
readonly accountsScheduler: AccountsSchedulerClaimPort | null;
|
|
45
|
+
readonly sandboxDispatchAuthority: import("..").SandboxDispatchAuthorityPortV2 | null;
|
|
46
|
+
readonly reconciler: PostgresReconciler;
|
|
47
|
+
readonly mutationJournal: PostgresMutationJournalCoordinator;
|
|
48
|
+
readonly api: import("..").AuthorityApi;
|
|
49
|
+
}>;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { SQL } from "bun";
|
|
2
|
+
export interface MigrationResult {
|
|
3
|
+
readonly applied: readonly string[];
|
|
4
|
+
readonly alreadyApplied: readonly string[];
|
|
5
|
+
}
|
|
6
|
+
export interface PostgresRoleNames {
|
|
7
|
+
readonly runtimeRole: string;
|
|
8
|
+
readonly reconcilerRole: string;
|
|
9
|
+
readonly journalAckerRole: string;
|
|
10
|
+
}
|
|
11
|
+
export declare const DEFAULT_POSTGRES_ROLES: PostgresRoleNames;
|
|
12
|
+
export declare const POSTGRES_MIGRATION_MANIFEST: Readonly<{
|
|
13
|
+
readonly "0001_authority.sql": "sha256:bfcff16873cf8664ee46aeea581f9f4d212bac05cf3bbc1817dc495434f7f1d6";
|
|
14
|
+
readonly "0002_effect_step_global_owner.sql": "sha256:3342801f79c4cf6321bbeaa3928cf7a0d4a3e9a391505274e88931c48eb4632d";
|
|
15
|
+
readonly "0003_effect_journal_observed_head.sql": "sha256:0cf5388c8665f9727df4f1f7430761086bd2fa03d0e1e2aaddecda9ca7790aba";
|
|
16
|
+
readonly "0004_authority_mutation_journal_binding.sql": "sha256:ddeb4d190016536f61ea55e3e0c36a5fa28211af5ed2c9a41c752ce3b1a857d0";
|
|
17
|
+
readonly "20260710_checkpoint_broker_v1.sql": "sha256:3e250bee6358188cf30acb2ab14f31edfdf94c2b73502793b91a7caaf28c3d8f";
|
|
18
|
+
readonly "20260711_checkpoint_trust_v2.sql": "sha256:5165e08ae32b671838a2ee9349b35cf7007afade70ec19694ad27334bdaac065";
|
|
19
|
+
readonly "20260711_verifier_cleanup_v2.sql": "sha256:fe06ed0ec0bde18310321e7cce19c885f127e550ac1ea365b159be4effb71e79";
|
|
20
|
+
readonly "20260711_accounts_operation_v1.sql": "sha256:7d9caa3aa9fbbdab501e81b363ec5258b006a86572211eccb563b000d52d3a62";
|
|
21
|
+
readonly "20260711_z_accounts_claim_authority_v2.sql": "sha256:1da1ace609a4813472f2637d61b435cf372bd9d0f66694b3c502e17da3b9de38";
|
|
22
|
+
readonly "20260711_zz_sandbox_dispatch_authority_v1.sql": "sha256:543bb2c9b392c98c2069c437616e3d7d0fbf1d02cb8d1f6e09f1bad83238e69f";
|
|
23
|
+
readonly "20260712_sandbox_dispatch_authority_v2.sql": "sha256:c93b5b31d4f94549018300c94a568a4b8b5a403f28bf04d6177d14726518b3e3";
|
|
24
|
+
}>;
|
|
25
|
+
export declare function applyPostgresMigrations(sql: SQL, directory?: string): Promise<MigrationResult>;
|
|
26
|
+
export declare function configurePostgresRoles(sql: SQL, roles?: PostgresRoleNames): Promise<void>;
|
|
27
|
+
export declare function readMigrationState(sql: SQL): Promise<readonly {
|
|
28
|
+
migration_name: string;
|
|
29
|
+
checksum: string;
|
|
30
|
+
}[]>;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { SQL } from "bun";
|
|
2
|
+
import type { IdFactory } from "../core/ids";
|
|
3
|
+
import { InMemoryAccountsOperationSignerHistory, type InfinityAccountsOperationRecoveryPort } from "../ports/accounts-operation";
|
|
4
|
+
import { type AccountsSlotEligibilityPort } from "../ports/accounts";
|
|
5
|
+
import type { ClaimAttemptInput, ClaimAttemptResult } from "../authority/authority";
|
|
6
|
+
import { type PostgresMutationJournalCoordinator } from "./postgres-mutation-journal";
|
|
7
|
+
/**
|
|
8
|
+
* PostgreSQL production authority for Accounts model-call evidence. Exact signed
|
|
9
|
+
* bytes are generated and verified by the shared local authority engine, while
|
|
10
|
+
* this adapter supplies durable SERIALIZABLE CAS, restart reconstruction, and
|
|
11
|
+
* the external authority mutation-journal boundary.
|
|
12
|
+
*/
|
|
13
|
+
export interface AccountsSchedulerClaimPort {
|
|
14
|
+
claimNextAttempt(input: ClaimAttemptInput): Promise<ClaimAttemptResult | null>;
|
|
15
|
+
}
|
|
16
|
+
export interface PostgresAccountsAuthorityFacade {
|
|
17
|
+
readonly scheduler: AccountsSchedulerClaimPort;
|
|
18
|
+
readonly operation: InfinityAccountsOperationRecoveryPort;
|
|
19
|
+
}
|
|
20
|
+
export declare function createPostgresAccountsAuthority(input: {
|
|
21
|
+
readonly sql: SQL;
|
|
22
|
+
readonly signerHistory: InMemoryAccountsOperationSignerHistory;
|
|
23
|
+
readonly mutationJournal: PostgresMutationJournalCoordinator;
|
|
24
|
+
readonly accounts: AccountsSlotEligibilityPort;
|
|
25
|
+
readonly ids: IdFactory;
|
|
26
|
+
}): Promise<PostgresAccountsAuthorityFacade>;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import type { SQL } from "bun";
|
|
2
|
+
import type { CapabilityProjection, PublicRunMutationContext, RunEventPage, RunMutationResult, RunWaitProjection, SubmitRunContext, SubmitRunResult } from "../authority/authority";
|
|
3
|
+
import type { AttemptRecord, RunRecord } from "../contracts/dtos";
|
|
4
|
+
import type { Clock } from "../core/clock";
|
|
5
|
+
import type { IdFactory } from "../core/ids";
|
|
6
|
+
import { type Int64 } from "../core/int64";
|
|
7
|
+
import { type RunSpec } from "../contracts/runspec";
|
|
8
|
+
import { type PostgresMutationJournalCoordinator } from "./postgres-mutation-journal";
|
|
9
|
+
export declare class PostgresRunAuthority {
|
|
10
|
+
private readonly sql;
|
|
11
|
+
private readonly clock;
|
|
12
|
+
private readonly ids;
|
|
13
|
+
private readonly mutationJournal;
|
|
14
|
+
constructor(sql: SQL, clock: Clock, ids: IdFactory, mutationJournal: PostgresMutationJournalCoordinator);
|
|
15
|
+
snapshot(): Promise<{
|
|
16
|
+
authority_epoch: Int64;
|
|
17
|
+
}>;
|
|
18
|
+
validateRunSpec(input: unknown): Promise<{
|
|
19
|
+
valid: true;
|
|
20
|
+
authority_epoch: Int64;
|
|
21
|
+
run_spec: RunSpec;
|
|
22
|
+
run_spec_digest: string;
|
|
23
|
+
}>;
|
|
24
|
+
planRun(input: unknown): Promise<{
|
|
25
|
+
authority_epoch: Int64;
|
|
26
|
+
run_spec: RunSpec;
|
|
27
|
+
run_spec_digest: string;
|
|
28
|
+
budget_ceiling_minor_units: number;
|
|
29
|
+
required_approvals: string[];
|
|
30
|
+
denials: string[];
|
|
31
|
+
}>;
|
|
32
|
+
listCapabilities(actorPrincipalInput: string): Promise<CapabilityProjection>;
|
|
33
|
+
submitRun(specInput: unknown, context: SubmitRunContext): Promise<SubmitRunResult>;
|
|
34
|
+
getRun(runIdInput: string, actorPrincipalInput: string): Promise<{
|
|
35
|
+
run: RunRecord;
|
|
36
|
+
attempt: AttemptRecord;
|
|
37
|
+
run_spec: RunSpec;
|
|
38
|
+
}>;
|
|
39
|
+
listRuns(actorPrincipalInput: string, options?: {
|
|
40
|
+
limit?: number;
|
|
41
|
+
cursor?: string;
|
|
42
|
+
}): Promise<{
|
|
43
|
+
items: Array<{
|
|
44
|
+
run: RunRecord;
|
|
45
|
+
attempt: AttemptRecord;
|
|
46
|
+
run_spec: RunSpec;
|
|
47
|
+
}>;
|
|
48
|
+
next_cursor: string | null;
|
|
49
|
+
}>;
|
|
50
|
+
waitRun(runIdInput: string, actorPrincipalInput: string, timeoutMsInput: number): Promise<RunWaitProjection>;
|
|
51
|
+
readRunEvents(runIdInput: string, actorPrincipalInput: string, options: {
|
|
52
|
+
cursor: string;
|
|
53
|
+
limit: number;
|
|
54
|
+
waitMs: number;
|
|
55
|
+
}): Promise<RunEventPage>;
|
|
56
|
+
cancelRun(runIdInput: string, context: PublicRunMutationContext & {
|
|
57
|
+
reasonCode: string;
|
|
58
|
+
}): Promise<RunMutationResult>;
|
|
59
|
+
retryRun(runIdInput: string, context: PublicRunMutationContext): Promise<RunMutationResult>;
|
|
60
|
+
resolveOperation(operationIdInput: string, actorPrincipalInput: string): Promise<Record<string, unknown>>;
|
|
61
|
+
private currentAuthorityEpoch;
|
|
62
|
+
private lockRuntimeMeta;
|
|
63
|
+
private prepareMutation;
|
|
64
|
+
private recordMutation;
|
|
65
|
+
private persistMutationEnvelope;
|
|
66
|
+
private appendRunEvent;
|
|
67
|
+
private databaseTime;
|
|
68
|
+
}
|
|
69
|
+
export declare function runSerializableMutation<T>(operation: () => Promise<T>, attempts?: number): Promise<T>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { SQL } from "bun";
|
|
2
|
+
import { type AuthorityMutationJournalPort, type AuthorityMutationJournalProtection, type AuthorityMutationJournalReceiptVerifier, type AuthorityMutationJournalSigner } from "../authority/mutation-journal";
|
|
3
|
+
export declare const POSTGRES_EXTERNAL_MUTATION_JOURNAL_MIGRATION_MANIFEST: Readonly<{
|
|
4
|
+
readonly "0001_external_authority_mutation_journal.sql": "sha256:ead2509a00dc767b855711be54f7480eaa09e0928cd16b1b86dc5a79b57c9b52";
|
|
5
|
+
}>;
|
|
6
|
+
export interface PostgresExternalMutationJournalOptions {
|
|
7
|
+
readonly signer: AuthorityMutationJournalSigner;
|
|
8
|
+
readonly verifier: AuthorityMutationJournalReceiptVerifier;
|
|
9
|
+
readonly journalId: string;
|
|
10
|
+
readonly restoreDomainId: string;
|
|
11
|
+
readonly encryptedAtRest: true;
|
|
12
|
+
readonly requiredRole?: string;
|
|
13
|
+
}
|
|
14
|
+
export interface PostgresExternalMutationJournalMigrationResult {
|
|
15
|
+
readonly applied: readonly string[];
|
|
16
|
+
readonly alreadyApplied: readonly string[];
|
|
17
|
+
}
|
|
18
|
+
export declare function createPostgresExternalMutationJournal(sql: SQL, options: PostgresExternalMutationJournalOptions): Promise<AuthorityMutationJournalPort>;
|
|
19
|
+
export declare function initializePostgresExternalMutationJournalStore(primarySql: SQL, journalSql: SQL, options: Omit<PostgresExternalMutationJournalOptions, "requiredRole">): Promise<Readonly<AuthorityMutationJournalProtection>>;
|
|
20
|
+
export declare function applyPostgresExternalMutationJournalMigrations(sql: SQL, directory?: string): Promise<PostgresExternalMutationJournalMigrationResult>;
|
|
21
|
+
export declare function configurePostgresExternalMutationJournalRole(sql: SQL, roleName?: string): Promise<void>;
|
|
22
|
+
export declare function assertPostgresExternalMutationJournalDatabaseSeparated(primarySql: SQL, journalSql: SQL): Promise<void>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function parsePostgresJsonText(value: unknown, label: string): unknown;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { SQL } from "bun";
|
|
2
|
+
import { type AuthorityMutationAppendReceipt, type AuthorityMutationJournalPort, type AuthorityMutationJournalProtection, type AuthorityMutationJournalReceiptVerifier } from "../authority/mutation-journal";
|
|
3
|
+
import { type Int64 } from "../core/int64";
|
|
4
|
+
export declare const MAX_V1_MUTATION_JOURNAL_STARTUP_RECORDS = 10000n;
|
|
5
|
+
export declare class PostgresMutationJournalCoordinator {
|
|
6
|
+
private readonly readSql;
|
|
7
|
+
private readonly acknowledgementSql;
|
|
8
|
+
private readonly journal;
|
|
9
|
+
private readonly verifier;
|
|
10
|
+
private readonly authorityRestoreDomainId;
|
|
11
|
+
private initialized;
|
|
12
|
+
private readonly expectedProtection;
|
|
13
|
+
constructor(readSql: SQL, acknowledgementSql: SQL, journal: AuthorityMutationJournalPort, verifier: AuthorityMutationJournalReceiptVerifier, authorityRestoreDomainId: string, expectedProtectionInput: Readonly<AuthorityMutationJournalProtection>);
|
|
14
|
+
initialize(): Promise<void>;
|
|
15
|
+
private assertExpectedProtection;
|
|
16
|
+
private guardedJournalCall;
|
|
17
|
+
private assertExpectedAcknowledgement;
|
|
18
|
+
private verifyExpectedAcknowledgementValue;
|
|
19
|
+
private readJournalHead;
|
|
20
|
+
private readJournalRange;
|
|
21
|
+
private appendJournalEnvelope;
|
|
22
|
+
private readExternalAcknowledgedPrefix;
|
|
23
|
+
private readLocalJournalSnapshot;
|
|
24
|
+
ensureAcknowledged(commitSequenceInput: Int64): Promise<Readonly<AuthorityMutationAppendReceipt>>;
|
|
25
|
+
verifyAcknowledgedMembership(commitSequenceInput: Int64, expectedEnvelopeInput: unknown): Promise<Readonly<AuthorityMutationAppendReceipt>>;
|
|
26
|
+
private readLocalMembershipSnapshot;
|
|
27
|
+
reconcilePending(limitInput?: number): Promise<number>;
|
|
28
|
+
verifyReady(): Promise<void>;
|
|
29
|
+
private requireInitialized;
|
|
30
|
+
}
|
|
31
|
+
export declare function runSerializableAcknowledgement<T>(operation: () => Promise<T>, attempts?: number): Promise<T>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { SQL } from "bun";
|
|
2
|
+
import { type EffectJournalPort, type EffectJournalReceiptVerifier, type StoredEffectJournalRecord } from "../authority/effect-journal";
|
|
3
|
+
import { type Int64 } from "../core/int64";
|
|
4
|
+
export declare const MAX_V1_EFFECT_JOURNAL_STARTUP_RECORDS = 10000n;
|
|
5
|
+
export type EffectJournalAnchorVerifier = EffectJournalReceiptVerifier;
|
|
6
|
+
export interface LeasedOutboxRecord {
|
|
7
|
+
id: string;
|
|
8
|
+
event_id: string;
|
|
9
|
+
payload_digest: string;
|
|
10
|
+
authority_commit_sequence: Int64;
|
|
11
|
+
event_record: unknown;
|
|
12
|
+
lease_expires_at: string;
|
|
13
|
+
}
|
|
14
|
+
export declare class PostgresReconciler {
|
|
15
|
+
private readonly sql;
|
|
16
|
+
private readonly effectJournal;
|
|
17
|
+
private readonly effectVerifier;
|
|
18
|
+
private readonly authorityRestoreDomainId;
|
|
19
|
+
private effectProtection;
|
|
20
|
+
constructor(sql: SQL, effectJournal: EffectJournalPort, effectVerifier: EffectJournalAnchorVerifier, authorityRestoreDomainId: string);
|
|
21
|
+
leaseOutbox(ownerInput: string, leaseDurationMs: number, limit?: number): Promise<readonly LeasedOutboxRecord[]>;
|
|
22
|
+
markOutboxDelivered(idInput: string, ownerInput: string): Promise<void>;
|
|
23
|
+
recoverExpiredOutboxLeases(): Promise<number>;
|
|
24
|
+
appendEffectAnchor(stepInput: unknown, anchorInput: unknown): Promise<Readonly<StoredEffectJournalRecord>>;
|
|
25
|
+
verifyEffectFrontier(): Promise<{
|
|
26
|
+
journal_sequence: Int64;
|
|
27
|
+
frontier_digest: string | null;
|
|
28
|
+
}>;
|
|
29
|
+
private pinVerifiedExternalHighWater;
|
|
30
|
+
private readAndVerifyLocalEffectFrontier;
|
|
31
|
+
private verifyExternalHead;
|
|
32
|
+
private readExternalPrefix;
|
|
33
|
+
private verifyExternalAnchorMembership;
|
|
34
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { SQL } from "bun";
|
|
2
|
+
import { type InMemoryAccountsOperationSignerHistory } from "../ports/accounts-operation";
|
|
3
|
+
import { type SandboxDispatchAuthorityPortV2 } from "../ports/sandbox-dispatch-authority";
|
|
4
|
+
import { type PostgresMutationJournalCoordinator } from "./postgres-mutation-journal";
|
|
5
|
+
export declare function createPostgresSandboxDispatchAuthorityV2(input: Readonly<{
|
|
6
|
+
sql: SQL;
|
|
7
|
+
signerHistory: InMemoryAccountsOperationSignerHistory;
|
|
8
|
+
mutationJournal: PostgresMutationJournalCoordinator;
|
|
9
|
+
}>): SandboxDispatchAuthorityPortV2;
|