@myrialabs/clopen 0.4.37 → 0.4.38

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 (101) hide show
  1. package/README.md +2 -2
  2. package/backend/auth/permissions.ts +14 -0
  3. package/backend/bootstrap.ts +16 -0
  4. package/backend/database/crypto/envelope.test.ts +93 -0
  5. package/backend/database/crypto/envelope.ts +127 -0
  6. package/backend/database/crypto/index.ts +22 -0
  7. package/backend/database/crypto/master-key.ts +129 -0
  8. package/backend/database/crypto/secret-columns.ts +147 -0
  9. package/backend/database/migrations/071_create_notes_tables.ts +90 -0
  10. package/backend/database/migrations/072_encrypt_stored_secrets.ts +107 -0
  11. package/backend/database/migrations/073_create_integration_tables.ts +119 -0
  12. package/backend/database/migrations/074_create_work_tables.ts +94 -0
  13. package/backend/database/migrations/index.ts +28 -0
  14. package/backend/database/queries/db-client-connection-queries.ts +23 -12
  15. package/backend/database/queries/engine-queries.ts +23 -10
  16. package/backend/database/queries/index.ts +6 -1
  17. package/backend/database/queries/integration-queries.ts +297 -0
  18. package/backend/database/queries/mcp-server-queries.ts +38 -11
  19. package/backend/database/queries/note-queries.test.ts +190 -0
  20. package/backend/database/queries/note-queries.ts +269 -0
  21. package/backend/database/queries/profile-queries.ts +1 -1
  22. package/backend/database/queries/ssh-connection-queries.ts +19 -8
  23. package/backend/database/queries/work-queries.ts +210 -0
  24. package/backend/engine/docs/artifacts.md +22 -9
  25. package/backend/files/os-clipboard.test.ts +209 -0
  26. package/backend/files/os-clipboard.ts +567 -0
  27. package/backend/http/integration-hooks.ts +42 -0
  28. package/backend/http/notes-images.test.ts +228 -0
  29. package/backend/http/notes-images.ts +196 -0
  30. package/backend/index.ts +9 -0
  31. package/backend/integrations/accounts.ts +229 -0
  32. package/backend/integrations/health.ts +146 -0
  33. package/backend/integrations/index.ts +36 -0
  34. package/backend/integrations/projections/index.ts +120 -0
  35. package/backend/integrations/projections/mcp-projector.test.ts +204 -0
  36. package/backend/integrations/projections/mcp-projector.ts +159 -0
  37. package/backend/integrations/projections/types.ts +51 -0
  38. package/backend/integrations/registry/define.ts +38 -0
  39. package/backend/integrations/registry/index.ts +56 -0
  40. package/backend/integrations/registry/providers/context7.ts +44 -0
  41. package/backend/integrations/registry/providers/firecrawl.ts +41 -0
  42. package/backend/integrations/registry/providers/github.ts +78 -0
  43. package/backend/integrations/registry/types.ts +96 -0
  44. package/backend/integrations/webhooks/gateway.ts +160 -0
  45. package/backend/integrations/webhooks/verify.ts +65 -0
  46. package/backend/mcp/README.md +25 -3
  47. package/backend/mcp/external/config.ts +35 -1
  48. package/backend/mcp/index.ts +1 -1
  49. package/backend/mcp/internal/config.ts +1 -1
  50. package/backend/notes/access.test.ts +82 -0
  51. package/backend/notes/access.ts +27 -0
  52. package/backend/notes/storage.test.ts +77 -0
  53. package/backend/notes/storage.ts +114 -0
  54. package/backend/permissions/service.ts +2 -2
  55. package/backend/profiles/service.ts +1 -1
  56. package/backend/projects/project-cleanup.ts +6 -0
  57. package/backend/work/bindings.ts +124 -0
  58. package/backend/work/index.ts +42 -0
  59. package/backend/work/prompts.ts +150 -0
  60. package/backend/work/providers/github/actions-logs.ts +180 -0
  61. package/backend/work/providers/github/adapter.test.ts +88 -0
  62. package/backend/work/providers/github/adapter.ts +1255 -0
  63. package/backend/work/providers/github/client.ts +280 -0
  64. package/backend/work/providers/github/list-range.test.ts +158 -0
  65. package/backend/work/providers/github/token-kind.test.ts +42 -0
  66. package/backend/work/pull-requests.ts +242 -0
  67. package/backend/work/registry.ts +27 -0
  68. package/backend/work/service.ts +436 -0
  69. package/backend/work/start-work.test.ts +71 -0
  70. package/backend/work/start-work.ts +232 -0
  71. package/backend/work/types.ts +180 -0
  72. package/backend/ws/files/clipboard.ts +78 -0
  73. package/backend/ws/files/index.ts +5 -0
  74. package/backend/ws/git/diff-budget.ts +70 -11
  75. package/backend/ws/index.ts +11 -1
  76. package/backend/ws/integrations/crud.ts +219 -0
  77. package/backend/ws/integrations/index.ts +22 -0
  78. package/backend/ws/mcp/crud.ts +25 -1
  79. package/backend/ws/notes/index.ts +278 -0
  80. package/backend/ws/profiles/crud.ts +1 -1
  81. package/backend/ws/work/actions.ts +206 -0
  82. package/backend/ws/work/context.ts +51 -0
  83. package/backend/ws/work/crud.ts +347 -0
  84. package/backend/ws/work/index.ts +17 -0
  85. package/backend/ws/work/pull-requests.ts +177 -0
  86. package/backend/ws/work/schemas.ts +226 -0
  87. package/dist/assets/{index-sJmS_CCm.js → index-CyH7fSbR.js} +1 -1
  88. package/dist/assets/{index-Bik9TCBi.js → index-DSHIANSy.js} +1 -1
  89. package/dist/assets/main-D2IOjftb.css +1 -0
  90. package/dist/assets/main-DM-tHKbW.js +1152 -0
  91. package/dist/index.html +2 -2
  92. package/package.json +1 -1
  93. package/shared/constants/engine-tools.ts +1 -1
  94. package/shared/constants/tool-icons.ts +33 -0
  95. package/shared/types/database/schema.ts +41 -0
  96. package/shared/types/integrations.ts +140 -0
  97. package/shared/types/stores/settings.ts +8 -0
  98. package/shared/types/work.ts +426 -0
  99. package/shared/utils/logger.ts +3 -0
  100. package/dist/assets/main-DLqolBI2.css +0 -1
  101. package/dist/assets/main-Df1I3hnw.js +0 -1096
