@haywoodmarx/agent-pager 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 (178) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +63 -0
  3. package/dist/src/broker/address.d.ts +49 -0
  4. package/dist/src/broker/address.js +110 -0
  5. package/dist/src/broker/broker.d.ts +665 -0
  6. package/dist/src/broker/broker.js +2270 -0
  7. package/dist/src/broker/database.d.ts +81 -0
  8. package/dist/src/broker/database.js +69 -0
  9. package/dist/src/broker/operator-projection.d.ts +291 -0
  10. package/dist/src/broker/operator-projection.js +722 -0
  11. package/dist/src/broker/protocol.d.ts +237 -0
  12. package/dist/src/broker/protocol.js +311 -0
  13. package/dist/src/broker/schema.d.ts +94 -0
  14. package/dist/src/broker/schema.js +454 -0
  15. package/dist/src/broker/snapshot.d.ts +171 -0
  16. package/dist/src/broker/snapshot.js +78 -0
  17. package/dist/src/configuration-defaults.d.ts +64 -0
  18. package/dist/src/configuration-defaults.js +48 -0
  19. package/dist/src/configuration.d.ts +76 -0
  20. package/dist/src/configuration.js +156 -0
  21. package/dist/src/implementations/claude/environment.d.ts +8 -0
  22. package/dist/src/implementations/claude/environment.js +9 -0
  23. package/dist/src/implementations/claude/gateway-cli.d.ts +2 -0
  24. package/dist/src/implementations/claude/gateway-cli.js +136 -0
  25. package/dist/src/implementations/claude/gateway-identity.d.ts +134 -0
  26. package/dist/src/implementations/claude/gateway-identity.js +103 -0
  27. package/dist/src/implementations/claude/gateway.d.ts +148 -0
  28. package/dist/src/implementations/claude/gateway.js +236 -0
  29. package/dist/src/implementations/claude/instructions.d.ts +33 -0
  30. package/dist/src/implementations/claude/instructions.js +64 -0
  31. package/dist/src/implementations/claude/manifest.d.ts +33 -0
  32. package/dist/src/implementations/claude/manifest.js +108 -0
  33. package/dist/src/implementations/claude/plugin-directory.d.ts +80 -0
  34. package/dist/src/implementations/claude/plugin-directory.js +137 -0
  35. package/dist/src/implementations/claude/session-continuation.d.ts +25 -0
  36. package/dist/src/implementations/claude/session-continuation.js +125 -0
  37. package/dist/src/implementations/claude/session-identity.d.ts +25 -0
  38. package/dist/src/implementations/claude/session-identity.js +31 -0
  39. package/dist/src/implementations/claude/session-start-cli.d.ts +2 -0
  40. package/dist/src/implementations/claude/session-start-cli.js +16 -0
  41. package/dist/src/implementations/claude/socket-delivery.d.ts +52 -0
  42. package/dist/src/implementations/claude/socket-delivery.js +159 -0
  43. package/dist/src/implementations/model.d.ts +162 -0
  44. package/dist/src/implementations/model.js +1 -0
  45. package/dist/src/implementations/opencode/adapter.d.ts +71 -0
  46. package/dist/src/implementations/opencode/adapter.js +94 -0
  47. package/dist/src/implementations/opencode/environment.d.ts +8 -0
  48. package/dist/src/implementations/opencode/environment.js +9 -0
  49. package/dist/src/implementations/opencode/manifest.d.ts +30 -0
  50. package/dist/src/implementations/opencode/manifest.js +93 -0
  51. package/dist/src/implementations/opencode/plugin-api.d.ts +120 -0
  52. package/dist/src/implementations/opencode/plugin-api.js +1 -0
  53. package/dist/src/implementations/opencode/plugin.d.ts +38 -0
  54. package/dist/src/implementations/opencode/plugin.js +303 -0
  55. package/dist/src/implementations/opencode/self-close-tool.d.ts +9 -0
  56. package/dist/src/implementations/opencode/self-close-tool.js +31 -0
  57. package/dist/src/implementations/orca/terminal.d.ts +48 -0
  58. package/dist/src/implementations/orca/terminal.js +154 -0
  59. package/dist/src/implementations/pi/broker-client.d.ts +56 -0
  60. package/dist/src/implementations/pi/broker-client.js +156 -0
  61. package/dist/src/implementations/pi/environment.d.ts +8 -0
  62. package/dist/src/implementations/pi/environment.js +9 -0
  63. package/dist/src/implementations/pi/extension.d.ts +57 -0
  64. package/dist/src/implementations/pi/extension.js +253 -0
  65. package/dist/src/implementations/pi/host-slots.d.ts +18 -0
  66. package/dist/src/implementations/pi/host-slots.js +27 -0
  67. package/dist/src/implementations/pi/manifest.d.ts +11 -0
  68. package/dist/src/implementations/pi/manifest.js +61 -0
  69. package/dist/src/implementations/pi/self-close-tool.d.ts +7 -0
  70. package/dist/src/implementations/pi/self-close-tool.js +27 -0
  71. package/dist/src/implementations/registry.d.ts +47 -0
  72. package/dist/src/implementations/registry.js +157 -0
  73. package/dist/src/implementations/session-key.d.ts +13 -0
  74. package/dist/src/implementations/session-key.js +19 -0
  75. package/dist/src/index.d.ts +27 -0
  76. package/dist/src/index.js +26 -0
  77. package/dist/src/launch/broker-lock.d.ts +257 -0
  78. package/dist/src/launch/broker-lock.js +644 -0
  79. package/dist/src/launch/cli.d.ts +37 -0
  80. package/dist/src/launch/cli.js +317 -0
  81. package/dist/src/launch/environment.d.ts +45 -0
  82. package/dist/src/launch/environment.js +48 -0
  83. package/dist/src/launch/launch.d.ts +235 -0
  84. package/dist/src/launch/launch.js +223 -0
  85. package/dist/src/launch/on-demand.d.ts +202 -0
  86. package/dist/src/launch/on-demand.js +435 -0
  87. package/dist/src/launch/runtime-composition.d.ts +88 -0
  88. package/dist/src/launch/runtime-composition.js +253 -0
  89. package/dist/src/launch/runtime.d.ts +79 -0
  90. package/dist/src/launch/runtime.js +196 -0
  91. package/dist/src/launch/service-system.d.ts +11 -0
  92. package/dist/src/launch/service-system.js +39 -0
  93. package/dist/src/launch/service.d.ts +173 -0
  94. package/dist/src/launch/service.js +492 -0
  95. package/dist/src/launch/skill.d.ts +57 -0
  96. package/dist/src/launch/skill.js +81 -0
  97. package/dist/src/launch/terminal.d.ts +26 -0
  98. package/dist/src/launch/terminal.js +43 -0
  99. package/dist/src/launch/workspace-branch.d.ts +10 -0
  100. package/dist/src/launch/workspace-branch.js +29 -0
  101. package/dist/src/messaging/delivery-client.d.ts +144 -0
  102. package/dist/src/messaging/delivery-client.js +261 -0
  103. package/dist/src/messaging/delivery.d.ts +75 -0
  104. package/dist/src/messaging/delivery.js +22 -0
  105. package/dist/src/messaging/inbox-socket.d.ts +98 -0
  106. package/dist/src/messaging/inbox-socket.js +278 -0
  107. package/dist/src/messaging/mcp.d.ts +53 -0
  108. package/dist/src/messaging/mcp.js +501 -0
  109. package/dist/src/messaging/notifications.d.ts +231 -0
  110. package/dist/src/messaging/notifications.js +489 -0
  111. package/dist/src/messaging/push-delivery.d.ts +77 -0
  112. package/dist/src/messaging/push-delivery.js +187 -0
  113. package/dist/src/messaging/tools.d.ts +11 -0
  114. package/dist/src/messaging/tools.js +102 -0
  115. package/dist/src/messaging/wake.d.ts +23 -0
  116. package/dist/src/messaging/wake.js +39 -0
  117. package/dist/src/operator/agent-projection.d.ts +102 -0
  118. package/dist/src/operator/agent-projection.js +249 -0
  119. package/dist/src/operator/commands.d.ts +50 -0
  120. package/dist/src/operator/commands.js +199 -0
  121. package/dist/src/operator/diagnostics.d.ts +21 -0
  122. package/dist/src/operator/diagnostics.js +22 -0
  123. package/dist/src/operator/protocol.d.ts +511 -0
  124. package/dist/src/operator/protocol.js +49 -0
  125. package/dist/src/operator/repository-system.d.ts +14 -0
  126. package/dist/src/operator/repository-system.js +150 -0
  127. package/dist/src/operator/repository.d.ts +79 -0
  128. package/dist/src/operator/repository.js +72 -0
  129. package/dist/src/operator/traffic-projection.d.ts +19 -0
  130. package/dist/src/operator/traffic-projection.js +229 -0
  131. package/dist/src/operator/transport.d.ts +87 -0
  132. package/dist/src/operator/transport.js +549 -0
  133. package/dist/src/operator/update-store.d.ts +53 -0
  134. package/dist/src/operator/update-store.js +162 -0
  135. package/dist/src/operator/updates.d.ts +94 -0
  136. package/dist/src/operator/updates.js +280 -0
  137. package/dist/src/operator/validation.d.ts +114 -0
  138. package/dist/src/operator/validation.js +916 -0
  139. package/dist/src/shared/guards.d.ts +59 -0
  140. package/dist/src/shared/guards.js +119 -0
  141. package/dist/src/shared/http.d.ts +30 -0
  142. package/dist/src/shared/http.js +50 -0
  143. package/dist/src/shared/row.d.ts +2 -0
  144. package/dist/src/shared/row.js +1 -0
  145. package/dist/src/shared/shell.d.ts +6 -0
  146. package/dist/src/shared/shell.js +8 -0
  147. package/dist/src/tui/actions.d.ts +166 -0
  148. package/dist/src/tui/actions.js +253 -0
  149. package/dist/src/tui/agent-tree.d.ts +125 -0
  150. package/dist/src/tui/agent-tree.js +663 -0
  151. package/dist/src/tui/app.d.ts +38 -0
  152. package/dist/src/tui/app.js +378 -0
  153. package/dist/src/tui/chrome.d.ts +86 -0
  154. package/dist/src/tui/chrome.js +85 -0
  155. package/dist/src/tui/client.d.ts +41 -0
  156. package/dist/src/tui/client.js +279 -0
  157. package/dist/src/tui/composition.d.ts +41 -0
  158. package/dist/src/tui/composition.js +146 -0
  159. package/dist/src/tui/message-views.d.ts +94 -0
  160. package/dist/src/tui/message-views.js +515 -0
  161. package/dist/src/tui/model.d.ts +414 -0
  162. package/dist/src/tui/model.js +758 -0
  163. package/dist/src/tui/presentation.d.ts +350 -0
  164. package/dist/src/tui/presentation.js +541 -0
  165. package/dist/src/tui/production.d.ts +79 -0
  166. package/dist/src/tui/production.js +253 -0
  167. package/dist/src/tui/run-terminal.d.ts +32 -0
  168. package/dist/src/tui/run-terminal.js +54 -0
  169. package/dist/src/tui/runtime.d.ts +113 -0
  170. package/dist/src/tui/runtime.js +189 -0
  171. package/dist/src/tui/theme.d.ts +49 -0
  172. package/dist/src/tui/theme.js +55 -0
  173. package/dist/src/tui/transport.d.ts +31 -0
  174. package/dist/src/tui/transport.js +255 -0
  175. package/dist/src/version.d.ts +11 -0
  176. package/dist/src/version.js +52 -0
  177. package/package.json +142 -0
  178. package/skills/pager/SKILL.md +112 -0
