agent-relay 2.0.23 → 2.0.25

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 (168) hide show
  1. package/dist/src/cli/index.js +160 -17
  2. package/package.json +18 -52
  3. package/packages/api-types/package.json +1 -1
  4. package/packages/bridge/package.json +8 -8
  5. package/packages/cli-tester/package.json +1 -1
  6. package/packages/config/package.json +2 -2
  7. package/packages/continuity/package.json +1 -1
  8. package/packages/daemon/package.json +12 -12
  9. package/packages/hooks/package.json +4 -4
  10. package/packages/mcp/package.json +2 -2
  11. package/packages/memory/package.json +2 -2
  12. package/packages/policy/package.json +2 -2
  13. package/packages/protocol/package.json +1 -1
  14. package/packages/resiliency/package.json +1 -1
  15. package/packages/sdk/package.json +2 -2
  16. package/packages/spawner/package.json +1 -1
  17. package/packages/state/package.json +1 -1
  18. package/packages/storage/package.json +2 -2
  19. package/packages/telemetry/package.json +1 -1
  20. package/packages/trajectory/package.json +2 -2
  21. package/packages/user-directory/package.json +2 -2
  22. package/packages/utils/package.json +1 -1
  23. package/packages/wrapper/package.json +6 -6
  24. package/deploy/init-db.sql +0 -5
  25. package/deploy/scripts/setup-fly-workspaces.sh +0 -69
  26. package/deploy/scripts/setup-railway.sh +0 -75
  27. package/dist/src/cloud/index.d.ts +0 -8
  28. package/dist/src/cloud/index.js +0 -8
  29. package/packages/cloud/dist/api/admin.d.ts +0 -8
  30. package/packages/cloud/dist/api/admin.js +0 -225
  31. package/packages/cloud/dist/api/auth.d.ts +0 -20
  32. package/packages/cloud/dist/api/auth.js +0 -138
  33. package/packages/cloud/dist/api/billing.d.ts +0 -7
  34. package/packages/cloud/dist/api/billing.js +0 -564
  35. package/packages/cloud/dist/api/cli-pty-runner.d.ts +0 -53
  36. package/packages/cloud/dist/api/cli-pty-runner.js +0 -175
  37. package/packages/cloud/dist/api/codex-auth-helper.d.ts +0 -21
  38. package/packages/cloud/dist/api/codex-auth-helper.js +0 -327
  39. package/packages/cloud/dist/api/consensus.d.ts +0 -13
  40. package/packages/cloud/dist/api/consensus.js +0 -261
  41. package/packages/cloud/dist/api/coordinators.d.ts +0 -8
  42. package/packages/cloud/dist/api/coordinators.js +0 -750
  43. package/packages/cloud/dist/api/daemons.d.ts +0 -12
  44. package/packages/cloud/dist/api/daemons.js +0 -535
  45. package/packages/cloud/dist/api/email-auth.d.ts +0 -11
  46. package/packages/cloud/dist/api/email-auth.js +0 -347
  47. package/packages/cloud/dist/api/generic-webhooks.d.ts +0 -8
  48. package/packages/cloud/dist/api/generic-webhooks.js +0 -129
  49. package/packages/cloud/dist/api/git.d.ts +0 -8
  50. package/packages/cloud/dist/api/git.js +0 -269
  51. package/packages/cloud/dist/api/github-app.d.ts +0 -11
  52. package/packages/cloud/dist/api/github-app.js +0 -223
  53. package/packages/cloud/dist/api/middleware/planLimits.d.ts +0 -43
  54. package/packages/cloud/dist/api/middleware/planLimits.js +0 -202
  55. package/packages/cloud/dist/api/monitoring.d.ts +0 -11
  56. package/packages/cloud/dist/api/monitoring.js +0 -578
  57. package/packages/cloud/dist/api/nango-auth.d.ts +0 -9
  58. package/packages/cloud/dist/api/nango-auth.js +0 -741
  59. package/packages/cloud/dist/api/onboarding.d.ts +0 -15
  60. package/packages/cloud/dist/api/onboarding.js +0 -679
  61. package/packages/cloud/dist/api/policy.d.ts +0 -8
  62. package/packages/cloud/dist/api/policy.js +0 -229
  63. package/packages/cloud/dist/api/provider-env.d.ts +0 -26
  64. package/packages/cloud/dist/api/provider-env.js +0 -141
  65. package/packages/cloud/dist/api/providers.d.ts +0 -7
  66. package/packages/cloud/dist/api/providers.js +0 -574
  67. package/packages/cloud/dist/api/repos.d.ts +0 -8
  68. package/packages/cloud/dist/api/repos.js +0 -577
  69. package/packages/cloud/dist/api/sessions.d.ts +0 -11
  70. package/packages/cloud/dist/api/sessions.js +0 -302
  71. package/packages/cloud/dist/api/teams.d.ts +0 -7
  72. package/packages/cloud/dist/api/teams.js +0 -281
  73. package/packages/cloud/dist/api/test-helpers.d.ts +0 -10
  74. package/packages/cloud/dist/api/test-helpers.js +0 -745
  75. package/packages/cloud/dist/api/usage.d.ts +0 -7
  76. package/packages/cloud/dist/api/usage.js +0 -111
  77. package/packages/cloud/dist/api/webhooks.d.ts +0 -8
  78. package/packages/cloud/dist/api/webhooks.js +0 -645
  79. package/packages/cloud/dist/api/workspaces.d.ts +0 -25
  80. package/packages/cloud/dist/api/workspaces.js +0 -1799
  81. package/packages/cloud/dist/billing/index.d.ts +0 -9
  82. package/packages/cloud/dist/billing/index.js +0 -9
  83. package/packages/cloud/dist/billing/plans.d.ts +0 -39
  84. package/packages/cloud/dist/billing/plans.js +0 -245
  85. package/packages/cloud/dist/billing/service.d.ts +0 -80
  86. package/packages/cloud/dist/billing/service.js +0 -388
  87. package/packages/cloud/dist/billing/types.d.ts +0 -141
  88. package/packages/cloud/dist/billing/types.js +0 -7
  89. package/packages/cloud/dist/config.d.ts +0 -5
  90. package/packages/cloud/dist/config.js +0 -5
  91. package/packages/cloud/dist/db/bulk-ingest.d.ts +0 -89
  92. package/packages/cloud/dist/db/bulk-ingest.js +0 -268
  93. package/packages/cloud/dist/db/drizzle.d.ts +0 -290
  94. package/packages/cloud/dist/db/drizzle.js +0 -1422
  95. package/packages/cloud/dist/db/index.d.ts +0 -56
  96. package/packages/cloud/dist/db/index.js +0 -70
  97. package/packages/cloud/dist/db/schema.d.ts +0 -5117
  98. package/packages/cloud/dist/db/schema.js +0 -656
  99. package/packages/cloud/dist/index.d.ts +0 -11
  100. package/packages/cloud/dist/index.js +0 -38
  101. package/packages/cloud/dist/provisioner/index.d.ts +0 -207
  102. package/packages/cloud/dist/provisioner/index.js +0 -2118
  103. package/packages/cloud/dist/server.d.ts +0 -17
  104. package/packages/cloud/dist/server.js +0 -2055
  105. package/packages/cloud/dist/services/auto-scaler.d.ts +0 -152
  106. package/packages/cloud/dist/services/auto-scaler.js +0 -439
  107. package/packages/cloud/dist/services/capacity-manager.d.ts +0 -148
  108. package/packages/cloud/dist/services/capacity-manager.js +0 -449
  109. package/packages/cloud/dist/services/ci-agent-spawner.d.ts +0 -49
  110. package/packages/cloud/dist/services/ci-agent-spawner.js +0 -373
  111. package/packages/cloud/dist/services/cloud-message-bus.d.ts +0 -28
  112. package/packages/cloud/dist/services/cloud-message-bus.js +0 -19
  113. package/packages/cloud/dist/services/compute-enforcement.d.ts +0 -57
  114. package/packages/cloud/dist/services/compute-enforcement.js +0 -175
  115. package/packages/cloud/dist/services/coordinator.d.ts +0 -62
  116. package/packages/cloud/dist/services/coordinator.js +0 -389
  117. package/packages/cloud/dist/services/index.d.ts +0 -17
  118. package/packages/cloud/dist/services/index.js +0 -25
  119. package/packages/cloud/dist/services/intro-expiration.d.ts +0 -60
  120. package/packages/cloud/dist/services/intro-expiration.js +0 -252
  121. package/packages/cloud/dist/services/mention-handler.d.ts +0 -65
  122. package/packages/cloud/dist/services/mention-handler.js +0 -405
  123. package/packages/cloud/dist/services/nango.d.ts +0 -219
  124. package/packages/cloud/dist/services/nango.js +0 -424
  125. package/packages/cloud/dist/services/persistence.d.ts +0 -131
  126. package/packages/cloud/dist/services/persistence.js +0 -200
  127. package/packages/cloud/dist/services/planLimits.d.ts +0 -147
  128. package/packages/cloud/dist/services/planLimits.js +0 -335
  129. package/packages/cloud/dist/services/presence-registry.d.ts +0 -56
  130. package/packages/cloud/dist/services/presence-registry.js +0 -91
  131. package/packages/cloud/dist/services/scaling-orchestrator.d.ts +0 -159
  132. package/packages/cloud/dist/services/scaling-orchestrator.js +0 -502
  133. package/packages/cloud/dist/services/scaling-policy.d.ts +0 -121
  134. package/packages/cloud/dist/services/scaling-policy.js +0 -415
  135. package/packages/cloud/dist/services/ssh-security.d.ts +0 -31
  136. package/packages/cloud/dist/services/ssh-security.js +0 -63
  137. package/packages/cloud/dist/services/workspace-keepalive.d.ts +0 -76
  138. package/packages/cloud/dist/services/workspace-keepalive.js +0 -234
  139. package/packages/cloud/dist/shims/consensus.d.ts +0 -23
  140. package/packages/cloud/dist/shims/consensus.js +0 -5
  141. package/packages/cloud/dist/webhooks/index.d.ts +0 -24
  142. package/packages/cloud/dist/webhooks/index.js +0 -29
  143. package/packages/cloud/dist/webhooks/parsers/github.d.ts +0 -8
  144. package/packages/cloud/dist/webhooks/parsers/github.js +0 -234
  145. package/packages/cloud/dist/webhooks/parsers/index.d.ts +0 -23
  146. package/packages/cloud/dist/webhooks/parsers/index.js +0 -30
  147. package/packages/cloud/dist/webhooks/parsers/linear.d.ts +0 -9
  148. package/packages/cloud/dist/webhooks/parsers/linear.js +0 -258
  149. package/packages/cloud/dist/webhooks/parsers/slack.d.ts +0 -9
  150. package/packages/cloud/dist/webhooks/parsers/slack.js +0 -214
  151. package/packages/cloud/dist/webhooks/responders/github.d.ts +0 -8
  152. package/packages/cloud/dist/webhooks/responders/github.js +0 -73
  153. package/packages/cloud/dist/webhooks/responders/index.d.ts +0 -23
  154. package/packages/cloud/dist/webhooks/responders/index.js +0 -30
  155. package/packages/cloud/dist/webhooks/responders/linear.d.ts +0 -9
  156. package/packages/cloud/dist/webhooks/responders/linear.js +0 -149
  157. package/packages/cloud/dist/webhooks/responders/slack.d.ts +0 -20
  158. package/packages/cloud/dist/webhooks/responders/slack.js +0 -178
  159. package/packages/cloud/dist/webhooks/router.d.ts +0 -25
  160. package/packages/cloud/dist/webhooks/router.js +0 -504
  161. package/packages/cloud/dist/webhooks/rules-engine.d.ts +0 -24
  162. package/packages/cloud/dist/webhooks/rules-engine.js +0 -287
  163. package/packages/cloud/dist/webhooks/types.d.ts +0 -186
  164. package/packages/cloud/dist/webhooks/types.js +0 -8
  165. package/packages/cloud/package.json +0 -60
  166. package/scripts/run-migrations.js +0 -43
  167. package/scripts/setup-stripe-products.ts +0 -312
  168. package/scripts/verify-schema.js +0 -134
