@bevel-software/platform-shared 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.
Files changed (77) hide show
  1. package/LICENSE +202 -0
  2. package/dist/auth/types.d.ts +15 -0
  3. package/dist/auth/types.d.ts.map +1 -0
  4. package/dist/auth/types.js +2 -0
  5. package/dist/auth/types.js.map +1 -0
  6. package/dist/chat/types.d.ts +39 -0
  7. package/dist/chat/types.d.ts.map +1 -0
  8. package/dist/chat/types.js +13 -0
  9. package/dist/chat/types.js.map +1 -0
  10. package/dist/git/branchAuthor.d.ts +28 -0
  11. package/dist/git/branchAuthor.d.ts.map +1 -0
  12. package/dist/git/branchAuthor.js +45 -0
  13. package/dist/git/branchAuthor.js.map +1 -0
  14. package/dist/git/pr.types.d.ts +264 -0
  15. package/dist/git/pr.types.d.ts.map +1 -0
  16. package/dist/git/pr.types.js +2 -0
  17. package/dist/git/pr.types.js.map +1 -0
  18. package/dist/git/protected.d.ts +52 -0
  19. package/dist/git/protected.d.ts.map +1 -0
  20. package/dist/git/protected.js +92 -0
  21. package/dist/git/protected.js.map +1 -0
  22. package/dist/git/review.types.d.ts +49 -0
  23. package/dist/git/review.types.d.ts.map +1 -0
  24. package/dist/git/review.types.js +2 -0
  25. package/dist/git/review.types.js.map +1 -0
  26. package/dist/git/types.d.ts +107 -0
  27. package/dist/git/types.d.ts.map +1 -0
  28. package/dist/git/types.js +2 -0
  29. package/dist/git/types.js.map +1 -0
  30. package/dist/index.d.ts +15 -0
  31. package/dist/index.d.ts.map +1 -0
  32. package/dist/index.js +20 -0
  33. package/dist/index.js.map +1 -0
  34. package/dist/workflow/events.d.ts +218 -0
  35. package/dist/workflow/events.d.ts.map +1 -0
  36. package/dist/workflow/events.js +48 -0
  37. package/dist/workflow/events.js.map +1 -0
  38. package/dist/workflow/interface.d.ts +233 -0
  39. package/dist/workflow/interface.d.ts.map +1 -0
  40. package/dist/workflow/interface.js +20 -0
  41. package/dist/workflow/interface.js.map +1 -0
  42. package/dist/workflow/types.d.ts +131 -0
  43. package/dist/workflow/types.d.ts.map +1 -0
  44. package/dist/workflow/types.js +17 -0
  45. package/dist/workflow/types.js.map +1 -0
  46. package/dist/workspace/filename.d.ts +33 -0
  47. package/dist/workspace/filename.d.ts.map +1 -0
  48. package/dist/workspace/filename.js +98 -0
  49. package/dist/workspace/filename.js.map +1 -0
  50. package/dist/workspace/frontmatter.d.ts +23 -0
  51. package/dist/workspace/frontmatter.d.ts.map +1 -0
  52. package/dist/workspace/frontmatter.js +48 -0
  53. package/dist/workspace/frontmatter.js.map +1 -0
  54. package/dist/workspace/kb-layout.d.ts +66 -0
  55. package/dist/workspace/kb-layout.d.ts.map +1 -0
  56. package/dist/workspace/kb-layout.js +63 -0
  57. package/dist/workspace/kb-layout.js.map +1 -0
  58. package/dist/workspace/types.d.ts +57 -0
  59. package/dist/workspace/types.d.ts.map +1 -0
  60. package/dist/workspace/types.js +2 -0
  61. package/dist/workspace/types.js.map +1 -0
  62. package/package.json +41 -0
  63. package/src/auth/types.ts +16 -0
  64. package/src/chat/types.ts +53 -0
  65. package/src/git/branchAuthor.ts +46 -0
  66. package/src/git/pr.types.ts +274 -0
  67. package/src/git/protected.ts +121 -0
  68. package/src/git/review.types.ts +51 -0
  69. package/src/git/types.ts +170 -0
  70. package/src/index.ts +23 -0
  71. package/src/workflow/events.ts +271 -0
  72. package/src/workflow/interface.ts +357 -0
  73. package/src/workflow/types.ts +156 -0
  74. package/src/workspace/filename.ts +102 -0
  75. package/src/workspace/frontmatter.ts +45 -0
  76. package/src/workspace/kb-layout.ts +81 -0
  77. package/src/workspace/types.ts +59 -0