@@ -0,0 +1,27 @@
1
+ export { Broker, type AgentImplementation, type AttachmentChannel, type BrokerCommit, type BrokerCommitListener, type BrokerFetchRequest, type BrokerOperationalEvent, type BrokerOptions, type ClaimedMessage, type ClaimSource, type NotificationOutcome, type ResumeSessionRequest, } from "./broker/broker.js";
2
+ export { type AgentLifecycleState, type LifecycleTone } from "./broker/schema.js";
3
+ export { ProtocolError, assertAgentId, assertProtocolVersion, decodeMessageBody, encodeMessageBody, hasControlCharacter, isAgentId, isDirectAgentAddress, isImplementationId, isOpaqueId, isSessionKey, issueOpaqueToken, lifecycleEventState, mintAgentId, normalizeMessageSubject, normalizeMessageType, validateImplementationId, validateSessionKey, AGENT_ID_SCHEME, FETCH_LIMIT_DEFAULT, FETCH_LIMIT_MAX, IMPLEMENTATION_ID_MAX_LENGTH, IMPLEMENTATION_ID_PATTERN, MESSAGE_BODY_LIMIT_BYTES, MESSAGE_SUBJECT_LIMIT_CHARACTERS, MESSAGE_TYPE_LIMIT_CHARACTERS, PROTOCOL_VERSION, REGISTRATION_SESSION_NAME_MAX_LENGTH, SESSION_IDENTIFIER_PATTERN, SESSION_KEY_MAX_LENGTH, type AgentId, type LifecycleEventType, type MessageState, } from "./broker/protocol.js";
4
+ export { publicEpoch, startSnapshotServer, type BrokerSnapshot, type SnapshotAgent, type SnapshotDelivery, type SnapshotDiagnostics, type SnapshotHealth, type SnapshotLifecycleEntry, type SnapshotServerHandle, type SnapshotWorkspace, } from "./broker/snapshot.js";
5
+ export { parseAgentAddress, workspaceTeamId } from "./broker/address.js";
6
+ export type { HostPushNotificationCapability, HostRegistrationCommand, HostRegistrationImplementationCapability, HostWake, ImplementationCapabilityName, ImplementationDescriptor, ImplementationId, ImplementationLaunchPlan, ImplementationLaunchRequest, ImplementationProvider, KnownValue, LaunchImplementationCapability, NotificationImplementationCapability, SessionIdentityImplementationCapability, SessionIdentityInput, UnsupportedImplementationCapability, } from "./implementations/model.js";
7
+ export { ImplementationRegistry, assertImplementationProvider, discoverImplementationRegistry, implementationId, type ImplementationDiscoveryPort, } from "./implementations/registry.js";
8
+ export { harnessSessionKey } from "./implementations/session-key.js";
9
+ export { createImplementationRegistry } from "./launch/runtime-composition.js";
10
+ export { PAGER_DEFAULTS, ConfigurationError, initializePagerStore, loadPagerConfiguration, resolvePagerStoreDirectory, resolveConfigurationSetting, type PagerConfig, type ConfigurationLoadOptions, type ConfigurationSettingPrecedence, type LoadedConfiguration, } from "./configuration.js";
11
+ export { DirectTerminalProvider, ForegroundTerminalProvider, LaunchService, renderLaunchResult, type AttachState, type ForegroundProcessSpawner, type LaunchDiagnostic, type LaunchRequest, type LaunchResult, type ProcessSpawner, type ProcessState, type TerminalLaunch, type TerminalProvider, type TerminalProviderName, type TerminalSession, type TerminalTaskCompletion, } from "./launch/launch.js";
12
+ export { BunRuntimeError, assertSupportedBunRuntime, probeBunVersion, resolveBunExecutable, satisfiesBunVersionFloor, BUN_PATH_ENVIRONMENT, MINIMUM_BUN_VERSION, RETIRED_NODE_PATH_ENVIRONMENT, type RuntimeProbe, } from "./launch/runtime.js";
13
+ export { BrokerService, EndpointPortUnavailableError, systemWorkspaceBranch, type BrokerServiceOptions, type BrokerServiceStatus, } from "./launch/service.js";
14
+ export { systemBrokerServiceFilesystem, systemBrokerServiceScheduler } from "./launch/service-system.js";
15
+ export { BrokerLockGuard, brokerLockPath } from "./launch/broker-lock.js";
16
+ export { readRuntimeEnvironment, PAGER_AGENT_ID_ENVIRONMENT, PAGER_ATTACH_RESERVATION_ENVIRONMENT, PAGER_BROKER_URL_ENVIRONMENT, PAGER_MCP_URL_ENVIRONMENT, type RuntimeEnvironment, } from "./launch/environment.js";
17
+ export { claimsWakeContent, CLAIMS_WAKE_PREFIX, type ClaimsDelivered, type DeliveryAddress, type DeliveryReach, type MessageClaim, } from "./messaging/delivery.js";
18
+ export { BrokerDeliveryClient, adoptRotation, asRecord, compatibilityPayload, exactRecord, registerAgent, rpcEnvelope, type AttachDeliveryClientOptions, type AttachedSession, type BrokerIdentity, type BrokerRequest, } from "./messaging/delivery-client.js";
19
+ export { startMcpServer, DELIVERY_ADDRESS_HEADER, type McpNotificationPort, type McpServerHandle, type StartMcpServerOptions, } from "./messaging/mcp.js";
20
+ export { NotificationHub, NotificationScheduler, NotificationValidationError, NOTIFICATION_OPERATIONAL_EVENT_LIMIT, OPERATOR_CONTROL_CORRELATION_LIMIT, type AdapterCapabilities, type BusyWakeRelease, type InboxChanged, type InboxMessageChanged, type InboxMessageReason, type NotificationBroker, type NotificationEvent, type NotificationSubscriberFailure, type OperatorPingAdmission, type OperatorPingChanged, } from "./messaging/notifications.js";
21
+ export { PushDeliveryService, type DeliveryAddressRegistration, type PushDeliveryBroker, type PushDeliveryDependencies, type PushDeliveryScheduler, } from "./messaging/push-delivery.js";
22
+ export { MCP_TOOLS, type McpToolDefinition } from "./messaging/tools.js";
23
+ export { PAGER_WAKE_TYPE, wakeLine, wakeMetadata } from "./messaging/wake.js";
24
+ export { classifyOperatorEvent, validateOperatorAgent, validateOperatorCommand, validateOperatorCommandResult, validateOperatorCommandResultForCommand, validateOperatorControlId, validateOperatorCursor, validateOperatorDiagnostic, validateOperatorEventEnvelope, validateOperatorMessageBody, validateOperatorRepository, validateOperatorSnapshot, validateOperatorSnapshotByteLength, validateOperatorTraffic, validateOperatorTransportRequest, OperatorValidationError, OPERATOR_ARRAY_LENGTH_LIMIT, } from "./operator/validation.js";
25
+ export { OPERATOR_DIAGNOSTIC_TEXT_LIMIT, OPERATOR_PROTOCOL_VERSION, OPERATOR_REJECTION_REASONS, OPERATOR_SNAPSHOT_CHUNK_BYTES, OPERATOR_SNAPSHOT_TOTAL_LIMIT_BYTES, OPERATOR_TRANSPORT_FRAME_LIMIT_BYTES, type OperatorAcceptedDelivery, type OperatorAdapterState, type OperatorAgent, type OperatorCommand, type OperatorCommandEnvelope, type OperatorCommandEnvelopeFor, type OperatorCommandResult, type OperatorCorrelatedCommandResult, type OperatorCursor, type OperatorCursorResult, type OperatorDeliveryLifecycleEntry, type OperatorDiagnostic, type OperatorDiagnosticSeverity, type OperatorEventEnvelope, type OperatorImplementation, type OperatorImplementationVersion, type OperatorJsonObject, type OperatorJsonValue, type OperatorMessageBody, type OperatorPingAudit, type OperatorRejectionReason, type OperatorRepository, type OperatorResyncReason, type OperatorSnapshot, type OperatorStateEvent, type OperatorTraffic, type OperatorTransportFrame, type OperatorTransportRequest, type OperatorWorktree, } from "./operator/protocol.js";
26
+ export { PAGER_VERSION } from "./version.js";
27
+ export { shellQuote } from "./shared/shell.js";
@@ -0,0 +1,26 @@
1
+ export { Broker, } from "./broker/broker.js";
2
+ export {} from "./broker/schema.js";
3
+ export { ProtocolError, assertAgentId, assertProtocolVersion, decodeMessageBody, encodeMessageBody, hasControlCharacter, isAgentId, isDirectAgentAddress, isImplementationId, isOpaqueId, isSessionKey, issueOpaqueToken, lifecycleEventState, mintAgentId, normalizeMessageSubject, normalizeMessageType, validateImplementationId, validateSessionKey, AGENT_ID_SCHEME, FETCH_LIMIT_DEFAULT, FETCH_LIMIT_MAX, IMPLEMENTATION_ID_MAX_LENGTH, IMPLEMENTATION_ID_PATTERN, MESSAGE_BODY_LIMIT_BYTES, MESSAGE_SUBJECT_LIMIT_CHARACTERS, MESSAGE_TYPE_LIMIT_CHARACTERS, PROTOCOL_VERSION, REGISTRATION_SESSION_NAME_MAX_LENGTH, SESSION_IDENTIFIER_PATTERN, SESSION_KEY_MAX_LENGTH, } from "./broker/protocol.js";
4
+ export { publicEpoch, startSnapshotServer, } from "./broker/snapshot.js";
5
+ export { parseAgentAddress, workspaceTeamId } from "./broker/address.js";
6
+ export { ImplementationRegistry, assertImplementationProvider, discoverImplementationRegistry, implementationId, } from "./implementations/registry.js";
7
+ export { harnessSessionKey } from "./implementations/session-key.js";
8
+ export { createImplementationRegistry } from "./launch/runtime-composition.js";
9
+ export { PAGER_DEFAULTS, ConfigurationError, initializePagerStore, loadPagerConfiguration, resolvePagerStoreDirectory, resolveConfigurationSetting, } from "./configuration.js";
10
+ export { DirectTerminalProvider, ForegroundTerminalProvider, LaunchService, renderLaunchResult, } from "./launch/launch.js";
11
+ export { BunRuntimeError, assertSupportedBunRuntime, probeBunVersion, resolveBunExecutable, satisfiesBunVersionFloor, BUN_PATH_ENVIRONMENT, MINIMUM_BUN_VERSION, RETIRED_NODE_PATH_ENVIRONMENT, } from "./launch/runtime.js";
12
+ export { BrokerService, EndpointPortUnavailableError, systemWorkspaceBranch, } from "./launch/service.js";
13
+ export { systemBrokerServiceFilesystem, systemBrokerServiceScheduler } from "./launch/service-system.js";
14
+ export { BrokerLockGuard, brokerLockPath } from "./launch/broker-lock.js";
15
+ export { readRuntimeEnvironment, PAGER_AGENT_ID_ENVIRONMENT, PAGER_ATTACH_RESERVATION_ENVIRONMENT, PAGER_BROKER_URL_ENVIRONMENT, PAGER_MCP_URL_ENVIRONMENT, } from "./launch/environment.js";
16
+ export { claimsWakeContent, CLAIMS_WAKE_PREFIX, } from "./messaging/delivery.js";
17
+ export { BrokerDeliveryClient, adoptRotation, asRecord, compatibilityPayload, exactRecord, registerAgent, rpcEnvelope, } from "./messaging/delivery-client.js";
18
+ export { startMcpServer, DELIVERY_ADDRESS_HEADER, } from "./messaging/mcp.js";
19
+ export { NotificationHub, NotificationScheduler, NotificationValidationError, NOTIFICATION_OPERATIONAL_EVENT_LIMIT, OPERATOR_CONTROL_CORRELATION_LIMIT, } from "./messaging/notifications.js";
20
+ export { PushDeliveryService, } from "./messaging/push-delivery.js";
21
+ export { MCP_TOOLS } from "./messaging/tools.js";
22
+ export { PAGER_WAKE_TYPE, wakeLine, wakeMetadata } from "./messaging/wake.js";
23
+ export { classifyOperatorEvent, validateOperatorAgent, validateOperatorCommand, validateOperatorCommandResult, validateOperatorCommandResultForCommand, validateOperatorControlId, validateOperatorCursor, validateOperatorDiagnostic, validateOperatorEventEnvelope, validateOperatorMessageBody, validateOperatorRepository, validateOperatorSnapshot, validateOperatorSnapshotByteLength, validateOperatorTraffic, validateOperatorTransportRequest, OperatorValidationError, OPERATOR_ARRAY_LENGTH_LIMIT, } from "./operator/validation.js";
24
+ export { OPERATOR_DIAGNOSTIC_TEXT_LIMIT, OPERATOR_PROTOCOL_VERSION, OPERATOR_REJECTION_REASONS, OPERATOR_SNAPSHOT_CHUNK_BYTES, OPERATOR_SNAPSHOT_TOTAL_LIMIT_BYTES, OPERATOR_TRANSPORT_FRAME_LIMIT_BYTES, } from "./operator/protocol.js";
25
+ export { PAGER_VERSION } from "./version.js";
26
+ export { shellQuote } from "./shared/shell.js";
@@ -0,0 +1,257 @@
1
+ import { ProtocolError, type BrokerServiceIdentity } from "../broker/protocol.js";
2
+ /** Identifies the ownership schema understood by this release. */
3
+ export declare const SERVICE_PROTOCOL_VERSION = 1;
4
+ /** Identifies the package build that owns production service state. */
5
+ export declare const SERVICE_BUILD_ID: string;
6
+ /** Identifies the production runtime required to own SQLite. */
7
+ export declare const SERVICE_RUNTIME = "bun";
8
+ /** Describes the process ownership record published beside a broker database. */
9
+ export type BrokerLock = {
10
+ /** Identifies the process that owns the lock. */
11
+ pid: number;
12
+ /** Identifies the broker generation held by the process. */
13
+ epoch: string;
14
+ /** Locates the shared MCP endpoint after service startup. */
15
+ mcpUrl?: string;
16
+ /** Locates the shared snapshot origin after service startup. */
17
+ snapshotUrl?: string;
18
+ /** Locates the loopback operator TCP stream when its projection boundary is available. */
19
+ operatorUrl?: string;
20
+ /**
21
+ * Identifies the acquisition that created the record. Only the acquisition holding this token may
22
+ * replace or remove the lock, so a reclaimer cannot delete a lock that was rewritten underneath it.
23
+ */
24
+ holder?: string;
25
+ /**
26
+ * Records the owning process's start time as the platform reports it. Absent where the platform
27
+ * cannot report one; present, it distinguishes the owner from a later process given its pid.
28
+ */
29
+ ownerStartedAt?: string;
30
+ } & BrokerServiceIdentity;
31
+ /**
32
+ * Returns the identity published by the current Bun service build.
33
+ * @returns - Runtime, build, and wire-protocol ownership fields.
34
+ */
35
+ export declare function currentBrokerServiceIdentity(): BrokerServiceIdentity;
36
+ /**
37
+ * Report whether a lock belongs to the current production service contract.
38
+ * @param lock - Candidate lock identity from an untrusted adjacent file.
39
+ * @returns - True only for the current Bun build and wire protocol.
40
+ */
41
+ export declare function brokerLockHasCurrentIdentity(lock: BrokerLock | undefined): boolean;
42
+ /**
43
+ * Validate an untrusted health payload against the current service contract.
44
+ * @param value - Parsed health response or lock-shaped object.
45
+ * @returns - True when it names a supported Bun and the current build/protocol.
46
+ */
47
+ export declare function isCurrentBrokerServiceIdentity(value: unknown): value is BrokerServiceIdentity;
48
+ /**
49
+ * Report whether a lock names a live, current-build service that has left its starting epoch.
50
+ * @param lock - Candidate lock identity from an untrusted adjacent file.
51
+ * @param isAlive - Operating-system liveness boundary.
52
+ * @returns - True only for a live service whose published endpoints a reader may use.
53
+ */
54
+ export declare function brokerLockIsLive(lock: BrokerLock | undefined, isAlive: (pid: number) => boolean): lock is BrokerLock;
55
+ /**
56
+ * Read only the process id from any structurally valid current or legacy lock.
57
+ * @param lockPath - File containing a candidate ownership record.
58
+ * @returns - Positive process id when the file carries one.
59
+ */
60
+ export declare function readBrokerOwnerPid(lockPath: string): number | undefined;
61
+ /**
62
+ * Read the owning process from any structurally valid current or legacy lock.
63
+ *
64
+ * Reads only the fields every build has written, so a lock left by a build whose full record this
65
+ * one no longer accepts still names its owner.
66
+ * @param lockPath - File containing a candidate ownership record.
67
+ * @returns - The owner's positive process id, with the start time the lock recorded for it when it
68
+ * recorded one.
69
+ */
70
+ export declare function readBrokerOwner(lockPath: string): {
71
+ pid: number;
72
+ startedAt?: string;
73
+ } | undefined;
74
+ /**
75
+ * Resolve the service lock beside its durable database.
76
+ * @param databasePath - Durable SQLite file whose owning service publishes the lock.
77
+ * @returns - Path of the lock file beside the database.
78
+ */
79
+ export declare function brokerLockPath(databasePath: string): string;
80
+ /**
81
+ * Read a valid broker lock record without importing the SQLite-backed service.
82
+ * @param lockPath - File containing the candidate lock record.
83
+ * @returns - Valid parsed lock data when the file is well-formed.
84
+ */
85
+ export declare function readBrokerLock(lockPath: string): BrokerLock | undefined;
86
+ /** Bounds how many times acquisition re-attempts after losing a lock-file race. */
87
+ export declare const BROKER_LOCK_ACQUISITION_ATTEMPTS = 5;
88
+ /** Reports the start time of a process, or that this platform cannot supply one. */
89
+ export type ProcessStartTime = {
90
+ known: true;
91
+ value: string;
92
+ } | {
93
+ known: false;
94
+ };
95
+ /** Supplies the operating-system and timing boundaries the lock protocol reads. */
96
+ export type BrokerLockPorts = {
97
+ /** Reports whether a process id currently names a running process. */
98
+ processIsAlive(pid: number): boolean;
99
+ /** Reports when a running process started, in a form comparable only against itself. */
100
+ processStartedAt(pid: number): ProcessStartTime;
101
+ /** Issues an unguessable token identifying one acquisition of the lock. */
102
+ newHolderToken(): string;
103
+ /** Blocks the calling thread, because lock acquisition runs before the service has an event loop. */
104
+ sleep(milliseconds: number): void;
105
+ };
106
+ /** Reports that the lock is held by a live service of the current build. */
107
+ export declare class BrokerServiceAlreadyRunningError extends ProtocolError {
108
+ /** Identifies the live process that owns the lock. */
109
+ readonly pid: number;
110
+ /**
111
+ * Construct the failure naming the live owner a second service must defer to.
112
+ * @param pid - Process id recorded by the lock this process could not take.
113
+ */
114
+ constructor(
115
+ /** Identifies the live process that owns the lock. */
116
+ pid: number);
117
+ }
118
+ /** Reports that the lock is held by a live service this build must not displace. */
119
+ export declare class BrokerServiceLockOwnedError extends ProtocolError {
120
+ /** Identifies the live process that owns the lock. */
121
+ readonly pid: number;
122
+ /**
123
+ * Construct the failure naming the incompatible owner an operator must resolve.
124
+ * @param pid - Process id recorded by the lock this process could not take.
125
+ */
126
+ constructor(
127
+ /** Identifies the live process that owns the lock. */
128
+ pid: number);
129
+ }
130
+ /** Reports that acquisition kept losing the lock file to another writer. */
131
+ export declare class BrokerLockContendedError extends ProtocolError {
132
+ /** Names the contended lock file. */
133
+ readonly lockPath: string;
134
+ /** Records how many attempts were made before giving up. */
135
+ readonly attempts: number;
136
+ /** Names the file that blocked the final attempt. */
137
+ readonly blockedBy: string;
138
+ /**
139
+ * Construct the failure that ends a bounded acquisition rather than retrying forever.
140
+ * @param lockPath - Lock file this process was trying to take.
141
+ * @param attempts - Number of acquisition attempts that were made and lost.
142
+ * @param blockedBy - File that was still held or recreated on the final attempt, which is the one
143
+ * an operator has to deal with and is not always the lock itself.
144
+ */
145
+ constructor(
146
+ /** Names the contended lock file. */
147
+ lockPath: string,
148
+ /** Records how many attempts were made before giving up. */
149
+ attempts: number,
150
+ /** Names the file that blocked the final attempt. */
151
+ blockedBy: string);
152
+ }
153
+ /** Reports that the lock this process acquired is no longer the one on disk. */
154
+ export declare class BrokerLockLostError extends ProtocolError {
155
+ /** Names the lock file this process no longer holds. */
156
+ readonly lockPath: string;
157
+ /**
158
+ * Construct the failure that stops a service publishing endpoints it no longer owns.
159
+ * @param lockPath - Lock file whose holder token stopped matching this acquisition.
160
+ */
161
+ constructor(
162
+ /** Names the lock file this process no longer holds. */
163
+ lockPath: string);
164
+ }
165
+ /**
166
+ * Report whether a process id names a running process.
167
+ * @param pid - Process id to probe.
168
+ * @returns - True unless the operating system reports no such process.
169
+ */
170
+ export declare function processIsAlive(pid: number): boolean;
171
+ /**
172
+ * Read a process's start time from the platform, where the platform can report one.
173
+ *
174
+ * The value is tagged with the reading that produced it. A record carrying a tag this build does not
175
+ * produce describes a moment measured some other way, and comparing the two would be meaningless.
176
+ * @param pid - Process id to describe.
177
+ * @returns - The start time, or an explicit absence on a platform that cannot supply one.
178
+ */
179
+ export declare function processStartedAt(pid: number): ProcessStartTime;
180
+ /**
181
+ * Report whether a recorded start time still describes whichever process now holds a process id.
182
+ * @param recorded - Start time captured when the record was written.
183
+ * @param actual - Start time read from the platform now.
184
+ * @returns - False only when both readings are the same kind and disagree.
185
+ */
186
+ export declare function startTimeStillMatches(recorded: string, actual: ProcessStartTime): boolean;
187
+ /**
188
+ * Build the operating-system boundaries used by a production lock acquisition.
189
+ * @returns - Ports backed by the operating system's process table, a random token source, and a sleep that blocks the thread.
190
+ */
191
+ export declare function systemBrokerLockPorts(): BrokerLockPorts;
192
+ /**
193
+ * The exclusive claim a broker service holds on its database for the life of the process.
194
+ *
195
+ * Structural rather than the class itself: `BrokerLockGuard` has `#private` fields, so a consumer
196
+ * typed against the class could only ever be handed a real one.
197
+ */
198
+ export type BrokerLockOwner = {
199
+ /** Names the lock file this owner claims. */
200
+ readonly path: string;
201
+ /** Takes exclusive ownership of the database, reclaiming a lock whose owner is gone. */
202
+ acquire(): void;
203
+ /** Replaces the acquired lock with the record readers adopt. */
204
+ publish(lock: BrokerLock): void;
205
+ /** Gives up ownership, leaving any lock this owner does not hold untouched. */
206
+ release(): void;
207
+ };
208
+ /**
209
+ * Owns one process's exclusive claim on a broker database.
210
+ *
211
+ * Creation links a staged record into place and fails on a name another process holds, so
212
+ * uncontended acquisition already selects one winner. Reclaiming a stale lock cannot be, because it
213
+ * spans a read and an unlink: two processes that each read the same dead owner would each remove
214
+ * whatever lock was present by the time they got to the unlink, including the other's fresh one. A
215
+ * separate reclaim file, claimed the same way, serialises that span, and the owner is re-read inside
216
+ * it, so a reclaimer that lost the race sees the winner rather than deleting it.
217
+ */
218
+ export declare class BrokerLockGuard implements BrokerLockOwner {
219
+ #private;
220
+ /**
221
+ * Construct a guard over one lock file.
222
+ * @param lockPath - Lock file adjacent to the database this process wants to own.
223
+ * @param ports - Operating-system boundaries, replaced only by this module's own tests.
224
+ */
225
+ constructor(lockPath: string, ports?: BrokerLockPorts);
226
+ /**
227
+ * Names the lock file this guard claims.
228
+ * @returns - Path the guard was constructed over.
229
+ */
230
+ get path(): string;
231
+ /**
232
+ * Take exclusive ownership of the database, reclaiming a lock whose owner is gone.
233
+ *
234
+ * Terminates in every case: each attempt either wins the lock, throws because a live owner holds
235
+ * it, or consumes one of a fixed number of attempts.
236
+ * @throws {BrokerServiceAlreadyRunningError} - A live service of this build holds the lock.
237
+ * @throws {BrokerServiceLockOwnedError} - A live service this build must not displace holds the lock.
238
+ * @throws {BrokerLockContendedError} - Another writer kept recreating the lock.
239
+ */
240
+ acquire(): void;
241
+ /**
242
+ * Replace the acquired lock with the record readers adopt.
243
+ *
244
+ * Written to a scratch file and renamed, so no reader can observe a partial document and treat
245
+ * the database as unowned.
246
+ * @param lock - Ownership record naming this process's published endpoints.
247
+ * @throws {BrokerLockLostError} - The lock on disk is no longer the one this guard acquired.
248
+ */
249
+ publish(lock: BrokerLock): void;
250
+ /**
251
+ * Give up ownership, leaving any lock this guard does not hold untouched.
252
+ *
253
+ * A service that failed to acquire, or whose lock was reclaimed while it shut down, must not
254
+ * delete the record naming whichever process owns the database now.
255
+ */
256
+ release(): void;
257
+ }