pi-harness-runtime 1.1.336 → 1.1.338

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 (199) hide show
  1. package/index.ts +21 -12
  2. package/package.json +1 -1
  3. package/packages/a2a-adapter/package.json +1 -1
  4. package/packages/agent-policy/package.json +1 -1
  5. package/packages/architecture-generator/package.json +1 -1
  6. package/packages/auth/package.json +1 -1
  7. package/packages/autonomous-refactor/package.json +1 -1
  8. package/packages/autonomous-runtime/package.json +1 -1
  9. package/packages/cache-strategy/package.json +1 -1
  10. package/packages/capability-registry/package.json +1 -1
  11. package/packages/checkpoint/package.json +1 -1
  12. package/packages/cli-plugin-sdk/package.json +1 -1
  13. package/packages/clipboard/package.json +1 -1
  14. package/packages/clipboard-plugin/package.json +1 -1
  15. package/packages/code-generation/package.json +1 -1
  16. package/packages/code-review/package.json +1 -1
  17. package/packages/codex-adapter/package.json +1 -1
  18. package/packages/codex-watcher/package.json +1 -1
  19. package/packages/config-capture/package.json +1 -1
  20. package/packages/connection-runtime/dist/index.d.ts +11 -0
  21. package/packages/connection-runtime/dist/index.js +11 -0
  22. package/packages/connection-runtime/dist/registry.d.ts +69 -0
  23. package/packages/connection-runtime/dist/registry.js +117 -0
  24. package/packages/connection-runtime/dist/supervisor.d.ts +89 -0
  25. package/packages/connection-runtime/dist/supervisor.js +169 -0
  26. package/packages/connection-runtime/dist/types.d.ts +70 -0
  27. package/packages/connection-runtime/dist/types.js +16 -0
  28. package/packages/connection-runtime/package.json +24 -0
  29. package/packages/connection-runtime/src/index.ts +12 -0
  30. package/packages/connection-runtime/src/registry.ts +142 -0
  31. package/packages/connection-runtime/src/supervisor.ts +224 -0
  32. package/packages/connection-runtime/src/types.ts +88 -0
  33. package/packages/context-compiler/package.json +1 -1
  34. package/packages/context-discovery/package.json +1 -1
  35. package/packages/context-manager/package.json +1 -1
  36. package/packages/contracts/dist/approvals.d.ts +273 -0
  37. package/packages/contracts/dist/approvals.js +93 -0
  38. package/packages/contracts/dist/base.d.ts +78 -0
  39. package/packages/contracts/dist/base.js +82 -0
  40. package/packages/contracts/dist/events.d.ts +99 -0
  41. package/packages/contracts/dist/events.js +65 -0
  42. package/packages/contracts/dist/index.d.ts +20 -0
  43. package/packages/contracts/dist/index.js +20 -0
  44. package/packages/contracts/dist/jobs.d.ts +234 -0
  45. package/packages/contracts/dist/jobs.js +79 -0
  46. package/packages/contracts/dist/notifications.d.ts +317 -0
  47. package/packages/contracts/dist/notifications.js +85 -0
  48. package/packages/contracts/dist/projects.d.ts +171 -0
  49. package/packages/contracts/dist/projects.js +62 -0
  50. package/packages/contracts/dist/sessions.d.ts +226 -0
  51. package/packages/contracts/dist/sessions.js +82 -0
  52. package/packages/contracts/package.json +24 -0
  53. package/packages/contracts/src/approvals.ts +115 -0
  54. package/packages/contracts/src/base.ts +126 -0
  55. package/packages/contracts/src/events.ts +78 -0
  56. package/packages/contracts/src/index.ts +21 -0
  57. package/packages/contracts/src/jobs.ts +101 -0
  58. package/packages/contracts/src/notifications.ts +104 -0
  59. package/packages/contracts/src/projects.ts +81 -0
  60. package/packages/contracts/src/sessions.ts +104 -0
  61. package/packages/cookie-sanitizer/package.json +1 -1
  62. package/packages/cost-optimizer/package.json +1 -1
  63. package/packages/dependency-analyzer/package.json +1 -1
  64. package/packages/django-plugin/package.json +1 -1
  65. package/packages/doc-generator/package.json +1 -1
  66. package/packages/durable-review/package.json +1 -1
  67. package/packages/e2e-tester/package.json +1 -1
  68. package/packages/evaluation-engine/package.json +1 -1
  69. package/packages/evaluation-runner/package.json +1 -1
  70. package/packages/event-bus/package.json +1 -1
  71. package/packages/event-sink/dist/index.d.ts +12 -0
  72. package/packages/event-sink/dist/index.js +12 -0
  73. package/packages/event-sink/dist/outbox.d.ts +51 -0
  74. package/packages/event-sink/dist/outbox.js +88 -0
  75. package/packages/event-sink/dist/projection.d.ts +41 -0
  76. package/packages/event-sink/dist/projection.js +62 -0
  77. package/packages/event-sink/dist/sink.d.ts +81 -0
  78. package/packages/event-sink/dist/sink.js +106 -0
  79. package/packages/event-sink/package.json +28 -0
  80. package/packages/event-sink/src/index.ts +15 -0
  81. package/packages/event-sink/src/outbox.ts +119 -0
  82. package/packages/event-sink/src/projection.ts +84 -0
  83. package/packages/event-sink/src/sink.ts +167 -0
  84. package/packages/event-store/package.json +1 -1
  85. package/packages/experience-replay/package.json +1 -1
  86. package/packages/feedback-collector/package.json +1 -1
  87. package/packages/file-copy-helper/package.json +1 -1
  88. package/packages/framework-detector/package.json +1 -1
  89. package/packages/framework-plugin-sdk/package.json +1 -1
  90. package/packages/frappe-plugin/package.json +1 -1
  91. package/packages/generic-web-plugin/package.json +1 -1
  92. package/packages/health-monitor/package.json +1 -1
  93. package/packages/intent-analyzer/package.json +1 -1
  94. package/packages/jev-judge/package.json +1 -1
  95. package/packages/knowledge-graph/package.json +1 -1
  96. package/packages/knowledge-retrieval/package.json +1 -1
  97. package/packages/laravel-plugin/package.json +1 -1
  98. package/packages/learning-engine/package.json +1 -1
  99. package/packages/mcp-adapter/package.json +1 -1
  100. package/packages/memory-engine/package.json +1 -1
  101. package/packages/milestone-manager/package.json +1 -1
  102. package/packages/model-registry/package.json +1 -1
  103. package/packages/nextjs-plugin/package.json +1 -1
  104. package/packages/notification/package.json +1 -1
  105. package/packages/observability/package.json +1 -1
  106. package/packages/okf-indexer/package.json +1 -1
  107. package/packages/paperclip-integration/package.json +1 -1
  108. package/packages/performance-optimizer/package.json +1 -1
  109. package/packages/permission-mode/dist/checker.d.ts +66 -0
  110. package/packages/permission-mode/dist/checker.js +64 -0
  111. package/packages/permission-mode/dist/index.d.ts +12 -0
  112. package/packages/permission-mode/dist/index.js +11 -0
  113. package/packages/permission-mode/dist/manager.d.ts +65 -0
  114. package/packages/permission-mode/dist/manager.js +91 -0
  115. package/packages/permission-mode/dist/mode.d.ts +31 -0
  116. package/packages/permission-mode/dist/mode.js +47 -0
  117. package/packages/permission-mode/package.json +24 -0
  118. package/packages/permission-mode/src/checker.ts +103 -0
  119. package/packages/permission-mode/src/index.ts +13 -0
  120. package/packages/permission-mode/src/manager.ts +154 -0
  121. package/packages/permission-mode/src/mode.ts +73 -0
  122. package/packages/privilege-broker/package.json +1 -1
  123. package/packages/project-analyzer/package.json +1 -1
  124. package/packages/project-bootstrap/package.json +1 -1
  125. package/packages/projection-engine/package.json +1 -1
  126. package/packages/prompt-compiler/package.json +1 -1
  127. package/packages/prompt-versioning/package.json +1 -1
  128. package/packages/provider-adapter-sdk/package.json +1 -1
  129. package/packages/provider-router/package.json +1 -1
  130. package/packages/provider-selector/package.json +1 -1
  131. package/packages/providers/package.json +1 -1
  132. package/packages/qdrant-skills/package.json +1 -1
  133. package/packages/quota-manager/package.json +1 -1
  134. package/packages/rate-limiter/package.json +1 -1
  135. package/packages/react-vite-plugin/package.json +1 -1
  136. package/packages/relay/dist/client.d.ts +53 -0
  137. package/packages/relay/dist/client.js +95 -0
  138. package/packages/relay/dist/index.d.ts +9 -0
  139. package/packages/relay/dist/index.js +8 -0
  140. package/packages/relay/dist/server.d.ts +58 -0
  141. package/packages/relay/dist/server.js +93 -0
  142. package/packages/relay/dist/types.d.ts +35 -0
  143. package/packages/relay/dist/types.js +4 -0
  144. package/packages/relay/package.json +24 -0
  145. package/packages/relay/src/client.ts +119 -0
  146. package/packages/relay/src/index.ts +10 -0
  147. package/packages/relay/src/server.ts +120 -0
  148. package/packages/relay/src/types.ts +38 -0
  149. package/packages/release-manager/package.json +1 -1
  150. package/packages/requirement-compiler/package.json +1 -1
  151. package/packages/runtime/package.json +1 -1
  152. package/packages/scheduler/package.json +1 -1
  153. package/packages/scheduler-adapter/package.json +1 -1
  154. package/packages/session/package.json +1 -1
  155. package/packages/session-api/package.json +1 -1
  156. package/packages/session-export/package.json +1 -1
  157. package/packages/shared-context/package.json +1 -1
  158. package/packages/skill-mcp-client/package.json +1 -1
  159. package/packages/skill-registry/package.json +1 -1
  160. package/packages/skills/package.json +1 -1
  161. package/packages/sprint-planner/package.json +1 -1
  162. package/packages/subscription-engine/package.json +1 -1
  163. package/packages/task-compiler/package.json +1 -1
  164. package/packages/telegram/package.json +1 -1
  165. package/packages/tencentdb-memory/package.json +1 -1
  166. package/packages/tencentdb-sync/package.json +1 -1
  167. package/packages/test-data-generator/package.json +1 -1
  168. package/packages/test-generator/package.json +1 -1
  169. package/packages/todo-bd-sync/package.json +1 -1
  170. package/packages/token-estimation/package.json +1 -1
  171. package/packages/token-optimizer/package.json +1 -1
  172. package/packages/trajectory/package.json +1 -1
  173. package/packages/tui/package.json +1 -1
  174. package/packages/types/package.json +1 -1
  175. package/packages/voice-api/dist/index.d.ts +14 -0
  176. package/packages/voice-api/dist/index.js +12 -0
  177. package/packages/voice-api/dist/line.d.ts +100 -0
  178. package/packages/voice-api/dist/line.js +147 -0
  179. package/packages/voice-api/dist/provider.d.ts +23 -0
  180. package/packages/voice-api/dist/provider.js +154 -0
  181. package/packages/voice-api/dist/telegram.d.ts +74 -0
  182. package/packages/voice-api/dist/telegram.js +119 -0
  183. package/packages/voice-api/dist/transcriber.d.ts +48 -0
  184. package/packages/voice-api/dist/transcriber.js +118 -0
  185. package/packages/voice-api/dist/types.d.ts +75 -0
  186. package/packages/voice-api/dist/types.js +4 -0
  187. package/packages/voice-api/package.json +24 -0
  188. package/packages/voice-api/src/index.ts +15 -0
  189. package/packages/voice-api/src/line.ts +229 -0
  190. package/packages/voice-api/src/provider.ts +186 -0
  191. package/packages/voice-api/src/telegram.ts +191 -0
  192. package/packages/voice-api/src/transcriber.ts +136 -0
  193. package/packages/voice-api/src/types.ts +79 -0
  194. package/packages/webmcp-tester/package.json +1 -1
  195. package/packages/wiki/package.json +1 -1
  196. package/packages/workflow-events/package.json +1 -1
  197. package/packages/workspace-scanner/package.json +1 -1
  198. package/packages/worktree/package.json +1 -1
  199. package/packages/write-review/package.json +1 -1
