@supaku/agentfactory-linear 0.7.9 → 0.7.11

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 (34) hide show
  1. package/dist/src/agent-client-project-repo.test.d.ts +2 -0
  2. package/dist/src/agent-client-project-repo.test.d.ts.map +1 -0
  3. package/dist/src/agent-client-project-repo.test.js +149 -0
  4. package/dist/src/agent-client.d.ts +11 -0
  5. package/dist/src/agent-client.d.ts.map +1 -1
  6. package/dist/src/agent-client.js +30 -0
  7. package/dist/src/constants.d.ts +5 -0
  8. package/dist/src/constants.d.ts.map +1 -1
  9. package/dist/src/constants.js +7 -0
  10. package/dist/src/defaults/index.d.ts +1 -1
  11. package/dist/src/defaults/index.d.ts.map +1 -1
  12. package/dist/src/defaults/index.js +1 -1
  13. package/dist/src/defaults/prompts.d.ts +18 -1
  14. package/dist/src/defaults/prompts.d.ts.map +1 -1
  15. package/dist/src/defaults/prompts.js +108 -5
  16. package/dist/src/defaults/prompts.test.d.ts +2 -0
  17. package/dist/src/defaults/prompts.test.d.ts.map +1 -0
  18. package/dist/src/defaults/prompts.test.js +130 -0
  19. package/dist/src/frontend-adapter.d.ts +168 -0
  20. package/dist/src/frontend-adapter.d.ts.map +1 -0
  21. package/dist/src/frontend-adapter.js +314 -0
  22. package/dist/src/frontend-adapter.test.d.ts +2 -0
  23. package/dist/src/frontend-adapter.test.d.ts.map +1 -0
  24. package/dist/src/frontend-adapter.test.js +545 -0
  25. package/dist/src/index.d.ts +6 -2
  26. package/dist/src/index.d.ts.map +1 -1
  27. package/dist/src/index.js +6 -2
  28. package/dist/src/platform-adapter.d.ts +119 -0
  29. package/dist/src/platform-adapter.d.ts.map +1 -0
  30. package/dist/src/platform-adapter.js +229 -0
  31. package/dist/src/platform-adapter.test.d.ts +2 -0
  32. package/dist/src/platform-adapter.test.d.ts.map +1 -0
  33. package/dist/src/platform-adapter.test.js +435 -0
  34. package/package.json +1 -1
