@supaku/agentfactory-linear 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.
@@ -0,0 +1,284 @@
1
+ import type { Issue } from '@linear/sdk';
2
+ import type { AgentSessionState, AgentSessionConfig, CreateActivityOptions, AgentPlan, AgentPlanItem, AgentPlanItemState, SessionOperationResult, AgentActivityContentPayload, AgentActivitySignal, AgentActivityResult, IssueRelationResult, IssueRelationInfo } from './types';
3
+ import { type EnvironmentIssueType } from './constants';
4
+ import { type CheckboxItem, type CheckboxUpdate } from './checkbox-utils';
5
+ /**
6
+ * Agent Session Handler
7
+ * Manages the lifecycle of an agent working on a Linear issue
8
+ */
9
+ export declare class AgentSession {
10
+ private readonly client;
11
+ private readonly issueId;
12
+ private readonly autoTransition;
13
+ private readonly workType;
14
+ private sessionId;
15
+ private state;
16
+ private currentPlan;
17
+ private issue;
18
+ private activityLog;
19
+ constructor(config: AgentSessionConfig);
20
+ get currentState(): AgentSessionState;
21
+ get id(): string | null;
22
+ get plan(): AgentPlan;
23
+ get activities(): Array<{
24
+ type: string;
25
+ timestamp: Date;
26
+ content: string;
27
+ }>;
28
+ /**
29
+ * Add or update an external URL for the session
30
+ * External URLs appear in the Linear issue view, linking to dashboards, logs, or PRs
31
+ *
32
+ * @param label - Display label for the URL (e.g., "Pull Request", "Logs")
33
+ * @param url - The URL to link to
34
+ */
35
+ addExternalUrl(label: string, url: string): Promise<void>;
36
+ /**
37
+ * Set the pull request URL for this session
38
+ * This unlocks additional PR-related features in Linear
39
+ *
40
+ * @param prUrl - The GitHub pull request URL
41
+ * @see https://linear.app/developers/agents
42
+ */
43
+ setPullRequestUrl(prUrl: string): Promise<void>;
44
+ /**
45
+ * Start the agent session
46
+ *
47
+ * Transitions issue status based on work type:
48
+ * - development: Backlog -> Started
49
+ * - Other work types: No transition on start (issue stays in current status)
50
+ */
51
+ start(): Promise<SessionOperationResult>;
52
+ /**
53
+ * Mark session as awaiting user input
54
+ */
55
+ awaitInput(prompt: string): Promise<void>;
56
+ /**
57
+ * Complete the session successfully
58
+ *
59
+ * Transitions issue status based on work type:
60
+ * - development/inflight: Started -> Finished
61
+ * - qa: Finished -> Delivered (only if workResult === 'passed')
62
+ * - acceptance: Delivered -> Accepted (only if workResult === 'passed')
63
+ * - refinement: Rejected -> Backlog
64
+ * - research: No transition (user decides when to move to Backlog)
65
+ *
66
+ * @param summary - Optional completion summary to post as a comment
67
+ * @param workResult - For QA/acceptance: 'passed' promotes, 'failed' transitions to fail status, undefined skips transition
68
+ */
69
+ complete(summary?: string, workResult?: 'passed' | 'failed'): Promise<SessionOperationResult>;
70
+ /**
71
+ * Mark session as failed
72
+ * Emits an error activity (auto-generates comment) if session ID is available,
73
+ * otherwise falls back to creating a comment directly.
74
+ */
75
+ fail(errorMessage: string): Promise<SessionOperationResult>;
76
+ /**
77
+ * Emit a generic activity (legacy method for backward compatibility)
78
+ * @deprecated Use createActivity for native Linear Agent API
79
+ */
80
+ emitActivity(options: CreateActivityOptions): Promise<void>;
81
+ /**
82
+ * Create an activity using the native Linear Agent API
83
+ *
84
+ * @param content - The activity content payload
85
+ * @param ephemeral - Whether the activity should disappear after the next activity
86
+ * @param signal - Optional modifier for how the activity should be interpreted
87
+ * @returns Result containing success status and activity ID
88
+ */
89
+ createActivity(content: AgentActivityContentPayload, ephemeral?: boolean, signal?: AgentActivitySignal): Promise<AgentActivityResult>;
90
+ /**
91
+ * Emit a thought activity (persistent by default for visibility in Linear)
92
+ */
93
+ emitThought(text: string, ephemeral?: boolean): Promise<void>;
94
+ /**
95
+ * Emit an action activity (tool call)
96
+ */
97
+ emitAction(toolName: string, input: Record<string, unknown>, ephemeral?: boolean): Promise<void>;
98
+ /**
99
+ * Emit a tool result activity
100
+ */
101
+ emitToolResult(toolName: string, output: unknown, ephemeral?: boolean): Promise<void>;
102
+ /**
103
+ * Emit a response activity (persisted)
104
+ */
105
+ emitResponse(text: string): Promise<void>;
106
+ /**
107
+ * Emit an error activity using native API
108
+ */
109
+ emitError(error: Error): Promise<void>;
110
+ /**
111
+ * Emit an elicitation activity - asking for clarification from the user
112
+ */
113
+ emitElicitation(text: string, ephemeral?: boolean): Promise<AgentActivityResult | void>;
114
+ /**
115
+ * Emit a prompt activity - prompts/instructions for the user
116
+ */
117
+ emitPrompt(text: string, ephemeral?: boolean): Promise<AgentActivityResult | void>;
118
+ /**
119
+ * Emit an authentication required activity
120
+ * Shows an authentication prompt to the user with a link to authorize
121
+ *
122
+ * @param authUrl - The URL the user should visit to authenticate
123
+ * @param providerName - Optional name of the auth provider (e.g., "GitHub", "Google")
124
+ * @param body - Optional custom message body
125
+ * @returns Activity result with ID
126
+ *
127
+ * @see https://linear.app/developers/agent-signals
128
+ */
129
+ emitAuthRequired(authUrl: string, providerName?: string, body?: string): Promise<AgentActivityResult>;
130
+ /**
131
+ * Emit a selection prompt activity
132
+ * Shows a multiple choice selection to the user
133
+ *
134
+ * @param prompt - The question or prompt for the user
135
+ * @param options - Array of option strings the user can select from
136
+ * @returns Activity result with ID
137
+ *
138
+ * @see https://linear.app/developers/agent-signals
139
+ */
140
+ emitSelect(prompt: string, options: string[]): Promise<AgentActivityResult>;
141
+ /**
142
+ * Report an environment issue for self-improvement.
143
+ * Creates a bug in the Agent project backlog to track infrastructure improvements.
144
+ *
145
+ * This is a best-effort operation - failures are logged but don't propagate.
146
+ *
147
+ * @param title - Short description of the issue
148
+ * @param description - Detailed explanation of what happened
149
+ * @param context - Additional context about the issue
150
+ * @returns The created issue, or null if creation failed
151
+ */
152
+ reportEnvironmentIssue(title: string, description: string, context?: {
153
+ issueType?: EnvironmentIssueType;
154
+ sourceIssueId?: string;
155
+ errorStack?: string;
156
+ additionalContext?: Record<string, unknown>;
157
+ }): Promise<{
158
+ id: string;
159
+ identifier: string;
160
+ url: string;
161
+ } | null>;
162
+ /**
163
+ * Create an agent session on a sub-issue for activity reporting
164
+ *
165
+ * The coordinator uses this to emit activities to individual sub-issue threads,
166
+ * making sub-agent progress visible on each sub-issue in Linear.
167
+ *
168
+ * @param subIssueId - The sub-issue ID (UUID) to create a session on
169
+ * @returns The session ID for the sub-issue, or null if creation failed
170
+ */
171
+ createSubIssueSession(subIssueId: string): Promise<string | null>;
172
+ /**
173
+ * Emit an activity to a sub-issue's agent session
174
+ *
175
+ * Used by the coordinator to report progress on individual sub-issues.
176
+ * Falls back to creating a comment if the activity emission fails.
177
+ *
178
+ * @param subIssueSessionId - The agent session ID for the sub-issue
179
+ * @param content - The activity content to emit
180
+ * @param ephemeral - Whether the activity is ephemeral (default: false)
181
+ */
182
+ emitSubIssueActivity(subIssueSessionId: string, content: AgentActivityContentPayload, ephemeral?: boolean): Promise<void>;
183
+ /**
184
+ * Get the current issue description
185
+ * Refreshes the issue data from Linear if needed
186
+ */
187
+ getDescription(): Promise<string | undefined>;
188
+ /**
189
+ * Parse checkboxes from the issue description
190
+ *
191
+ * @returns Array of checkbox items, or empty array if no description
192
+ */
193
+ getDescriptionCheckboxes(): Promise<CheckboxItem[]>;
194
+ /**
195
+ * Update checkboxes in the issue description
196
+ *
197
+ * @param updates - Array of updates to apply
198
+ * @returns The updated issue, or null if no changes were made
199
+ */
200
+ updateDescriptionCheckboxes(updates: CheckboxUpdate[]): Promise<Issue | null>;
201
+ /**
202
+ * Mark a specific task as complete in the issue description
203
+ *
204
+ * @param textPattern - String or regex to match the task text
205
+ * @returns The updated issue, or null if task not found
206
+ */
207
+ completeDescriptionTask(textPattern: string | RegExp): Promise<Issue | null>;
208
+ /**
209
+ * Mark a specific task as incomplete in the issue description
210
+ *
211
+ * @param textPattern - String or regex to match the task text
212
+ * @returns The updated issue, or null if task not found
213
+ */
214
+ uncompleteDescriptionTask(textPattern: string | RegExp): Promise<Issue | null>;
215
+ /**
216
+ * Link this issue as related to another issue
217
+ *
218
+ * @param relatedIssueId - The issue ID or identifier to link to
219
+ * @returns Result with relation ID, or null if relation already exists
220
+ */
221
+ linkRelatedIssue(relatedIssueId: string): Promise<IssueRelationResult | null>;
222
+ /**
223
+ * Mark this issue as blocked by another issue
224
+ *
225
+ * @param blockingIssueId - The issue ID or identifier that blocks this one
226
+ * @returns Result with relation ID, or null if relation already exists
227
+ */
228
+ markAsBlockedBy(blockingIssueId: string): Promise<IssueRelationResult | null>;
229
+ /**
230
+ * Mark this issue as blocking another issue
231
+ *
232
+ * @param blockedIssueId - The issue ID or identifier that this issue blocks
233
+ * @returns Result with relation ID, or null if relation already exists
234
+ */
235
+ markAsBlocking(blockedIssueId: string): Promise<IssueRelationResult | null>;
236
+ /**
237
+ * Mark this issue as a duplicate of another issue
238
+ *
239
+ * @param originalIssueId - The original issue ID or identifier
240
+ * @returns Result with relation ID, or null if relation already exists
241
+ */
242
+ markAsDuplicateOf(originalIssueId: string): Promise<IssueRelationResult | null>;
243
+ /**
244
+ * Get issues that are blocking this issue
245
+ *
246
+ * @returns Array of relation info for blocking issues
247
+ */
248
+ getBlockers(): Promise<IssueRelationInfo[]>;
249
+ /**
250
+ * Check if this issue is blocked by any other issues
251
+ *
252
+ * @returns True if blocked, false otherwise
253
+ */
254
+ isBlocked(): Promise<boolean>;
255
+ /**
256
+ * Update the agent's plan (full replacement)
257
+ *
258
+ * Uses Linear's native agentSessionUpdate mutation to display the plan
259
+ * as checkboxes in the Linear UI. Also maintains internal plan state
260
+ * for checkbox sync and completion tracking.
261
+ */
262
+ updatePlan(items: Omit<AgentPlanItem, 'id'>[]): Promise<void>;
263
+ /**
264
+ * Flatten nested plan items into Linear's flat format
265
+ * Converts: { title, state, children } -> { content, status }
266
+ */
267
+ private flattenPlanItems;
268
+ /**
269
+ * Update a single plan item's state
270
+ * Also updates the plan in Linear's native API and syncs description checkboxes
271
+ */
272
+ updatePlanItemState(itemId: string, state: AgentPlanItemState): Promise<void>;
273
+ /**
274
+ * Create a plan item helper
275
+ */
276
+ createPlanItem(title: string, state?: AgentPlanItemState, details?: string): Omit<AgentPlanItem, 'id'>;
277
+ private formatActivityAsComment;
278
+ private postCompletionComment;
279
+ }
280
+ /**
281
+ * Create a new agent session
282
+ */
283
+ export declare function createAgentSession(config: AgentSessionConfig): AgentSession;
284
+ //# sourceMappingURL=agent-session.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-session.d.ts","sourceRoot":"","sources":["../../src/agent-session.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AAExC,OAAO,KAAK,EACV,iBAAiB,EACjB,kBAAkB,EAClB,qBAAqB,EACrB,SAAS,EACT,aAAa,EACb,kBAAkB,EAClB,sBAAsB,EACtB,2BAA2B,EAC3B,mBAAmB,EACnB,mBAAmB,EAInB,mBAAmB,EACnB,iBAAiB,EAClB,MAAM,SAAS,CAAA;AAYhB,OAAO,EAIL,KAAK,oBAAoB,EAC1B,MAAM,aAAa,CAAA;AACpB,OAAO,EAGL,KAAK,YAAY,EACjB,KAAK,cAAc,EACpB,MAAM,kBAAkB,CAAA;AAMzB;;;GAGG;AACH,qBAAa,YAAY;IACvB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAmB;IAC1C,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAQ;IAChC,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAS;IACxC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAe;IAExC,OAAO,CAAC,SAAS,CAAsB;IACvC,OAAO,CAAC,KAAK,CAA+B;IAC5C,OAAO,CAAC,WAAW,CAA2B;IAC9C,OAAO,CAAC,KAAK,CAAqB;IAClC,OAAO,CAAC,WAAW,CAIZ;gBAEK,MAAM,EAAE,kBAAkB;IAQtC,IAAI,YAAY,IAAI,iBAAiB,CAEpC;IAED,IAAI,EAAE,IAAI,MAAM,GAAG,IAAI,CAEtB;IAED,IAAI,IAAI,IAAI,SAAS,CAEpB;IAED,IAAI,UAAU,IAAI,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,IAAI,CAAC;QAAC,OAAO,EAAE,MAAM,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