@@ -0,0 +1,426 @@
1
+ /**
2
+ * Issues & PRs surface — shared vocabulary.
3
+ *
4
+ * The panel talks about WORK ITEMS, not about GitHub. Every provider that can
5
+ * offer the `issues` capability is normalised into these shapes by an adapter,
6
+ * and the panel never learns which one answered. That is the whole test for
7
+ * this surface: if a second provider needs a second panel, these types are
8
+ * wrong and fixing them is the work — not adding a panel.
9
+ *
10
+ * Nothing here carries a credential. The adapter resolves the account's secret
11
+ * on the server and it never crosses this line.
12
+ */
13
+
14
+ /** An issue and a pull request are the same kind of thing to this surface. */
15
+ export type WorkItemKind = 'issue' | 'pull-request';
16
+
17
+ /**
18
+ * The one state fact the UI is allowed to reason about.
19
+ *
20
+ * Providers name their states whatever they like — "closed", "Done",
21
+ * "Won't Fix" — and those names are shown verbatim. The category is what
22
+ * decides colour and grouping, so a Linear workflow with nine states still
23
+ * renders without the panel knowing any of them.
24
+ */
25
+ export type WorkItemStateCategory = 'open' | 'closed' | 'merged' | 'draft';
26
+
27
+ export interface WorkItem {
28
+ /** Opaque provider id. Used for API calls, never shown. */
29
+ id: string;
30
+ /**
31
+ * The identifier a human uses: `123` on GitHub, `ENG-45` on Linear. This is
32
+ * what branch names and prompts are built from, so it must survive a round
33
+ * trip through a filesystem path.
34
+ */
35
+ identifier: string;
36
+ kind: WorkItemKind;
37
+ title: string;
38
+ url: string;
39
+ /** The provider's own state name, shown as-is. */
40
+ state: string;
41
+ stateCategory: WorkItemStateCategory;
42
+ labels: string[];
43
+ assignees: string[];
44
+ author: string | null;
45
+ commentCount: number;
46
+ createdAt: string;
47
+ updatedAt: string;
48
+ /** Pull requests only. */
49
+ headBranch?: string;
50
+ /**
51
+ * The commit the pull request currently points at.
52
+ *
53
+ * Carried because a BRANCH name is not a reliable way to read a pull
54
+ * request's files: a fork's branch does not exist in the base repository,
55
+ * and a merged pull request's branch is usually deleted. The sha does.
56
+ */
57
+ headSha?: string;
58
+ baseBranch?: string;
59
+ isDraft?: boolean;
60
+ }
61
+
62
+ /**
63
+ * Where a comment came from.
64
+ *
65
+ * `review-summary` is the body a reviewer wrote when submitting a review, and
66
+ * it lives on a third endpoint with its own edit semantics. It is shown because
67
+ * leaving it out makes Clopen's thread disagree with the provider's — a bot
68
+ * that posts its findings as a review appeared to have vanished — but it is not
69
+ * editable here, and saying so is better than an edit that 404s.
70
+ */
71
+ export type CommentSource = 'conversation' | 'review' | 'review-summary';
72
+
73
+ export interface WorkItemComment {
74
+ id: string;
75
+ author: string;
76
+ body: string;
77
+ createdAt: string;
78
+ url?: string;
79
+ /**
80
+ * Which conversation this belongs to.
81
+ *
82
+ * GitHub keeps review comments on a different endpoint from the discussion
83
+ * thread, and editing one through the other's URL is a 404. The surface
84
+ * shows them together, so the origin has to travel with the comment.
85
+ */
86
+ source: CommentSource;
87
+ /** True when the signed-in user may edit or delete it. */
88
+ canModify: boolean;
89
+ /** File a review comment was left on, when it was left on one. */
90
+ path?: string;
91
+ line?: number | null;
92
+ }
93
+
94
+ /** How a pull request may be merged. */
95
+ export type MergeMethod = 'merge' | 'squash' | 'rebase';
96
+
97
+ export const MERGE_METHOD_LABELS: Record<MergeMethod, string> = {
98
+ merge: 'Create a merge commit',
99
+ squash: 'Squash and merge',
100
+ rebase: 'Rebase and merge'
101
+ };
102
+
103
+ /**
104
+ * Whether this pull request can be merged right now.
105
+ *
106
+ * `mergeable` is deliberately nullable: GitHub computes it asynchronously and
107
+ * answers null while it is still thinking. Rendering null as "cannot merge"
108
+ * would tell the user their branch is broken when it is merely young.
109
+ */
110
+ export interface PullRequestMergeability {
111
+ mergeable: boolean | null;
112
+ /** The provider's own word — `clean`, `blocked`, `dirty`, `behind`. */
113
+ state: string;
114
+ /** Methods the repository allows. A repo can disable squash or rebase. */
115
+ allowedMethods: MergeMethod[];
116
+ merged: boolean;
117
+ }
118
+
119
+ export interface CommitRef {
120
+ hash: string;
121
+ subject: string;
122
+ author: string | null;
123
+ date: string;
124
+ url: string;
125
+ }
126
+
127
+ /** One commit, opened: the rest of its message and everything it touched. */
128
+ export interface CommitDetail {
129
+ commit: CommitRef;
130
+ /** The message below the subject line. Empty for a one-line commit. */
131
+ body: string;
132
+ additions: number;
133
+ deletions: number;
134
+ files: FileChange[];
135
+ }
136
+
137
+ /** One file in a pull request's diff. */
138
+ export interface FileChange {
139
+ path: string;
140
+ status: string;
141
+ additions: number;
142
+ deletions: number;
143
+ /** Unified diff. Absent for binary files and for anything over the cap. */
144
+ patch?: string;
145
+ url: string;
146
+ /**
147
+ * The blob this file's content lives in, at this revision.
148
+ *
149
+ * This is what "view the whole file" reads, in preference to a path plus a
150
+ * ref: a blob id needs no branch to still exist, no repository to be the
151
+ * one the branch lives in, and no guess about which side of a rename the
152
+ * path is on. It is the difference between the viewer working on a fork's
153
+ * pull request and the viewer reporting that the repository is unreachable.
154
+ */
155
+ sha?: string;
156
+ /** Where the file moved from, when the provider says it was renamed. */
157
+ previousPath?: string;
158
+ }
159
+
160
+ /**
161
+ * A file's text, as much of it as is worth sending.
162
+ *
163
+ * `truncated` exists so a partial file can be SHOWN and labelled instead of
164
+ * refused. "Open it on the web instead" is the viewer admitting it would rather
165
+ * not, and a generated bundle or a big lockfile is exactly the sort of file a
166
+ * reviewer needs a look at rather than a lecture about.
167
+ */
168
+ export interface FileContent {
169
+ content: string;
170
+ truncated: boolean;
171
+ }
172
+
173
+ /**
174
+ * Something that HAPPENED to an item, other than a comment.
175
+ *
176
+ * Labels, references, assignments and closures are what turn a thread into a
177
+ * history: "aanfaisal mentioned this in #454" is often the answer to why an
178
+ * issue looks the way it does, and reading only the comments hides it.
179
+ *
180
+ * `kind` is normalised; unknown provider events are dropped rather than
181
+ * rendered as a shrug, because a timeline of "something happened" entries is
182
+ * worse than a shorter honest one.
183
+ */
184
+ export type TimelineEventKind =
185
+ | 'labeled'
186
+ | 'unlabeled'
187
+ | 'assigned'
188
+ | 'unassigned'
189
+ | 'renamed'
190
+ | 'referenced'
191
+ | 'cross-referenced'
192
+ | 'closed'
193
+ | 'reopened'
194
+ | 'merged'
195
+ | 'review-requested';
196
+
197
+ export interface WorkItemEvent {
198
+ id: string;
199
+ kind: TimelineEventKind;
200
+ actor: string | null;
201
+ createdAt: string;
202
+ /** Label name, assignee login, new title — whatever the event carries. */
203
+ subject?: string;
204
+ /** The thing referenced, for reference events. */
205
+ referenceTitle?: string;
206
+ referenceUrl?: string;
207
+ referenceIdentifier?: string;
208
+ }
209
+
210
+ export interface WorkItemDetail extends WorkItem {
211
+ body: string;
212
+ comments: WorkItemComment[];
213
+ /** Non-comment history, newest last, interleaved by the UI. */
214
+ events: WorkItemEvent[];
215
+ /** Pull requests only, and only when the provider can merge. */
216
+ mergeability?: PullRequestMergeability;
217
+ }
218
+
219
+ /** One state an item can be moved to, as the provider names it. */
220
+ export interface WorkItemStateOption {
221
+ value: string;
222
+ label: string;
223
+ category: WorkItemStateCategory;
224
+ }
225
+
226
+ export type CheckStatus =
227
+ | 'queued'
228
+ | 'running'
229
+ | 'success'
230
+ | 'failure'
231
+ | 'cancelled'
232
+ | 'skipped'
233
+ | 'unknown';
234
+
235
+ /** One CI run against a branch. GitHub Actions is the first shape; others fit. */
236
+ export interface CheckRun {
237
+ id: string;
238
+ name: string;
239
+ status: CheckStatus;
240
+ url: string;
241
+ headBranch: string | null;
242
+ headSha: string;
243
+ event: string;
244
+ startedAt: string | null;
245
+ finishedAt: string | null;
246
+ /** False when the provider exposes no log endpoint for this run. */
247
+ canFetchLogs: boolean;
248
+ }
249
+
250
+ /** A failing run's logs, already trimmed to something a prompt can carry. */
251
+ export interface CheckLogBundle {
252
+ runId: string;
253
+ runName: string;
254
+ text: string;
255
+ truncated: boolean;
256
+ }
257
+
258
+ /** What a provider is actually able to do, so the UI hides what it cannot. */
259
+ export interface WorkProviderCapabilities {
260
+ pullRequests: boolean;
261
+ checks: boolean;
262
+ comments: boolean;
263
+ /** Editing and deleting comments, which not every tracker permits. */
264
+ editComments: boolean;
265
+ transitions: boolean;
266
+ /** Editing an item's title. */
267
+ editTitle: boolean;
268
+ createPullRequest: boolean;
269
+ createIssue: boolean;
270
+ merge: boolean;
271
+ assign: boolean;
272
+ /** Commits and per-file diffs for a pull request. */
273
+ diff: boolean;
274
+ }
275
+
276
+ /**
277
+ * How a work item's identifier becomes a branch name.
278
+ *
279
+ * `{kind}` → `issue` / `pr`, `{identifier}` → `123`, `{slug}` → the title
280
+ * slugified. Kept as a template rather than a boolean so a team with a naming
281
+ * convention does not have to fight the default.
282
+ */
283
+ export const DEFAULT_BRANCH_TEMPLATE = '{kind}/{identifier}-{slug}';
284
+
285
+ /**
286
+ * Per-binding behaviour. Every transition is null by default: moving someone
287
+ * else's ticket is a visible, outward-facing act, and a tool that starts doing
288
+ * it because it was installed is a tool people stop trusting.
289
+ */
290
+ export interface WorkBindingConfig {
291
+ /** State to move the item to when "Start work" runs. Null = do nothing. */
292
+ transitionOnStartWork: string | null;
293
+ /** State to move the item to when a PR is opened for it. Null = do nothing. */
294
+ transitionOnPrOpen: string | null;
295
+ branchTemplate: string;
296
+ }
297
+
298
+ export const DEFAULT_BINDING_CONFIG: WorkBindingConfig = {
299
+ transitionOnStartWork: null,
300
+ transitionOnPrOpen: null,
301
+ branchTemplate: DEFAULT_BRANCH_TEMPLATE
302
+ };
303
+
304
+ /** Which remote project this Clopen project is looking at, through one account. */
305
+ export interface IssueBinding {
306
+ /** Provider-specific locator. `owner/repo` for GitHub. */
307
+ locator: string;
308
+ /** How to print it. */
309
+ displayName: string;
310
+ /**
311
+ * True when nobody chose this — it was read off the git remote. A detected
312
+ * binding is still editable; the flag exists so the UI can say where it came
313
+ * from instead of presenting a guess as a decision.
314
+ */
315
+ detected: boolean;
316
+ defaultBranch: string | null;
317
+ config: WorkBindingConfig;
318
+ }
319
+
320
+ /** One connected account that can serve work items for the current project. */
321
+ export interface WorkSource {
322
+ accountId: string;
323
+ provider: string;
324
+ providerName: string;
325
+ label: string;
326
+ /** Who the credential belongs to, used to decide what the user may edit. */
327
+ viewer: string | null;
328
+ capabilities: WorkProviderCapabilities;
329
+ binding: IssueBinding | null;
330
+ /** Candidate locators read off the project's git remotes, for the picker. */
331
+ suggestedLocators: string[];
332
+ status: 'ok' | 'needs_auth' | 'needs_config' | 'error' | 'unknown';
333
+ statusDetail: string | null;
334
+ }
335
+
336
+ /** Provider-side state filter. Separate from "mine", which is about people. */
337
+ export type WorkItemState = 'open' | 'closed' | 'all';
338
+
339
+ export interface WorkItemQuery {
340
+ kind: WorkItemKind;
341
+ state: WorkItemState;
342
+ /** Only items assigned to — or, for pull requests, opened by — the viewer. */
343
+ mineOnly: boolean;
344
+ author?: string;
345
+ labels?: string[];
346
+ /** ISO dates, inclusive, applied to the item's last update. */
347
+ since?: string;
348
+ until?: string;
349
+ search?: string;
350
+ /** 1-based. The list appends rather than replaces for anything above 1. */
351
+ page?: number;
352
+ }
353
+
354
+ /** Remaining API budget, shown in the panel footer rather than discovered by a 403. */
355
+ export interface WorkRateLimit {
356
+ remaining: number;
357
+ limit: number;
358
+ resetAt: string | null;
359
+ }
360
+
361
+ export interface WorkItemPage {
362
+ items: WorkItem[];
363
+ rateLimit: WorkRateLimit | null;
364
+ /** True when the provider reported another page after this one. */
365
+ hasMore: boolean;
366
+ /**
367
+ * Provider page to resume from.
368
+ *
369
+ * NOT `page + 1`: a filtered page can drain several provider pages, and
370
+ * guessing would re-request everything the last call already consumed.
371
+ */
372
+ nextPage: number | null;
373
+ }
374
+
375
+ /** The link between a work item and the local work started for it. */
376
+ export interface WorkItemLink {
377
+ itemKind: WorkItemKind;
378
+ itemIdentifier: string;
379
+ worktreeId: string | null;
380
+ worktreeName: string | null;
381
+ sessionId: string | null;
382
+ branch: string | null;
383
+ createdAt: string;
384
+ }
385
+
386
+ export interface StartWorkResult {
387
+ worktreeId: string;
388
+ worktreeName: string;
389
+ sessionId: string;
390
+ branch: string;
391
+ /** The first message, already composed. The client sends it. */
392
+ prompt: string;
393
+ /** Null when no transition was configured, or when one was and it failed. */
394
+ transitionedTo: string | null;
395
+ transitionError: string | null;
396
+ /** True when the clone could not carry ignored files, so deps need installing. */
397
+ needsSetup: boolean;
398
+ }
399
+
400
+ export interface PullRequestDraft {
401
+ title: string;
402
+ body: string;
403
+ base: string;
404
+ head: string;
405
+ isDraft: boolean;
406
+ }
407
+
408
+ /** Everything the PR composer needs to open, resolved server-side in one call. */
409
+ export interface PullRequestContext {
410
+ /** Local branch the PR would come from. */
411
+ head: string;
412
+ base: string;
413
+ baseCandidates: string[];
414
+ /** Local branches the PR could come from instead. */
415
+ headCandidates: string[];
416
+ /** False when the branch has never been pushed — the composer offers to. */
417
+ isPushed: boolean;
418
+ /** Where an unpushed branch would go, so the offer can name it. */
419
+ pushRemote: string;
420
+ /** Commits on head that are not on base, newest first. */
421
+ commits: { hash: string; subject: string }[];
422
+ /** An open PR for this branch, when one already exists. */
423
+ existing: WorkItem | null;
424
+ /** The work item this branch was started from, when "Start work" made it. */
425
+ linkedItem: WorkItemLink | null;
426
+ }
@@ -28,6 +28,8 @@ export type LogLabel =
28
28
  // Communication
29
29
  | 'websocket'
30
30
  | 'mcp'
31
+ | 'integrations'
32
+ | 'work'
31
33
  | 'skills'
32
34
  | 'artifacts'
33
35
  | 'commands'
@@ -42,6 +44,7 @@ export type LogLabel =
42
44
  // Configuration
43
45
  | 'project'
44
46
  | 'workspace'
47
+ | 'notes'
45
48
  | 'settings'
46
49
  | 'engine'
47
50
  | 'tunnel'