@@ -0,0 +1,119 @@
1
+ /**
2
+ * LinearPlatformAdapter
3
+ *
4
+ * Extends LinearFrontendAdapter with Governor event integration methods.
5
+ * Structurally satisfies the PlatformAdapter interface from @supaku/agentfactory
6
+ * without an explicit `implements` clause, avoiding a circular package dependency
7
+ * (core depends on linear, so linear cannot import core).
8
+ *
9
+ * Responsibilities:
10
+ * - Normalize Linear webhook payloads into GovernorEvents
11
+ * - Scan Linear projects for non-terminal issues
12
+ * - Convert Linear SDK Issue objects to GovernorIssue
13
+ */
14
+ import { LinearFrontendAdapter } from './frontend-adapter.js';
15
+ import type { LinearAgentClient } from './agent-client.js';
16
+ /**
17
+ * Minimal issue representation used by the Governor.
18
+ * Structurally identical to GovernorIssue in @supaku/agentfactory.
19
+ */
20
+ export interface GovernorIssue {
21
+ id: string;
22
+ identifier: string;
23
+ title: string;
24
+ description?: string;
25
+ status: string;
26
+ labels: string[];
27
+ createdAt: number;
28
+ parentId?: string;
29
+ project?: string;
30
+ }
31
+ /** Where an event originated. */
32
+ type EventSource = 'webhook' | 'poll' | 'manual';
33
+ /**
34
+ * Fired when an issue's workflow status changes.
35
+ * Structurally identical to IssueStatusChangedEvent in @supaku/agentfactory.
36
+ */
37
+ interface IssueStatusChangedEvent {
38
+ type: 'issue-status-changed';
39
+ issueId: string;
40
+ issue: GovernorIssue;
41
+ previousStatus?: string;
42
+ newStatus: string;
43
+ timestamp: string;
44
+ source: EventSource;
45
+ }
46
+ /**
47
+ * Fired when a comment is added to an issue.
48
+ * Structurally identical to CommentAddedEvent in @supaku/agentfactory.
49
+ */
50
+ interface CommentAddedEvent {
51
+ type: 'comment-added';
52
+ issueId: string;
53
+ issue: GovernorIssue;
54
+ commentId: string;
55
+ commentBody: string;
56
+ userId?: string;
57
+ userName?: string;
58
+ timestamp: string;
59
+ source: EventSource;
60
+ }
61
+ /** Union of events this adapter can produce. */
62
+ type GovernorEvent = IssueStatusChangedEvent | CommentAddedEvent;
63
+ /**
64
+ * Linear platform adapter for the EventDrivenGovernor.
65
+ *
66
+ * Extends LinearFrontendAdapter to inherit all frontend operations
67
+ * (status mapping, issue read/write, agent sessions) and adds
68
+ * Governor-specific methods for webhook normalization, project scanning,
69
+ * and issue conversion.
70
+ *
71
+ * Structurally satisfies PlatformAdapter from @supaku/agentfactory.
72
+ */
73
+ export declare class LinearPlatformAdapter extends LinearFrontendAdapter {
74
+ /**
75
+ * The underlying Linear client, exposed to subclass methods.
76
+ * Re-declared here because the parent's `client` field is private.
77
+ */
78
+ private readonly linearAgentClient;
79
+ constructor(client: LinearAgentClient);
80
+ /**
81
+ * Normalize a raw Linear webhook payload into GovernorEvents.
82
+ *
83
+ * Handles two payload types:
84
+ * - Issue updates with state changes -> IssueStatusChangedEvent
85
+ * - Comment creations -> CommentAddedEvent
86
+ *
87
+ * Returns `null` for unrecognized payloads (e.g., label changes,
88
+ * AgentSession events, or other resource types).
89
+ *
90
+ * @param payload - Raw Linear webhook payload
91
+ * @returns Array of GovernorEvents, or null if not relevant
92
+ */
93
+ normalizeWebhookEvent(payload: unknown): GovernorEvent[] | null;
94
+ /**
95
+ * Scan a Linear project for all non-terminal issues.
96
+ *
97
+ * Queries the Linear API with a filter that excludes terminal statuses
98
+ * (Accepted, Canceled, Duplicate). Each issue is converted to a
99
+ * GovernorIssue for evaluation by the Governor.
100
+ *
101
+ * @param project - Linear project name to scan
102
+ * @returns Array of GovernorIssue for all active issues
103
+ */
104
+ scanProjectIssues(project: string): Promise<GovernorIssue[]>;
105
+ /**
106
+ * Convert a Linear SDK Issue object to a GovernorIssue.
107
+ *
108
+ * The `native` parameter is typed as `unknown` to satisfy the
109
+ * PlatformAdapter interface. Internally it is cast to the Linear SDK
110
+ * `Issue` type. Callers must ensure they pass a valid Linear Issue.
111
+ *
112
+ * @param native - Linear SDK Issue object
113
+ * @returns GovernorIssue representation
114
+ * @throws Error if the native object is not a valid Linear Issue
115
+ */
116
+ toGovernorIssue(native: unknown): Promise<GovernorIssue>;
117
+ }
118
+ export {};
119
+ //# sourceMappingURL=platform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AA;CACpB;AAED,gDAAgD;AAChD,KAAK,aAAa,GAAG,uBAAuB,GAAG,iBAAiB,CAAA;AAmJhE;;;;;;;;;GASG;AACH,qBAAa,qBAAsB,SAAQ,qBAAqB;IAC9D;;;OAGG;IACH,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAmB;gBAEzC,MAAM,EAAE,iBAAiB;IAOrC;;;;;;;;;;;;OAYG;IACH,qBAAqB,CAAC,OAAO,EAAE,OAAO,GAAG,aAAa,EAAE,GAAG,IAAI;IA0D/D;;;;;;;;;OASG;IACG,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;IAkBlE;;;;;;;;;;OAUG;IACG,eAAe,CAAC,MAAM,EAAE,OAAO,GAAG,OAAO,CAAC,aAAa,CAAC;CAS/D"}
@@ -0,0 +1,229 @@
1
+ /**
2
+ * LinearPlatformAdapter
3
+ *
4
+ * Extends LinearFrontendAdapter with Governor event integration methods.
5
+ * Structurally satisfies the PlatformAdapter interface from @supaku/agentfactory
6
+ * without an explicit `implements` clause, avoiding a circular package dependency
7
+ * (core depends on linear, so linear cannot import core).
8
+ *
9
+ * Responsibilities:
10
+ * - Normalize Linear webhook payloads into GovernorEvents
11
+ * - Scan Linear projects for non-terminal issues
12
+ * - Convert Linear SDK Issue objects to GovernorIssue
13
+ */
14
+ import { LinearFrontendAdapter } from './frontend-adapter.js';
15
+ // ---------------------------------------------------------------------------
16
+ // Terminal statuses
17
+ // ---------------------------------------------------------------------------
18
+ /**
19
+ * Statuses that represent terminal states in Linear.
20
+ * Issues in these states are excluded from project scans.
21
+ */
22
+ const TERMINAL_STATUSES = ['Accepted', 'Canceled', 'Duplicate'];
23
+ // ---------------------------------------------------------------------------
24
+ // Helpers
25
+ // ---------------------------------------------------------------------------
26
+ /**
27
+ * Generate an ISO-8601 timestamp for the current moment.
28
+ * Equivalent to `eventTimestamp()` from @supaku/agentfactory.
29
+ */
30
+ function eventTimestamp() {
31
+ return new Date().toISOString();
32
+ }
33
+ /**
34
+ * Build a GovernorIssue from Linear webhook issue data.
35
+ * Does not make API calls -- uses only the data present in the webhook payload.
36
+ */
37
+ function webhookIssueToGovernorIssue(issueData) {
38
+ return {
39
+ id: issueData.id,
40
+ identifier: issueData.identifier,
41
+ title: issueData.title,
42
+ description: issueData.description ?? undefined,
43
+ status: issueData.state?.name ?? 'Backlog',
44
+ labels: issueData.labels?.map((l) => l.name) ?? [],
45
+ createdAt: issueData.createdAt
46
+ ? new Date(issueData.createdAt).getTime()
47
+ : Date.now(),
48
+ parentId: issueData.parent?.id,
49
+ project: issueData.project?.name,
50
+ };
51
+ }
52
+ /**
53
+ * Convert a Linear SDK Issue object to a GovernorIssue.
54
+ * Resolves lazy-loaded relations (state, labels, parent, project).
55
+ */
56
+ async function sdkIssueToGovernorIssue(issue) {
57
+ const state = await issue.state;
58
+ const labels = await issue.labels();
59
+ const parent = await issue.parent;
60
+ const project = await issue.project;
61
+ return {
62
+ id: issue.id,
63
+ identifier: issue.identifier,
64
+ title: issue.title,
65
+ description: issue.description ?? undefined,
66
+ status: state?.name ?? 'Backlog',
67
+ labels: labels.nodes.map((l) => l.name),
68
+ createdAt: issue.createdAt.getTime(),
69
+ parentId: parent?.id,
70
+ project: project?.name,
71
+ };
72
+ }
73
+ // ---------------------------------------------------------------------------
74
+ // Type guards for webhook payloads
75
+ // ---------------------------------------------------------------------------
76
+ /**
77
+ * Check if a payload looks like a Linear issue webhook.
78
+ */
79
+ function isIssuePayload(payload) {
80
+ if (typeof payload !== 'object' || payload === null)
81
+ return false;
82
+ const p = payload;
83
+ return (p.type === 'Issue' &&
84
+ typeof p.action === 'string' &&
85
+ typeof p.data === 'object' &&
86
+ p.data !== null);
87
+ }
88
+ /**
89
+ * Check if a payload looks like a Linear comment webhook.
90
+ */
91
+ function isCommentPayload(payload) {
92
+ if (typeof payload !== 'object' || payload === null)
93
+ return false;
94
+ const p = payload;
95
+ return (p.type === 'Comment' &&
96
+ typeof p.action === 'string' &&
97
+ typeof p.data === 'object' &&
98
+ p.data !== null);
99
+ }
100
+ // ---------------------------------------------------------------------------
101
+ // LinearPlatformAdapter
102
+ // ---------------------------------------------------------------------------
103
+ /**
104
+ * Linear platform adapter for the EventDrivenGovernor.
105
+ *
106
+ * Extends LinearFrontendAdapter to inherit all frontend operations
107
+ * (status mapping, issue read/write, agent sessions) and adds
108
+ * Governor-specific methods for webhook normalization, project scanning,
109
+ * and issue conversion.
110
+ *
111
+ * Structurally satisfies PlatformAdapter from @supaku/agentfactory.
112
+ */
113
+ export class LinearPlatformAdapter extends LinearFrontendAdapter {
114
+ /**
115
+ * The underlying Linear client, exposed to subclass methods.
116
+ * Re-declared here because the parent's `client` field is private.
117
+ */
118
+ linearAgentClient;
119
+ constructor(client) {
120
+ super(client);
121
+ this.linearAgentClient = client;
122
+ }
123
+ // ---- PlatformAdapter methods ----
124
+ /**
125
+ * Normalize a raw Linear webhook payload into GovernorEvents.
126
+ *
127
+ * Handles two payload types:
128
+ * - Issue updates with state changes -> IssueStatusChangedEvent
129
+ * - Comment creations -> CommentAddedEvent
130
+ *
131
+ * Returns `null` for unrecognized payloads (e.g., label changes,
132
+ * AgentSession events, or other resource types).
133
+ *
134
+ * @param payload - Raw Linear webhook payload
135
+ * @returns Array of GovernorEvents, or null if not relevant
136
+ */
137
+ normalizeWebhookEvent(payload) {
138
+ // Handle Issue update with state change
139
+ if (isIssuePayload(payload)) {
140
+ // Only handle updates (not creates/removes)
141
+ if (payload.action !== 'update')
142
+ return null;
143
+ // Only produce an event if the state actually changed
144
+ const hasStateChange = payload.updatedFrom?.stateId !== undefined;
145
+ if (!hasStateChange)
146
+ return null;
147
+ const issue = webhookIssueToGovernorIssue(payload.data);
148
+ const event = {
149
+ type: 'issue-status-changed',
150
+ issueId: payload.data.id,
151
+ issue,
152
+ newStatus: issue.status,
153
+ // Previous status name is not directly available from stateId alone;
154
+ // we only know the stateId changed. The previous status name would
155
+ // require an API call, so we leave it undefined.
156
+ previousStatus: undefined,
157
+ timestamp: eventTimestamp(),
158
+ source: 'webhook',
159
+ };
160
+ return [event];
161
+ }
162
+ // Handle Comment creation
163
+ if (isCommentPayload(payload)) {
164
+ if (payload.action !== 'create')
165
+ return null;
166
+ const commentData = payload.data;
167
+ const issueData = commentData.issue;
168
+ if (!issueData)
169
+ return null;
170
+ const issue = webhookIssueToGovernorIssue(issueData);
171
+ const event = {
172
+ type: 'comment-added',
173
+ issueId: issueData.id,
174
+ issue,
175
+ commentId: commentData.id,
176
+ commentBody: commentData.body,
177
+ userId: commentData.user?.id,
178
+ userName: commentData.user?.name,
179
+ timestamp: eventTimestamp(),
180
+ source: 'webhook',
181
+ };
182
+ return [event];
183
+ }
184
+ // Unrecognized payload type
185
+ return null;
186
+ }
187
+ /**
188
+ * Scan a Linear project for all non-terminal issues.
189
+ *
190
+ * Queries the Linear API with a filter that excludes terminal statuses
191
+ * (Accepted, Canceled, Duplicate). Each issue is converted to a
192
+ * GovernorIssue for evaluation by the Governor.
193
+ *
194
+ * @param project - Linear project name to scan
195
+ * @returns Array of GovernorIssue for all active issues
196
+ */
197
+ async scanProjectIssues(project) {
198
+ const linearClient = this.linearAgentClient.linearClient;
199
+ const issueConnection = await linearClient.issues({
200
+ filter: {
201
+ project: { name: { eq: project } },
202
+ state: { name: { nin: [...TERMINAL_STATUSES] } },
203
+ },
204
+ });
205
+ const results = [];
206
+ for (const issue of issueConnection.nodes) {
207
+ results.push(await sdkIssueToGovernorIssue(issue));
208
+ }
209
+ return results;
210
+ }
211
+ /**
212
+ * Convert a Linear SDK Issue object to a GovernorIssue.
213
+ *
214
+ * The `native` parameter is typed as `unknown` to satisfy the
215
+ * PlatformAdapter interface. Internally it is cast to the Linear SDK
216
+ * `Issue` type. Callers must ensure they pass a valid Linear Issue.
217
+ *
218
+ * @param native - Linear SDK Issue object
219
+ * @returns GovernorIssue representation
220
+ * @throws Error if the native object is not a valid Linear Issue
221
+ */
222
+ async toGovernorIssue(native) {
223
+ const issue = native;
224
+ if (!issue || typeof issue.id !== 'string') {
225
+ throw new Error('LinearPlatformAdapter.toGovernorIssue: expected a Linear SDK Issue object');
226
+ }
227
+ return sdkIssueToGovernorIssue(issue);
228
+ }
229
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=platform-adapter.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"platform-adapter.test.d.ts","sourceRoot":"","sources":["../../src/platform-adapter.test.ts"],"names":[],"mappings":""}