cyrus-edge-worker 0.0.17 → 0.0.18-alpha.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.
@@ -1,25 +1,23 @@
1
1
  import { EventEmitter } from 'events';
2
+ import type { SerializableEdgeWorkerState } from 'cyrus-core';
2
3
  import type { EdgeWorkerConfig, EdgeWorkerEvents } from './types.js';
3
4
  export declare interface EdgeWorker {
4
5
  on<K extends keyof EdgeWorkerEvents>(event: K, listener: EdgeWorkerEvents[K]): this;
5
6
  emit<K extends keyof EdgeWorkerEvents>(event: K, ...args: Parameters<EdgeWorkerEvents[K]>): boolean;
6
7
  }
7
8
  /**
8
- * Unified edge worker that orchestrates NDJSON streaming, Claude processing, and Linear integration
9
+ * Unified edge worker that **orchestrates**
10
+ * capturing Linear webhooks,
11
+ * managing Claude Code processes, and
12
+ * processes results through to Linear Agent Activity Sessions
9
13
  */
10
14
  export declare class EdgeWorker extends EventEmitter {
11
15
  private config;
12
16
  private repositories;
17
+ private agentSessionManagers;
13
18
  private linearClients;
14
19
  private ndjsonClients;
15
- private sessionManager;
16
- private claudeRunners;
17
- private commentToRepo;
18
- private commentToIssue;
19
- private commentToLatestAgentReply;
20
- private issueToCommentThreads;
21
- private tokenToClientId;
22
- private issueToReplyContext;
20
+ private persistenceManager;
23
21
  private sharedApplicationServer;
24
22
  constructor(config: EdgeWorkerConfig);
25
23
  /**
@@ -42,26 +40,10 @@ export declare class EdgeWorker extends EventEmitter {
42
40
  * Handle errors
43
41
  */
44
42
  private handleError;
45
- /**
46
- * Check if Claude logs exist for a workspace
47
- */
48
- private hasExistingLogs;
49
43
  /**
50
44
  * Handle webhook events from proxy - now accepts native webhook payloads
51
45
  */
52
46
  private handleWebhook;
53
- /**
54
- * Handle issue assignment webhook
55
- */
56
- private handleIssueAssignedWebhook;
57
- /**
58
- * Handle issue comment mention webhook
59
- */
60
- private handleIssueCommentMentionWebhook;
61
- /**
62
- * Handle issue new comment webhook
63
- */
64
- private handleIssueNewCommentWebhook;
65
47
  /**
66
48
  * Handle issue unassignment webhook
67
49
  */
@@ -71,29 +53,19 @@ export declare class EdgeWorker extends EventEmitter {
71
53
  */
72
54
  private findRepositoryForWebhook;
73
55
  /**
74
- * Handle issue assignment
75
- * @param issue Linear issue object from webhook data (contains full Linear SDK properties)
76
- * @param repository Repository configuration
77
- */
78
- private handleIssueAssigned;
79
- private handleIssueAssignedWithFullIssue;
80
- /**
81
- * Find the root comment of a comment thread by traversing parent relationships
82
- */
83
- /**
84
- * Handle new root comment - creates a new Claude session for a new comment thread
85
- * @param issue Linear issue object from webhook data
86
- * @param comment Linear comment object from webhook data
56
+ * Handle agent session created webhook
57
+ * . Can happen due to being 'delegated' or @ mentioned in a new thread
58
+ * @param webhook
87
59
  * @param repository Repository configuration
88
60
  */
89
- private handleNewRootComment;
61
+ private handleAgentSessionCreatedWebhook;
90
62
  /**
91
63
  * Handle new comment on issue (updated for comment-based sessions)
92
64
  * @param issue Linear issue object from webhook data
93
65
  * @param comment Linear comment object from webhook data
94
66
  * @param repository Repository configuration
95
67
  */
96
- private handleNewComment;
68
+ private handleUserPostedAgentActivity;
97
69
  /**
98
70
  * Handle issue unassignment
99
71
  * @param issue Linear issue object from webhook data
@@ -104,22 +76,30 @@ export declare class EdgeWorker extends EventEmitter {
104
76
  * Handle Claude messages
105
77
  */
106
78
  private handleClaudeMessage;
107
- /**
108
- * Handle Claude session completion (successful)
109
- */
110
- private handleClaudeComplete;
111
79
  /**
112
80
  * Handle Claude session error
81
+ * TODO: improve this
113
82
  */
114
83
  private handleClaudeError;
115
- /**
116
- * Handle token limit by restarting session
117
- */
118
- private handleTokenLimit;
119
84
  /**
120
85
  * Fetch complete issue details from Linear API
121
86
  */
122
87
  private fetchFullIssueDetails;
88
+ /**
89
+ * Fetch issue labels for a given issue
90
+ */
91
+ private fetchIssueLabels;
92
+ /**
93
+ * Determine system prompt based on issue labels and repository configuration
94
+ */
95
+ private determineSystemPromptFromLabels;
96
+ /**
97
+ * Build simplified prompt for label-based workflows
98
+ * @param issue Full Linear issue
99
+ * @param repository Repository configuration
100
+ * @returns Formatted prompt string
101
+ */
102
+ private buildLabelBasedPrompt;
123
103
  /**
124
104
  * Convert full Linear SDK issue to CoreIssue interface for Session creation
125
105
  */
@@ -143,18 +123,10 @@ export declare class EdgeWorker extends EventEmitter {
143
123
  * @returns Formatted prompt string
144
124
  */
145
125
  private buildPromptV2;
146
- /**
147
- * Extract text content from Claude message
148
- */
149
- private extractTextContent;
150
126
  /**
151
127
  * Get connection status by repository ID
152
128
  */
153
129
  getConnectionStatus(): Map<string, boolean>;
154
- /**
155
- * Get active sessions
156
- */
157
- getActiveSessions(): string[];
158
130
  /**
159
131
  * Get NDJSON client by token (for testing purposes)
160
132
  * @internal
@@ -185,19 +157,13 @@ export declare class EdgeWorker extends EventEmitter {
185
157
  /**
186
158
  * Post initial comment when assigned to issue
187
159
  */
188
- private postInitialComment;
189
160
  /**
190
161
  * Post a comment to Linear
191
162
  */
192
163
  private postComment;
193
- /**
194
- * Update initial comment with TODO checklist
195
- */
196
- private updateCommentWithTodos;
197
164
  /**
198
165
  * Format todos as Linear checklist markdown
199
166
  */
200
- private formatTodosAsChecklist;
201
167
  /**
202
168
  * Extract attachment URLs from text (issue description or comment)
203
169
  */
@@ -217,13 +183,6 @@ export declare class EdgeWorker extends EventEmitter {
217
183
  * Generate a markdown section describing downloaded attachments
218
184
  */
219
185
  private generateAttachmentManifest;
220
- /**
221
- * Check if the agent (Cyrus) is mentioned in a comment
222
- * @param comment Linear comment object from webhook data
223
- * @param repository Repository configuration
224
- * @returns true if the agent is mentioned, false otherwise
225
- */
226
- private isAgentMentionedInComment;
227
186
  /**
228
187
  * Build MCP configuration with automatic Linear server injection
229
188
  */
@@ -232,5 +191,33 @@ export declare class EdgeWorker extends EventEmitter {
232
191
  * Build allowed tools list with Linear MCP tools automatically included
233
192
  */
234
193
  private buildAllowedTools;
194
+ /**
195
+ * Get Agent Sessions for an issue
196
+ */
197
+ getAgentSessionsForIssue(issueId: string, repositoryId: string): any[];
198
+ /**
199
+ * Load persisted EdgeWorker state for all repositories
200
+ */
201
+ private loadPersistedState;
202
+ /**
203
+ * Save current EdgeWorker state for all repositories
204
+ */
205
+ private savePersistedState;
206
+ /**
207
+ * Serialize EdgeWorker mappings to a serializable format
208
+ */
209
+ serializeMappings(): SerializableEdgeWorkerState;
210
+ /**
211
+ * Restore EdgeWorker mappings from serialized state
212
+ */
213
+ restoreMappings(state: SerializableEdgeWorkerState): void;
214
+ /**
215
+ * Post instant acknowledgment thought when agent session is created
216
+ */
217
+ private postInstantAcknowledgment;
218
+ /**
219
+ * Post thought about system prompt selection based on labels
220
+ */
221
+ private postSystemPromptSelectionThought;
235
222
  }
236
223
  //# sourceMappingURL=EdgeWorker.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"EdgeWorker.d.ts","sourceRoot":"","sources":["../src/EdgeWorker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAA;AAuBrC,OAAO,KAAK,EAAE,gBAAgB,EAAE,gBAAgB,EAAoB,MAAM,YAAY,CAAA;AAStF,MAAM,CAAC,OAAO,WAAW,UAAU;IACjC,EAAE,CAAC,CAAC,SAAS,MAAM,gBAAgB,EAAE,KAAK,EAAE,CAAC,EAAE,QAAQ,EAAE,gBAAgB,CAAC,CAAC,CAAC,GAAG,IAAI,CAAA;IACnF,IAAI,CAAC,CAAC,SAAS,MAAM,gBAAgB,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,IAAI,EAAE,UAAU,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,GAAG,OAAO,CAAA;CACpG;AAED;;GAEG;AACH,qBAAa,UAAW,SAAQ,YAAY;IAC1C,OAAO,CAAC,MAAM,CAAkB;IAChC,OAAO,CAAC,YAAY,CAA2C;IAC/D,OAAO,CAAC,aAAa,CAAuC;IAC5D,OAAO,CAAC,aAAa,CAAuC;IAC5D,O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