package/index.ts CHANGED
@@ -2054,8 +2054,20 @@ let _nc: {
2054
2054
  ctx: Record<string, unknown>,
2055
2055
  options?: { approveLabel?: string; rejectLabel?: string },
2056
2056
  ) => Promise<unknown>;
2057
+ notifyWithButtons?: (
2058
+ event: string,
2059
+ ctx: Record<string, unknown>,
2060
+ buttons: Array<{ text: string; action: string; targetId: string; url?: string }>,
2061
+ ) => Promise<unknown>;
2057
2062
  } | null = null;
2058
2063
 
2064
+ // Type for _nc.center
2065
+ type NcCenter = {
2066
+ notifyWithApproval: Function;
2067
+ notify: Function;
2068
+ notifyWithButtons?: Function;
2069
+ };
2070
+
2059
2071
  /**
2060
2072
  * Fire a Telegram notification event. Logs delivery outcomes.
2061
2073
  * Silently skips if Telegram is not configured.
@@ -2063,12 +2075,7 @@ let _nc: {
2063
2075
  async function nc(event: string, ctx: Record<string, unknown>): Promise<void> {
2064
2076
  if (!_nc) return;
2065
2077
  try {
2066
- const nc = _nc as {
2067
- center: {
2068
- notifyWithApproval: Function;
2069
- notify: Function;
2070
- };
2071
- };
2078
+ const center = _nc!.center as NcCenter;
2072
2079
 
2073
2080
  // Import policy engine dynamically to check if approval buttons needed
2074
2081
  // This is a simple sync check - can be replaced with Jev-powered evaluation
@@ -2077,9 +2084,9 @@ async function nc(event: string, ctx: Record<string, unknown>): Promise<void> {
2077
2084
  // Capture results for logging
2078
2085
  let results: unknown;
2079
2086
  if (requiresApproval(event)) {
2080
- results = await nc.center.notifyWithApproval(event as never, ctx as never);
2087
+ results = await center.notifyWithApproval(event as never, ctx as never);
2081
2088
  } else {
2082
- results = await nc.center.notify(event as never, ctx as never);
2089
+ results = await center.notify(event as never, ctx as never);
2083
2090
  }
2084
2091
 
2085
2092
  // Log delivery outcomes to file
@@ -2730,10 +2737,11 @@ export default async function (pi: ExtensionAPI) {
2730
2737
  const doneToken = _createPendingAction(sessionId, "done", projectRoot, "plan");
2731
2738
 
2732
2739
  // Use event type based on stage
2733
- if (hasReviewMarker) {
2740
+ if (hasReviewMarker) {
2734
2741
  // Review stage: buttons are Code again and Done
2735
2742
  const codeAgainToken = _createPendingAction(sessionId, "code_again", projectRoot, "review");
2736
- void nc.center.notifyWithButtons("CodexReviewDetected", {
2743
+ // SAFETY: _nc.center is always an object with notifyWithButtons in our usage
2744
+ void (_nc as unknown as { center: { notifyWithButtons: Function } }).center.notifyWithButtons("CodexReviewDetected", {
2737
2745
  requirement: msg.text,
2738
2746
  taskTitle: sessionId,
2739
2747
  details: {
@@ -2746,9 +2754,10 @@ export default async function (pi: ExtensionAPI) {
2746
2754
  { text: "Code again", action: PING_PONG_ACTIONS.CODE_AGAIN, targetId: codeAgainToken },
2747
2755
  { text: "Done", action: PING_PONG_ACTIONS.DONE, targetId: doneToken },
2748
2756
  ]);
2749
- } else {
2757
+ } else {
2750
2758
  // Plan stage: buttons are Code and Done
2751
- void nc.center.notifyWithButtons("CodexPlanDetected", {
2759
+ // SAFETY: _nc.center is always an object with notifyWithButtons in our usage
2760
+ void (_nc as unknown as { center: { notifyWithButtons: Function } }).center.notifyWithButtons("CodexPlanDetected", {
2752
2761
  requirement: msg.text, // Full text, no truncation
2753
2762
  taskTitle: sessionId,
2754
2763
  details: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-harness-runtime",
3
- "version": "1.1.336",
3
+ "version": "1.1.338",
4
4
  "description": "[BETA] Codex-style /usage status + autonomous coding harness for pi. Not production ready — expect breaking changes.",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi/a2a-adapter",
3
- "version": "1.1.336",
3
+ "version": "1.1.338",
4
4
  "type": "module",
5
5
  "description": "Google Agent-to-Agent (A2A) protocol adapter for pi-harness",
6
6
  "main": "dist/index.js",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi/agent-policy",
3
- "version": "1.1.336",
3
+ "version": "1.1.338",
4
4
  "description": "Agent policy runtime for pi-harness - enforces mandatory rule delivery and mutation gating",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-harness/architecture-generator",
3
- "version": "1.1.336",
3
+ "version": "1.1.338",
4
4
  "description": "Generate ADR and Mermaid diagrams from project analysis",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-harness/auth",
3
- "version": "1.1.336",
3
+ "version": "1.1.338",
4
4
  "description": "pi-harness-runtime — auth",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi/autonomous-refactor",
3
- "version": "1.1.336",
3
+ "version": "1.1.338",
4
4
  "type": "module",
5
5
  "description": "Autonomous refactoring engine",
6
6
  "main": "dist/index.js",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi/autonomous-runtime",
3
- "version": "1.1.336",
3
+ "version": "1.1.338",
4
4
  "description": "Autonomous Operations Runtime — task inbox, lease management, and worker lifecycle (RFC-0101)",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi/cache-strategy",
3
- "version": "1.1.336",
3
+ "version": "1.1.338",
4
4
  "type": "module",
5
5
  "description": "Smart caching with TTL and invalidation strategies (RFC-0022)",
6
6
  "main": "dist/index.js",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-harness/capability-registry",
3
- "version": "1.1.336",
3
+ "version": "1.1.338",
4
4
  "description": "Capability Registry for pi-harness-runtime — tracks model capabilities and enables capability-based routing",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi/checkpoint",
3
- "version": "1.1.336",
3
+ "version": "1.1.338",
4
4
  "description": "Enhanced checkpoint system with incremental snapshots, diff-based storage, and recovery strategies",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi/cli-plugin-sdk",
3
- "version": "1.1.336",
3
+ "version": "1.1.338",
4
4
  "type": "module",
5
5
  "description": "CLI Plugin SDK for pi-harness — install, list, remove, update, invoke plugins",
6
6
  "main": "dist/index.js",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi/clipboard",
3
- "version": "1.1.336",
3
+ "version": "1.1.338",
4
4
  "type": "module",
5
5
  "main": "src/index.ts",
6
6
  "exports": {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi/clipboard-plugin",
3
- "version": "1.1.336",
3
+ "version": "1.1.338",
4
4
  "type": "module",
5
5
  "main": "src/index.ts",
6
6
  "exports": {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi/code-generation",
3
- "version": "1.1.336",
3
+ "version": "1.1.338",
4
4
  "description": "Code generation pipeline for pi-harness-runtime",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi/code-review",
3
- "version": "1.1.336",
3
+ "version": "1.1.338",
4
4
  "description": "Automated code review engine for pi-harness-runtime",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi/codex-adapter",
3
- "version": "1.1.336",
3
+ "version": "1.1.338",
4
4
  "type": "module",
5
5
  "description": "OpenAI Codex provider adapter for pi-harness",
6
6
  "main": "dist/index.js",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-harness/codex-watcher",
3
- "version": "1.1.336",
3
+ "version": "1.1.338",
4
4
  "description": "Watches Codex CLI sessions and emits visible messages for PING-PONG monitoring",
5
5
  "type": "module",
6
6
  "main": "./dist/src/index.js",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moocoding/config-capture",
3
- "version": "1.1.336",
3
+ "version": "1.1.338",
4
4
  "description": "Auto-capture API-fetched configuration values to AGENTS.md",
5
5
  "type": "module",
6
6
  "main": "src/index.ts",
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Connection Runtime for pi-harness
3
+ *
4
+ * Inspired by T3Code's client-runtime:
5
+ * - Jittered exponential backoff for reconnection
6
+ * - One transport retry owner per environment
7
+ * - Shared subscription logic across clients
8
+ */
9
+ export * from './supervisor.js';
10
+ export * from './registry.js';
11
+ export * from './types.js';
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Connection Runtime for pi-harness
3
+ *
4
+ * Inspired by T3Code's client-runtime:
5
+ * - Jittered exponential backoff for reconnection
6
+ * - One transport retry owner per environment
7
+ * - Shared subscription logic across clients
8
+ */
9
+ export * from './supervisor.js';
10
+ export * from './registry.js';
11
+ export * from './types.js';
@@ -0,0 +1,69 @@
1
+ /**
2
+ * Connection Registry
3
+ *
4
+ * Scopes connections by environment/context.
5
+ * Tracks active connections and their state.
6
+ */
7
+ import { ConnectionSupervisor } from './supervisor.js';
8
+ export interface RegistryEntry {
9
+ id: string;
10
+ supervisor: ConnectionSupervisor;
11
+ metadata?: Record<string, unknown>;
12
+ createdAt: Date;
13
+ lastConnectedAt?: Date;
14
+ }
15
+ /**
16
+ * Connection Registry
17
+ *
18
+ * Manages multiple connections by ID.
19
+ * Connections persist even after disconnect (for reconnection).
20
+ */
21
+ export declare class ConnectionRegistry {
22
+ private connections;
23
+ private onChange?;
24
+ constructor(onChange?: (entries: RegistryEntry[]) => void);
25
+ /**
26
+ * Register a new connection
27
+ */
28
+ register(id: string, supervisor: ConnectionSupervisor, metadata?: Record<string, unknown>): RegistryEntry;
29
+ /**
30
+ * Unregister a connection
31
+ */
32
+ unregister(id: string): boolean;
33
+ /**
34
+ * Get a connection by ID
35
+ */
36
+ get(id: string): RegistryEntry | undefined;
37
+ /**
38
+ * Get all connections
39
+ */
40
+ list(): RegistryEntry[];
41
+ /**
42
+ * Get connections by state
43
+ */
44
+ listByState(state: string): RegistryEntry[];
45
+ /**
46
+ * Update connection metadata
47
+ */
48
+ updateMetadata(id: string, metadata: Record<string, unknown>): boolean;
49
+ /**
50
+ * Update last connected timestamp
51
+ */
52
+ touch(id: string): boolean;
53
+ /**
54
+ * Clear all connections
55
+ */
56
+ clear(): Promise<void>;
57
+ /**
58
+ * Get count of connections
59
+ */
60
+ size(): number;
61
+ /**
62
+ * Check if connection exists
63
+ */
64
+ has(id: string): boolean;
65
+ /**
66
+ * Notify change listeners
67
+ */
68
+ private notifyChange;
69
+ }
@@ -0,0 +1,117 @@
1
+ /**
2
+ * Connection Registry
3
+ *
4
+ * Scopes connections by environment/context.
5
+ * Tracks active connections and their state.
6
+ */
7
+ /**
8
+ * Connection Registry
9
+ *
10
+ * Manages multiple connections by ID.
11
+ * Connections persist even after disconnect (for reconnection).
12
+ */
13
+ export class ConnectionRegistry {
14
+ connections = new Map();
15
+ onChange;
16
+ constructor(onChange) {
17
+ this.onChange = onChange;
18
+ }
19
+ /**
20
+ * Register a new connection
21
+ */
22
+ register(id, supervisor, metadata) {
23
+ const entry = {
24
+ id,
25
+ supervisor,
26
+ metadata,
27
+ createdAt: new Date(),
28
+ };
29
+ this.connections.set(id, entry);
30
+ this.notifyChange();
31
+ return entry;
32
+ }
33
+ /**
34
+ * Unregister a connection
35
+ */
36
+ unregister(id) {
37
+ const entry = this.connections.get(id);
38
+ if (entry) {
39
+ entry.supervisor.disconnect().catch(() => { });
40
+ this.connections.delete(id);
41
+ this.notifyChange();
42
+ return true;
43
+ }
44
+ return false;
45
+ }
46
+ /**
47
+ * Get a connection by ID
48
+ */
49
+ get(id) {
50
+ return this.connections.get(id);
51
+ }
52
+ /**
53
+ * Get all connections
54
+ */
55
+ list() {
56
+ return Array.from(this.connections.values());
57
+ }
58
+ /**
59
+ * Get connections by state
60
+ */
61
+ listByState(state) {
62
+ return this.list().filter(e => e.supervisor.getState() === state);
63
+ }
64
+ /**
65
+ * Update connection metadata
66
+ */
67
+ updateMetadata(id, metadata) {
68
+ const entry = this.connections.get(id);
69
+ if (entry) {
70
+ entry.metadata = { ...entry.metadata, ...metadata };
71
+ this.notifyChange();
72
+ return true;
73
+ }
74
+ return false;
75
+ }
76
+ /**
77
+ * Update last connected timestamp
78
+ */
79
+ touch(id) {
80
+ const entry = this.connections.get(id);
81
+ if (entry) {
82
+ entry.lastConnectedAt = new Date();
83
+ this.notifyChange();
84
+ return true;
85
+ }
86
+ return false;
87
+ }
88
+ /**
89
+ * Clear all connections
90
+ */
91
+ async clear() {
92
+ const promises = this.list().map(e => e.supervisor.disconnect());
93
+ await Promise.allSettled(promises);
94
+ this.connections.clear();
95
+ this.notifyChange();
96
+ }
97
+ /**
98
+ * Get count of connections
99
+ */
100
+ size() {
101
+ return this.connections.size;
102
+ }
103
+ /**
104
+ * Check if connection exists
105
+ */
106
+ has(id) {
107
+ return this.connections.has(id);
108
+ }
109
+ /**
110
+ * Notify change listeners
111
+ */
112
+ notifyChange() {
113
+ if (this.onChange) {
114
+ this.onChange(this.list());
115
+ }
116
+ }
117
+ }
@@ -0,0 +1,89 @@
1
+ /**
2
+ * Connection Supervisor
3
+ *
4
+ * Inspired by T3Code's connection supervisor:
5
+ * - Jittered exponential backoff for reconnection
6
+ * - Resets delay after successful connection
7
+ * - Cap at maxDelay to prevent thundering herd
8
+ */
9
+ import type { EventEmitter } from './types.js';
10
+ /**
11
+ * Connection Supervisor options
12
+ */
13
+ export interface SupervisorOptions {
14
+ /** Transport to manage */
15
+ transport: EventEmitter & {
16
+ open(): Promise<void>;
17
+ close(): Promise<void>;
18
+ isConnected(): boolean;
19
+ };
20
+ /** Initial retry delay in ms */
21
+ initialDelay?: number;
22
+ /** Maximum retry delay in ms */
23
+ maxDelay?: number;
24
+ /** Maximum retries (0 = infinite) */
25
+ maxRetries?: number;
26
+ /** Enable jitter */
27
+ jitter?: boolean;
28
+ /** Callback when connected */
29
+ onConnected?: () => void;
30
+ /** Callback when disconnected */
31
+ onDisconnected?: () => void;
32
+ /** Callback on error */
33
+ onError?: (error: Error) => void;
34
+ /** Callback on retry attempt */
35
+ onRetry?: (attempt: number, delay: number) => void;
36
+ }
37
+ /**
38
+ * Connection Supervisor
39
+ *
40
+ * Manages transport connection with automatic reconnection using
41
+ * jittered exponential backoff.
42
+ */
43
+ export declare class ConnectionSupervisor {
44
+ private transport;
45
+ private delay;
46
+ private maxDelay;
47
+ private maxRetries;
48
+ private jitter;
49
+ private retries;
50
+ private state;
51
+ private stopping;
52
+ private onConnected?;
53
+ private onDisconnected?;
54
+ private onError?;
55
+ private onRetry?;
56
+ constructor(options: SupervisorOptions);
57
+ /**
58
+ * Current connection state
59
+ */
60
+ getState(): "connected" | "connecting" | "error" | "idle" | "reconnecting" | "stopped";
61
+ /**
62
+ * Number of retries attempted
63
+ */
64
+ getRetries(): number;
65
+ /**
66
+ * Start the connection
67
+ */
68
+ connect(): Promise<void>;
69
+ /**
70
+ * Stop the connection
71
+ */
72
+ disconnect(): Promise<void>;
73
+ /**
74
+ * Force reconnection
75
+ */
76
+ reconnect(): Promise<void>;
77
+ /**
78
+ * Handle connection error with backoff
79
+ */
80
+ private handleConnectionError;
81
+ /**
82
+ * Attempt connection with backoff
83
+ */
84
+ private attemptConnection;
85
+ /**
86
+ * Get initial delay (allows override)
87
+ */
88
+ protected getInitialDelay(): number;
89
+ }