@@ -1,62 +0,0 @@
1
- /**
2
- * Coordinator Agent Service
3
- *
4
- * Manages lifecycle of coordinator agents for project groups.
5
- * Coordinators oversee and orchestrate work across repositories in a group.
6
- */
7
- import { Repository } from '../db/index.js';
8
- /**
9
- * Coordinator agent state
10
- */
11
- interface CoordinatorState {
12
- groupId: string;
13
- groupName: string;
14
- agentName: string;
15
- model: string;
16
- status: 'starting' | 'running' | 'stopping' | 'stopped' | 'error';
17
- startedAt?: Date;
18
- stoppedAt?: Date;
19
- error?: string;
20
- repositories: Repository[];
21
- }
22
- export interface CoordinatorService {
23
- start(groupId: string): Promise<void>;
24
- stop(groupId: string): Promise<void>;
25
- restart(groupId: string): Promise<void>;
26
- getStatus(groupId: string): Promise<CoordinatorState | null>;
27
- listActive(): Promise<CoordinatorState[]>;
28
- }
29
- /**
30
- * Send a message from coordinator to a workspace
31
- */
32
- export declare function sendToWorkspace(coordinatorGroupId: string, targetWorkspaceId: string, agentName: string, message: string, thread?: string): Promise<void>;
33
- /**
34
- * Broadcast a message to all workspaces in a project group
35
- */
36
- export declare function broadcastToGroup(coordinatorGroupId: string, message: string, thread?: string): Promise<void>;
37
- /**
38
- * Route a message from a workspace to the coordinator
39
- */
40
- export declare function routeToCoordinator(workspaceId: string, agentName: string, message: string, thread?: string): Promise<void>;
41
- /**
42
- * Get all active coordinators
43
- */
44
- export declare function getActiveCoordinators(): Promise<Array<{
45
- groupId: string;
46
- groupName: string;
47
- agentName: string;
48
- model: string;
49
- startedAt: string;
50
- workspaces: string[];
51
- }>>;
52
- /**
53
- * Get the coordinator service singleton
54
- */
55
- export declare function getCoordinatorService(): CoordinatorService;
56
- /**
57
- * Initialize coordinator service
58
- * Restarts any coordinators that should be running
59
- */
60
- export declare function initializeCoordinatorService(): Promise<void>;
61
- export {};
62
- //# sourceMappingURL=coordinator.d.ts.map
@@ -1,389 +0,0 @@
1
- /**
2
- * Coordinator Agent Service
3
- *
4
- * Manages lifecycle of coordinator agents for project groups.
5
- * Coordinators oversee and orchestrate work across repositories in a group.
6
- */
7
- import { db } from '../db/index.js';
8
- import { createClient } from 'redis';
9
- import { getConfig } from '../config.js';
10
- /**
11
- * In-memory coordinator state tracker
12
- * In production, this would be persisted to database or Redis
13
- */
14
- const coordinatorStates = new Map();
15
- /**
16
- * Start a coordinator agent for a project group
17
- */
18
- async function start(groupId) {
19
- const group = await db.projectGroups.findById(groupId);
20
- if (!group) {
21
- throw new Error('Project group not found');
22
- }
23
- if (!group.coordinatorAgent?.enabled) {
24
- throw new Error('Coordinator is not enabled for this group');
25
- }
26
- const repositories = await db.repositories.findByProjectGroupId(groupId);
27
- if (repositories.length === 0) {
28
- throw new Error('Cannot start coordinator for empty group');
29
- }
30
- const config = group.coordinatorAgent;
31
- const agentName = config.name || `${group.name} Coordinator`;
32
- const model = config.model || 'claude-sonnet-4-5';
33
- // Check if already running
34
- const existing = coordinatorStates.get(groupId);
35
- if (existing && existing.status === 'running') {
36
- console.log(`Coordinator for group ${groupId} is already running`);
37
- return;
38
- }
39
- // Update state to starting
40
- const state = {
41
- groupId,
42
- groupName: group.name,
43
- agentName,
44
- model,
45
- status: 'starting',
46
- repositories,
47
- };
48
- coordinatorStates.set(groupId, state);
49
- try {
50
- // Spawn the coordinator agent
51
- // In a real implementation, this would:
52
- // 1. Connect to agent-relay daemon or cloud workspace
53
- // 2. Spawn agent with configured name and model
54
- // 3. Provide system prompt with group context
55
- // 4. Configure capabilities (read repos, create PRs, etc.)
56
- await spawnCoordinatorAgent(group, config, repositories);
57
- // Update state to running
58
- state.status = 'running';
59
- state.startedAt = new Date();
60
- coordinatorStates.set(groupId, state);
61
- console.log(`Coordinator agent started for group ${groupId}: ${agentName}`);
62
- }
63
- catch (error) {
64
- state.status = 'error';
65
- state.error = error instanceof Error ? error.message : 'Unknown error';
66
- coordinatorStates.set(groupId, state);
67
- throw error;
68
- }
69
- }
70
- /**
71
- * Stop a coordinator agent for a project group
72
- */
73
- async function stop(groupId) {
74
- const state = coordinatorStates.get(groupId);
75
- if (!state) {
76
- // Not running, nothing to do
77
- return;
78
- }
79
- if (state.status === 'stopped') {
80
- return;
81
- }
82
- // Update state to stopping
83
- state.status = 'stopping';
84
- coordinatorStates.set(groupId, state);
85
- try {
86
- // Stop the coordinator agent
87
- // In a real implementation, this would:
88
- // 1. Send stop signal to the agent
89
- // 2. Wait for graceful shutdown
90
- // 3. Clean up resources
91
- await stopCoordinatorAgent(groupId, state);
92
- // Update state to stopped
93
- state.status = 'stopped';
94
- state.stoppedAt = new Date();
95
- coordinatorStates.set(groupId, state);
96
- console.log(`Coordinator agent stopped for group ${groupId}`);
97
- }
98
- catch (error) {
99
- state.status = 'error';
100
- state.error = error instanceof Error ? error.message : 'Unknown error';
101
- coordinatorStates.set(groupId, state);
102
- throw error;
103
- }
104
- }
105
- /**
106
- * Restart a coordinator agent
107
- */
108
- async function restart(groupId) {
109
- await stop(groupId);
110
- await start(groupId);
111
- }
112
- /**
113
- * Get status of a coordinator agent
114
- */
115
- async function getStatus(groupId) {
116
- return coordinatorStates.get(groupId) || null;
117
- }
118
- /**
119
- * List all active coordinators
120
- */
121
- async function listActive() {
122
- return Array.from(coordinatorStates.values()).filter((state) => state.status === 'running' || state.status === 'starting');
123
- }
124
- /**
125
- * Redis pub/sub for cross-workspace messaging
126
- */
127
- let pubClient = null;
128
- let subClient = null;
129
- const messageHandlers = new Map();
130
- /**
131
- * Initialize Redis pub/sub clients
132
- */
133
- async function initRedisClients() {
134
- if (pubClient && subClient)
135
- return;
136
- const config = getConfig();
137
- pubClient = createClient({ url: config.redisUrl });
138
- subClient = createClient({ url: config.redisUrl });
139
- await pubClient.connect();
140
- await subClient.connect();
141
- // Subscribe to coordinator channel
142
- await subClient.subscribe('coordinator:messages', (message) => {
143
- try {
144
- const parsed = JSON.parse(message);
145
- const handler = messageHandlers.get(parsed.toWorkspace || '*');
146
- if (handler) {
147
- handler(parsed);
148
- }
149
- }
150
- catch (error) {
151
- console.error('Failed to parse coordinator message:', error);
152
- }
153
- });
154
- console.log('[coordinator] Redis pub/sub initialized');
155
- }
156
- /**
157
- * Send a message from coordinator to a workspace
158
- */
159
- export async function sendToWorkspace(coordinatorGroupId, targetWorkspaceId, agentName, message, thread) {
160
- if (!pubClient) {
161
- await initRedisClients();
162
- }
163
- const crossMessage = {
164
- type: 'relay',
165
- from: 'Coordinator',
166
- fromWorkspace: `coordinator:${coordinatorGroupId}`,
167
- to: agentName,
168
- toWorkspace: targetWorkspaceId,
169
- body: message,
170
- thread,
171
- timestamp: new Date().toISOString(),
172
- };
173
- await pubClient.publish('workspace:messages', JSON.stringify(crossMessage));
174
- console.log(`[coordinator] Sent message to ${targetWorkspaceId}:${agentName}`);
175
- }
176
- /**
177
- * Broadcast a message to all workspaces in a project group
178
- */
179
- export async function broadcastToGroup(coordinatorGroupId, message, thread) {
180
- if (!pubClient) {
181
- await initRedisClients();
182
- }
183
- const group = await db.projectGroups.findById(coordinatorGroupId);
184
- if (!group) {
185
- throw new Error('Project group not found');
186
- }
187
- const repositories = await db.repositories.findByProjectGroupId(coordinatorGroupId);
188
- // Get all workspaces containing these repositories
189
- const workspaceIds = new Set();
190
- for (const repo of repositories) {
191
- if (repo.workspaceId) {
192
- workspaceIds.add(repo.workspaceId);
193
- }
194
- }
195
- const crossMessage = {
196
- type: 'relay',
197
- from: 'Coordinator',
198
- fromWorkspace: `coordinator:${coordinatorGroupId}`,
199
- to: '*',
200
- body: message,
201
- thread,
202
- timestamp: new Date().toISOString(),
203
- };
204
- // Broadcast to each workspace
205
- for (const workspaceId of workspaceIds) {
206
- crossMessage.toWorkspace = workspaceId;
207
- await pubClient.publish('workspace:messages', JSON.stringify(crossMessage));
208
- }
209
- console.log(`[coordinator] Broadcast to ${workspaceIds.size} workspace(s)`);
210
- }
211
- /**
212
- * Spawn the actual coordinator agent
213
- */
214
- async function spawnCoordinatorAgent(group, config, repositories) {
215
- // Initialize Redis for cross-workspace messaging
216
- await initRedisClients();
217
- // Build system prompt for the coordinator
218
- const systemPrompt = buildCoordinatorSystemPrompt(group, config, repositories);
219
- // Get workspaces for the repositories
220
- const workspaceIds = new Set();
221
- for (const repo of repositories) {
222
- if (repo.workspaceId) {
223
- workspaceIds.add(repo.workspaceId);
224
- }
225
- }
226
- const workspaces = await Promise.all(Array.from(workspaceIds).map(id => db.workspaces.findById(id)));
227
- console.log(`[coordinator] Spawning coordinator agent: ${config.name || group.name}`);
228
- console.log(`[coordinator] Model: ${config.model || 'claude-sonnet-4-5'}`);
229
- console.log(`[coordinator] Repositories: ${repositories.map((r) => r.githubFullName).join(', ')}`);
230
- console.log(`[coordinator] Connected workspaces: ${workspaces.filter(Boolean).length}`);
231
- // Register message handler for this coordinator
232
- messageHandlers.set(`coordinator:${group.id}`, async (message) => {
233
- console.log(`[coordinator:${group.id}] Received: ${message.body.substring(0, 100)}...`);
234
- // In a full implementation, this would:
235
- // 1. Parse the message for coordinator commands
236
- // 2. Route to appropriate workspace(s)
237
- // 3. Track conversation state
238
- });
239
- // Store coordinator connection info in Redis for workspace discovery
240
- if (pubClient) {
241
- await pubClient.hSet(`coordinator:${group.id}`, {
242
- groupId: group.id,
243
- groupName: group.name,
244
- agentName: config.name || `${group.name} Coordinator`,
245
- model: config.model || 'claude-sonnet-4-5',
246
- startedAt: new Date().toISOString(),
247
- workspaces: JSON.stringify(Array.from(workspaceIds)),
248
- systemPrompt,
249
- });
250
- await pubClient.expire(`coordinator:${group.id}`, 86400); // 24h TTL
251
- }
252
- }
253
- /**
254
- * Stop the actual coordinator agent
255
- */
256
- async function stopCoordinatorAgent(groupId, state) {
257
- console.log(`[coordinator] Stopping coordinator agent for group ${groupId}: ${state.agentName}`);
258
- // Remove message handler
259
- messageHandlers.delete(`coordinator:${groupId}`);
260
- // Remove from Redis
261
- if (pubClient) {
262
- await pubClient.del(`coordinator:${groupId}`);
263
- }
264
- }
265
- /**
266
- * Route a message from a workspace to the coordinator
267
- */
268
- export async function routeToCoordinator(workspaceId, agentName, message, thread) {
269
- if (!pubClient) {
270
- await initRedisClients();
271
- }
272
- // Find which coordinator is managing this workspace
273
- // by scanning all coordinator keys
274
- const coordinatorKeys = await pubClient.keys('coordinator:*');
275
- for (const key of coordinatorKeys) {
276
- if (key === 'coordinator:messages')
277
- continue; // Skip the channel
278
- const data = await pubClient.hGetAll(key);
279
- if (data.workspaces) {
280
- const workspaces = JSON.parse(data.workspaces);
281
- if (workspaces.includes(workspaceId)) {
282
- // Found the coordinator for this workspace
283
- const crossMessage = {
284
- type: 'relay',
285
- from: agentName,
286
- fromWorkspace: workspaceId,
287
- to: 'Coordinator',
288
- toWorkspace: key,
289
- body: message,
290
- thread,
291
- timestamp: new Date().toISOString(),
292
- };
293
- await pubClient.publish('coordinator:messages', JSON.stringify(crossMessage));
294
- console.log(`[coordinator] Routed message from ${workspaceId}:${agentName} to ${key}`);
295
- return;
296
- }
297
- }
298
- }
299
- console.warn(`[coordinator] No coordinator found for workspace ${workspaceId}`);
300
- }
301
- /**
302
- * Get all active coordinators
303
- */
304
- export async function getActiveCoordinators() {
305
- if (!pubClient) {
306
- await initRedisClients();
307
- }
308
- const coordinatorKeys = await pubClient.keys('coordinator:*');
309
- const coordinators = [];
310
- for (const key of coordinatorKeys) {
311
- if (key === 'coordinator:messages')
312
- continue;
313
- const data = await pubClient.hGetAll(key);
314
- if (data.groupId) {
315
- coordinators.push({
316
- groupId: data.groupId,
317
- groupName: data.groupName,
318
- agentName: data.agentName,
319
- model: data.model,
320
- startedAt: data.startedAt,
321
- workspaces: data.workspaces ? JSON.parse(data.workspaces) : [],
322
- });
323
- }
324
- }
325
- return coordinators;
326
- }
327
- /**
328
- * Build system prompt for coordinator agent
329
- */
330
- function buildCoordinatorSystemPrompt(group, config, repositories) {
331
- const repoList = repositories.map((r) => r.githubFullName).join('\n- ');
332
- let prompt = `You are the coordinator agent for the "${group.name}" project group.
333
-
334
- Your role is to oversee and orchestrate work across the following repositories:
335
- - ${repoList}
336
-
337
- `;
338
- if (config.capabilities && config.capabilities.length > 0) {
339
- prompt += `You have the following capabilities:
340
- ${config.capabilities.map((c) => `- ${c}`).join('\n')}
341
-
342
- `;
343
- }
344
- if (config.systemPrompt) {
345
- prompt += `${config.systemPrompt}\n\n`;
346
- }
347
- prompt += `When coordinating work:
348
- 1. Monitor all repositories in your group
349
- 2. Identify dependencies and coordination points
350
- 3. Delegate tasks to project-specific agents when appropriate
351
- 4. Ensure consistency across repositories
352
- 5. Report status and blockers to the team
353
-
354
- Use the Agent Relay messaging system to communicate with other agents and team members.`;
355
- return prompt;
356
- }
357
- /**
358
- * Singleton instance
359
- */
360
- let coordinatorServiceInstance = null;
361
- /**
362
- * Get the coordinator service singleton
363
- */
364
- export function getCoordinatorService() {
365
- if (!coordinatorServiceInstance) {
366
- coordinatorServiceInstance = {
367
- start,
368
- stop,
369
- restart,
370
- getStatus,
371
- listActive,
372
- };
373
- }
374
- return coordinatorServiceInstance;
375
- }
376
- /**
377
- * Initialize coordinator service
378
- * Restarts any coordinators that should be running
379
- */
380
- export async function initializeCoordinatorService() {
381
- console.log('Initializing coordinator service...');
382
- // In a production system, this would:
383
- // 1. Query database for all enabled coordinators
384
- // 2. Check their expected state
385
- // 3. Restart any that should be running
386
- // For now, just log initialization
387
- console.log('Coordinator service initialized');
388
- }
389
- //# sourceMappingURL=coordinator.js.map
@@ -1,17 +0,0 @@
1
- /**
2
- * Cloud Services Index
3
- *
4
- * Exports all cloud-side services for easy importing.
5
- */
6
- export { ScalingPolicyService, type ScalingThresholds, type ScalingPolicy, type ScalingCondition, type ScalingAction, type ScalingDecision, type UserScalingContext, type WorkspaceMetrics, getScalingPolicyService, } from './scaling-policy.js';
7
- export { AutoScaler, type AutoScalerConfig, type ScalingOperation, type MetricsSnapshot, getAutoScaler, createAutoScaler, } from './auto-scaler.js';
8
- export { CapacityManager, type CapacityManagerConfig, type WorkspaceCapacity, type PlacementRecommendation, type CapacitySnapshot, type CapacityForecast, getCapacityManager, createCapacityManager, } from './capacity-manager.js';
9
- export { ScalingOrchestrator, type OrchestratorConfig, type ScalingEvent, getScalingOrchestrator, createScalingOrchestrator, } from './scaling-orchestrator.js';
10
- export { spawnCIFixAgent, notifyAgentOfCIFailure, completeFixAttempt, getFailureHistory, getPRFailureHistory, } from './ci-agent-spawner.js';
11
- export { handleMention, handleIssueAssignment, getPendingMentions, getPendingIssueAssignments, processPendingMentions, processPendingIssueAssignments, KNOWN_AGENTS, isKnownAgent, } from './mention-handler.js';
12
- export { ComputeEnforcementService, type ComputeEnforcementConfig, type EnforcementResult, getComputeEnforcementService, createComputeEnforcementService, } from './compute-enforcement.js';
13
- export { IntroExpirationService, type IntroExpirationConfig, type IntroStatus, type ExpirationResult as IntroExpirationResult, INTRO_PERIOD_DAYS, DESTROY_GRACE_PERIOD_DAYS, getIntroStatus, getIntroExpirationService, startIntroExpirationService, stopIntroExpirationService, } from './intro-expiration.js';
14
- export { WorkspaceKeepaliveService, type WorkspaceKeepaliveConfig, type KeepaliveStats, getWorkspaceKeepaliveService, createWorkspaceKeepaliveService, } from './workspace-keepalive.js';
15
- export { registerUserPresence, unregisterUserPresence, updateUserLastSeen, isUserOnline, getOnlineUser, getOnlineUsers, getOnlineUsersForDiscovery, clearAllPresence, type PresenceUserInfo, } from './presence-registry.js';
16
- export { cloudMessageBus, type CloudMessage, } from './cloud-message-bus.js';
17
- //# sourceMappingURL=index.d.ts.map
@@ -1,25 +0,0 @@
1
- /**
2
- * Cloud Services Index
3
- *
4
- * Exports all cloud-side services for easy importing.
5
- */
6
- // Scaling infrastructure
7
- export { ScalingPolicyService, getScalingPolicyService, } from './scaling-policy.js';
8
- export { AutoScaler, getAutoScaler, createAutoScaler, } from './auto-scaler.js';
9
- export { CapacityManager, getCapacityManager, createCapacityManager, } from './capacity-manager.js';
10
- export { ScalingOrchestrator, getScalingOrchestrator, createScalingOrchestrator, } from './scaling-orchestrator.js';
11
- // CI failure handling
12
- export { spawnCIFixAgent, notifyAgentOfCIFailure, completeFixAttempt, getFailureHistory, getPRFailureHistory, } from './ci-agent-spawner.js';
13
- // Issue and mention handling
14
- export { handleMention, handleIssueAssignment, getPendingMentions, getPendingIssueAssignments, processPendingMentions, processPendingIssueAssignments, KNOWN_AGENTS, isKnownAgent, } from './mention-handler.js';
15
- // Compute enforcement (free tier limits)
16
- export { ComputeEnforcementService, getComputeEnforcementService, createComputeEnforcementService, } from './compute-enforcement.js';
17
- // Intro expiration (auto-resize/destroy after free tier intro period)
18
- export { IntroExpirationService, INTRO_PERIOD_DAYS, DESTROY_GRACE_PERIOD_DAYS, getIntroStatus, getIntroExpirationService, startIntroExpirationService, stopIntroExpirationService, } from './intro-expiration.js';
19
- // Workspace keepalive (prevent Fly.io from idling machines with active agents)
20
- export { WorkspaceKeepaliveService, getWorkspaceKeepaliveService, createWorkspaceKeepaliveService, } from './workspace-keepalive.js';
21
- // Presence registry (shared registry for tracking online users)
22
- export { registerUserPresence, unregisterUserPresence, updateUserLastSeen, isUserOnline, getOnlineUser, getOnlineUsers, getOnlineUsersForDiscovery, clearAllPresence, } from './presence-registry.js';
23
- // Cloud message bus (event-based message delivery for cloud users)
24
- export { cloudMessageBus, } from './cloud-message-bus.js';
25
- //# sourceMappingURL=index.js.map
@@ -1,60 +0,0 @@
1
- /**
2
- * Intro Expiration Service
3
- *
4
- * Handles auto-resize and auto-destroy of free tier workspaces:
5
- * 1. Resize: Free users get Pro-level resources (2 CPU / 4GB) for the first 14 days,
6
- * then get automatically downsized to standard free tier (1 CPU / 2GB).
7
- * 2. Destroy: Free workspaces inactive for 7+ days after intro expires get auto-destroyed
8
- * to prevent ongoing infrastructure costs for churned users.
9
- */
10
- export declare const INTRO_PERIOD_DAYS = 14;
11
- export declare const DESTROY_GRACE_PERIOD_DAYS = 7;
12
- export interface IntroExpirationConfig {
13
- enabled: boolean;
14
- checkIntervalMs: number;
15
- }
16
- export interface IntroStatus {
17
- isIntroPeriod: boolean;
18
- daysRemaining: number;
19
- introPeriodDays: number;
20
- expiresAt: Date | null;
21
- }
22
- export interface ExpirationResult {
23
- userId: string;
24
- workspaceId: string;
25
- workspaceName: string;
26
- action: 'resized' | 'destroyed' | 'skipped' | 'error';
27
- reason?: string;
28
- }
29
- /**
30
- * Get intro period status for a user
31
- */
32
- export declare function getIntroStatus(userCreatedAt: Date | string | null, plan: string): IntroStatus;
33
- export declare class IntroExpirationService {
34
- private config;
35
- private checkTimer;
36
- private isRunning;
37
- constructor(config?: Partial<IntroExpirationConfig>);
38
- /**
39
- * Start the expiration service
40
- */
41
- start(): void;
42
- /**
43
- * Stop the expiration service
44
- */
45
- stop(): void;
46
- /**
47
- * Run expiration check for all free tier users with expired intro periods
48
- */
49
- runExpirationCheck(): Promise<ExpirationResult[]>;
50
- /**
51
- * Check and process workspaces for a user whose intro period has expired
52
- * - Resize workspaces that are still at intro-tier resources
53
- * - Destroy workspaces that have been inactive for DESTROY_GRACE_PERIOD_DAYS
54
- */
55
- private checkAndProcessUserWorkspaces;
56
- }
57
- export declare function getIntroExpirationService(): IntroExpirationService;
58
- export declare function startIntroExpirationService(): void;
59
- export declare function stopIntroExpirationService(): void;
60
- //# sourceMappingURL=intro-expiration.d.ts.map