package/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,15 @@
1
+ export interface AuthUser {
2
+ id: string;
3
+ email: string;
4
+ name: string;
5
+ avatarUrl?: string;
6
+ }
7
+ export interface LoginRequest {
8
+ email: string;
9
+ password: string;
10
+ }
11
+ export interface LoginResponse {
12
+ token: string;
13
+ user: AuthUser;
14
+ }
15
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/auth/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,QAAQ;IACvB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,QAAQ,CAAC;CAChB"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/auth/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,39 @@
1
+ import type { UIMessage } from 'ai';
2
+ import type { AuthUser } from '../auth/types.js';
3
+ /**
4
+ * Domain-owned alias for the AI SDK v5 UIMessage shape.
5
+ *
6
+ * Backend and frontend both import `ChatUIMessage` rather than `UIMessage`
7
+ * directly so the seam is renameable if the SDK type shifts.
8
+ */
9
+ export type ChatUIMessage = UIMessage;
10
+ export interface ChatThread {
11
+ id: string;
12
+ title: string;
13
+ createdAt: number;
14
+ updatedAt: number;
15
+ }
16
+ export declare const COMPACTION_SOFT_LIMIT_TOKENS = 200000;
17
+ export declare const COMPACTION_HARD_LIMIT_TOKENS = 350000;
18
+ /** Per-turn token usage attached to the assistant message via a `data-usage` part. */
19
+ export interface UsagePartData {
20
+ used: number;
21
+ softLimit: number;
22
+ hardLimit: number;
23
+ }
24
+ export interface IChatService {
25
+ streamResponse(params: {
26
+ message: string;
27
+ resourceId: string;
28
+ threadId: string;
29
+ workspaceId: string;
30
+ /**
31
+ * Required — the agent authors every git commit as the user, and the
32
+ * author marker it pastes into PR bodies is derived from the user's email.
33
+ * Backend reads `user.name` and `user.email` unconditionally.
34
+ */
35
+ user: AuthUser;
36
+ abortSignal?: AbortSignal;
37
+ }): Promise<ReadableStream<unknown>>;
38
+ }
39
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/chat/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AACpC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAEjD;;;;;GAKG;AACH,MAAM,MAAM,aAAa,GAAG,SAAS,CAAC;AAEtC,MAAM,WAAW,UAAU;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;CACnB;AAYD,eAAO,MAAM,4BAA4B,SAAU,CAAC;AACpD,eAAO,MAAM,4BAA4B,SAAU,CAAC;AAEpD,sFAAsF;AACtF,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,YAAY;IAC3B,cAAc,CAAC,MAAM,EAAE;QACrB,OAAO,EAAE,MAAM,CAAC;QAChB,UAAU,EAAE,MAAM,CAAC;QACnB,QAAQ,EAAE,MAAM,CAAC;QACjB,WAAW,EAAE,MAAM,CAAC;QACpB;;;;WAIG;QACH,IAAI,EAAE,QAAQ,CAAC;QACf,WAAW,CAAC,EAAE,WAAW,CAAC;KAC3B,GAAG,OAAO,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,CAAC;CACtC"}
@@ -0,0 +1,13 @@
1
+ // Calibrated for gpt-5.1 (~400k context) with current agent.instructions.ts size
2
+ // + typical KB file tree. Lower than the raw window because the system prompt
3
+ // and workspace state occupy ~40-80k before the user types. Re-tune if the
4
+ // model changes or the system prompt grows materially.
5
+ //
6
+ // Both thresholds drive the agent's input processors in BaseAgentFactory:
7
+ // - softLimit → SummaryCompactor recaps the middle of the transcript
8
+ // - hardLimit → TokenLimiterProcessor backstops with truncation
9
+ // The composer's context-usage gauge also reads these via the UsagePartData
10
+ // emitted at end-of-turn.
11
+ export const COMPACTION_SOFT_LIMIT_TOKENS = 200_000;
12
+ export const COMPACTION_HARD_LIMIT_TOKENS = 350_000;
13
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/chat/types.ts"],"names":[],"mappings":"AAkBA,iFAAiF;AACjF,8EAA8E;AAC9E,2EAA2E;AAC3E,uDAAuD;AACvD,EAAE;AACF,0EAA0E;AAC1E,wEAAwE;AACxE,mEAAmE;AACnE,4EAA4E;AAC5E,0BAA0B;AAC1B,MAAM,CAAC,MAAM,4BAA4B,GAAG,OAAO,CAAC;AACpD,MAAM,CAAC,MAAM,4BAA4B,GAAG,OAAO,CAAC"}
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Derive the kebab-cased branch-author localpart from an email.
3
+ *
4
+ * The frontend's `slugifyDraftName` lowercases the email's localpart and
5
+ * replaces non-alphanumeric runs with `-` when building a new branch name
6
+ * (e.g. `Alice@example.com` → `alice/<slug>`, `john.doe@…` → `john-doe/…`).
7
+ * Authorship lookup must use the same transformation so a branch the user
8
+ * could create via the UI is also recognised as theirs on delete.
9
+ *
10
+ * Returns `null` when the email is missing or sanitizes to an empty string —
11
+ * authorship MUST NOT silently fall back to a default identity like `user`.
12
+ * If the helper returned a fallback, any user without a valid localpart
13
+ * would be granted ownership of every `user/...` branch on origin, which is
14
+ * the opposite of the safety property `isBranchAuthoredBy` is meant to
15
+ * provide. The frontend's `slugifyDraftName` can keep its UI-side `user`
16
+ * fallback at the call site because draft creation is not access-gated.
17
+ */
18
+ export declare function branchAuthorLocalpart(email: string | null | undefined): string | null;
19
+ /**
20
+ * True when `branchName` starts with `<email-localpart>/` — i.e. when the
21
+ * branch matches the UI-created draft convention for this user.
22
+ *
23
+ * The trailing `/` is REQUIRED: without it, `alice-extra/foo` would look
24
+ * authored by `alice@…`, and any user could delete branches whose prefix
25
+ * happens to start with their own localpart. Substring is not authorship.
26
+ */
27
+ export declare function isBranchAuthoredBy(branchName: string, email: string | null | undefined): boolean;
28
+ //# sourceMappingURL=branchAuthor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"branchAuthor.d.ts","sourceRoot":"","sources":["../../src/git/branchAuthor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,qBAAqB,CACnC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAC/B,MAAM,GAAG,IAAI,CASf;AAED;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAChC,UAAU,EAAE,MAAM,EAClB,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAC/B,OAAO,CAIT"}
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Derive the kebab-cased branch-author localpart from an email.
3
+ *
4
+ * The frontend's `slugifyDraftName` lowercases the email's localpart and
5
+ * replaces non-alphanumeric runs with `-` when building a new branch name
6
+ * (e.g. `Alice@example.com` → `alice/<slug>`, `john.doe@…` → `john-doe/…`).
7
+ * Authorship lookup must use the same transformation so a branch the user
8
+ * could create via the UI is also recognised as theirs on delete.
9
+ *
10
+ * Returns `null` when the email is missing or sanitizes to an empty string —
11
+ * authorship MUST NOT silently fall back to a default identity like `user`.
12
+ * If the helper returned a fallback, any user without a valid localpart
13
+ * would be granted ownership of every `user/...` branch on origin, which is
14
+ * the opposite of the safety property `isBranchAuthoredBy` is meant to
15
+ * provide. The frontend's `slugifyDraftName` can keep its UI-side `user`
16
+ * fallback at the call site because draft creation is not access-gated.
17
+ */
18
+ export function branchAuthorLocalpart(email) {
19
+ if (!email)
20
+ return null;
21
+ const before = email.split('@')[0];
22
+ if (!before)
23
+ return null;
24
+ const sanitized = before.toLowerCase().replace(/[^a-z0-9]+/g, '-');
25
+ // Sanitized can be all dashes (`-`, `--`) when every char was non-alphanumeric;
26
+ // treat that as no usable identity.
27
+ if (!sanitized.replace(/-/g, ''))
28
+ return null;
29
+ return sanitized;
30
+ }
31
+ /**
32
+ * True when `branchName` starts with `<email-localpart>/` — i.e. when the
33
+ * branch matches the UI-created draft convention for this user.
34
+ *
35
+ * The trailing `/` is REQUIRED: without it, `alice-extra/foo` would look
36
+ * authored by `alice@…`, and any user could delete branches whose prefix
37
+ * happens to start with their own localpart. Substring is not authorship.
38
+ */
39
+ export function isBranchAuthoredBy(branchName, email) {
40
+ const localpart = branchAuthorLocalpart(email);
41
+ if (!localpart)
42
+ return false;
43
+ return branchName.startsWith(`${localpart}/`);
44
+ }
45
+ //# sourceMappingURL=branchAuthor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"branchAuthor.js","sourceRoot":"","sources":["../../src/git/branchAuthor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,qBAAqB,CACnC,KAAgC;IAEhC,IAAI,CAAC,KAAK;QAAE,OAAO,IAAI,CAAC;IACxB,MAAM,MAAM,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IACnC,IAAI,CAAC,MAAM;QAAE,OAAO,IAAI,CAAC;IACzB,MAAM,SAAS,GAAG,MAAM,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,aAAa,EAAE,GAAG,CAAC,CAAC;IACnE,gFAAgF;IAChF,oCAAoC;IACpC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC;QAAE,OAAO,IAAI,CAAC;IAC9C,OAAO,SAAS,CAAC;AACnB,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,kBAAkB,CAChC,UAAkB,EAClB,KAAgC;IAEhC,MAAM,SAAS,GAAG,qBAAqB,CAAC,KAAK,CAAC,CAAC;IAC/C,IAAI,CAAC,SAAS;QAAE,OAAO,KAAK,CAAC;IAC7B,OAAO,UAAU,CAAC,UAAU,CAAC,GAAG,SAAS,GAAG,CAAC,CAAC;AAChD,CAAC"}
@@ -0,0 +1,264 @@
1
+ export type PullRequestState = 'open' | 'merged' | 'closed';
2
+ export interface PullRequestAuthor {
3
+ login: string;
4
+ name?: string;
5
+ }
6
+ export interface PullRequestReviewStatus {
7
+ approvals: number;
8
+ changesRequested: number;
9
+ /** GitHub logins of reviewers with a pending request (no review yet). */
10
+ pendingLogins: string[];
11
+ }
12
+ export interface PullRequestSummary {
13
+ number: number;
14
+ title: string;
15
+ author: PullRequestAuthor;
16
+ /**
17
+ * Opaque SHA-256 hash of the authoring user's email. Embedded in the PR body via a hidden
18
+ * marker so `/pr/mine` can filter by identity without leaking raw emails into bodies. Absent
19
+ * on PRs not created through this backend. `author.login` is always the GitHub account that
20
+ * actually opened the PR (typically our service account). Compare by re-hashing the caller's
21
+ * email; there is no reverse lookup.
22
+ */
23
+ authorId?: string;
24
+ /**
25
+ * The app user (not the GitHub account) who triggered this PR. Resolved server-side by
26
+ * matching `authorId` against the hash of every app user's email. Use this in user-facing
27
+ * surfaces — `author.login` is always the shared service account.
28
+ *
29
+ * Display name only — no email. Other authenticated workspace members don't need raw
30
+ * emails to render PR attribution. The hash in `authorId` is the stable identity if
31
+ * downstream code needs to compare against the current user.
32
+ *
33
+ * Absent when no app user matches the hash (e.g. PRs opened outside this backend, or after
34
+ * an app user was removed from the users table).
35
+ */
36
+ appAuthor?: {
37
+ name: string;
38
+ };
39
+ branch: string;
40
+ base: string;
41
+ state: PullRequestState;
42
+ createdAt: string;
43
+ /** Relative paths within `knowledge-base/`. Empty if not yet computed. */
44
+ touchedNodePaths: string[];
45
+ review: PullRequestReviewStatus;
46
+ url: string;
47
+ }
48
+ export type PrFileStatus = 'added' | 'modified' | 'removed' | 'renamed' | 'copied' | 'changed' | 'unchanged';
49
+ /**
50
+ * A single file in a PR. Patch is GitHub's unified-diff text; it's absent for
51
+ * binary files and for files larger than the API cutoff (~3 MB). `previousPath`
52
+ * is populated for renames/copies.
53
+ */
54
+ export interface PullRequestFile {
55
+ path: string;
56
+ previousPath?: string;
57
+ status: PrFileStatus;
58
+ additions: number;
59
+ deletions: number;
60
+ patch?: string;
61
+ isBinary: boolean;
62
+ /** Blob SHA at the PR head — stable identifier for caching raw content. */
63
+ sha: string;
64
+ /** Authenticated `raw.githubusercontent.com`-style URL for the blob at head. */
65
+ rawUrl: string;
66
+ }
67
+ /**
68
+ * One comment in the Bevel-owned PR discussion. GitHub never sees these —
69
+ * they live only in our DB, attributed to the authenticated user. Shape
70
+ * encodes three comment kinds:
71
+ *
72
+ * General → path undefined, line undefined
73
+ * File-level → path set, line undefined
74
+ * Inline (line) → path set, line set
75
+ *
76
+ * Threading: `parentId` points at the root of the thread; top-level comments
77
+ * have it undefined.
78
+ */
79
+ export interface PrReviewComment {
80
+ id: string;
81
+ author: {
82
+ email: string;
83
+ name: string;
84
+ };
85
+ body: string;
86
+ path?: string;
87
+ line?: number;
88
+ /** The head SHA the comment was authored against — lets the UI grey out stale inline pins. */
89
+ headSha: string;
90
+ parentId?: string;
91
+ createdAt: string;
92
+ updatedAt?: string;
93
+ }
94
+ export interface PostPrCommentInput {
95
+ body: string;
96
+ path?: string;
97
+ line?: number;
98
+ parentId?: string;
99
+ }
100
+ /**
101
+ * One owner's approval on one file. Stored straight from the
102
+ * `pr_file_approvals` row, with derived flags the UI needs.
103
+ */
104
+ export interface FileApprovalEntry {
105
+ email: string;
106
+ name: string;
107
+ approvedAt: string;
108
+ /** True when this approval was captured against a SHA that is no longer the PR head. */
109
+ isStale: boolean;
110
+ /** True when the approver is the PR author (hash-matched against the PR body marker). */
111
+ isSelfApproval: boolean;
112
+ }
113
+ /**
114
+ * Per-file approval state the PR viewer needs to render the approval badge,
115
+ * the Approve button, and the merge gate.
116
+ *
117
+ * `eligibleApprovers` lists everyone who could approve this file at the PR
118
+ * head SHA, derived from the access tree (`roles.yaml` + `access.md`). A
119
+ * file is approved when any non-author user holding one of those roles (or
120
+ * directly named) submits a non-stale approval. The built-in role `everyone`
121
+ * means any signed-in approver is eligible.
122
+ */
123
+ export interface FileApprovalState {
124
+ path: string;
125
+ /**
126
+ * Roles + direct user grants that confer write access on this file as of
127
+ * the PR head. `roles` may include the built-in role `everyone`. Empty roles
128
+ * + empty users means the file is outside the access-controlled surface (no
129
+ * rule grants write); the merge gate silently excludes such entries instead
130
+ * of blocking on them.
131
+ */
132
+ eligibleApprovers: {
133
+ roles: string[];
134
+ users: {
135
+ name: string;
136
+ email: string;
137
+ }[];
138
+ };
139
+ approvedBy: FileApprovalEntry[];
140
+ /**
141
+ * True iff at least one eligible approver has submitted a non-stale
142
+ * approval. Always `false` when `eligibleApprovers` is empty — with no
143
+ * eligible set, nobody can satisfy the check.
144
+ * Whether the gate *cares* about this file is a separate concern handled
145
+ * by the merge-gate logic: non-md files and files with no eligible
146
+ * approvers are silently excluded from the gate, so `isApproved: false`
147
+ * on one of them does not block merge.
148
+ */
149
+ isApproved: boolean;
150
+ /**
151
+ * Pre-computed for the requesting viewer: would `approveFile` accept their
152
+ * click? True iff their email resolves to `write` on this path under the
153
+ * access tree at `origin/<baseBranch>`. The frontend uses this to gate the
154
+ * Approve button — without it, the button shows for any user whenever the
155
+ * eligible-roles list is non-empty, which is misleading because most users
156
+ * aren't actually in those roles. Backend remains authoritative; this is a
157
+ * UX hint, not a security boundary.
158
+ */
159
+ viewerCanApprove: boolean;
160
+ }
161
+ /**
162
+ * Full read-only PR detail for the in-app viewer. Extends the summary with
163
+ * body, SHAs, file list, and the Bevel-owned comments. Later phases add
164
+ * `approvals` and merge-gate fields — this shape grows incrementally.
165
+ */
166
+ export interface PullRequestDetail extends PullRequestSummary {
167
+ body: string;
168
+ headSha: string;
169
+ baseSha: string;
170
+ files: PullRequestFile[];
171
+ comments: PrReviewComment[];
172
+ /**
173
+ * One entry per file in `files`, same order. Empty when the caller had no
174
+ * resolvable workspace to do the owner lookup against.
175
+ */
176
+ approvals: FileApprovalState[];
177
+ /**
178
+ * True iff no *hard* block applies — the PR is open, has files, and isn't
179
+ * merged/closed. Soft warnings (missing owner approvals on md files) do
180
+ * **not** set this to false; the UI handles them via the bypass dialog.
181
+ * The button is disabled only when this is false.
182
+ */
183
+ mergeableInBevel: boolean;
184
+ /**
185
+ * Hard-block reasons — merging is impossible until these resolve (PR state,
186
+ * no files, etc.). Empty when the PR can be merged (possibly after bypass).
187
+ */
188
+ mergeBlockedReasons: string[];
189
+ /**
190
+ * Soft warnings — md files with an owner who hasn't approved (or whose
191
+ * approval is stale). Merging is allowed but the UI asks for an explicit
192
+ * bypass confirmation first. Non-md files and ownerless md files are silent.
193
+ */
194
+ mergeWarnings: string[];
195
+ /**
196
+ * True iff the viewer holds write on `roles.yaml` at `origin/<base>` —
197
+ * i.e. they're in the Admin role on the canonical access tree. The
198
+ * frontend uses this to hide / disable the bypass action for non-admins;
199
+ * the backend enforces the same check on the merge route. False when no
200
+ * viewer was passed (anonymous detail fetch) or when the access tree on
201
+ * base can't be resolved.
202
+ */
203
+ viewerCanBypassMerge: boolean;
204
+ /**
205
+ * True iff the viewer is allowed to cancel this change request: the PR is
206
+ * open AND the viewer is either its author (hash-matched against the body
207
+ * marker) or an admin (write on `roles.yaml` at `origin/<base>` — same
208
+ * predicate `viewerCanBypassMerge` uses). The frontend renders the Cancel
209
+ * button as disabled when this is false; the backend re-checks server-side
210
+ * on `POST /pr/:n/cancel`, so this is a UX hint, not a security boundary.
211
+ * False when no viewer was passed, the state isn't `open`, or the access
212
+ * tree can't be resolved.
213
+ */
214
+ viewerCanCancel: boolean;
215
+ }
216
+ /**
217
+ * Result of a successful merge via the in-app gate. `sha` is the merge commit
218
+ * GitHub produced; the UI uses it to link to the resulting commit and to
219
+ * invalidate any stale views.
220
+ */
221
+ export interface MergePrResult {
222
+ prNumber: number;
223
+ sha: string;
224
+ mergedAt: string;
225
+ }
226
+ /**
227
+ * Result of a successful cancel via `POST /pr/:n/cancel`. No SHA — closing a
228
+ * PR without merging produces no merge commit. `cancelledAt` is the
229
+ * server-side timestamp the close was recorded; useful for audit display.
230
+ */
231
+ export interface CancelPrResult {
232
+ prNumber: number;
233
+ cancelledAt: string;
234
+ }
235
+ export interface IPullRequestService {
236
+ /**
237
+ * `opts.fresh` bypasses the internal 30s list cache — used when the UI has
238
+ * a reason to believe the server-side state just changed (agent-opened PR
239
+ * via `gh pr create`) and the user expects to see the update immediately.
240
+ */
241
+ listOpenPrs(opts?: {
242
+ fresh?: boolean;
243
+ }): Promise<PullRequestSummary[]>;
244
+ listPrsAuthoredBy(githubLoginOrEmail: string): Promise<PullRequestSummary[]>;
245
+ /**
246
+ * PRs whose touched paths have an owner with the given email.
247
+ * Resolution uses the given workspace's KB — caller passes their own workspaceId.
248
+ */
249
+ listPrsForOwnerEmail(workspaceId: string, email: string, opts?: {
250
+ fresh?: boolean;
251
+ }): Promise<PullRequestSummary[]>;
252
+ getPr(prNumber: number): Promise<PullRequestSummary | null>;
253
+ /**
254
+ * Full detail for the in-app PR viewer. `opts.fresh` bypasses the detail cache
255
+ * — use for event-driven refreshes (post-merge, share-dialog create).
256
+ * `opts.viewerEmail` pre-computes `viewerCanApprove` per file.
257
+ */
258
+ getPrDetail(prNumber: number, opts?: {
259
+ fresh?: boolean;
260
+ workspaceId?: string;
261
+ viewerEmail?: string;
262
+ }): Promise<PullRequestDetail | null>;
263
+ }
264
+ //# sourceMappingURL=pr.types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pr.types.d.ts","sourceRoot":"","sources":["../../src/git/pr.types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,gBAAgB,GAAG,MAAM,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAE5D,M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