@critical-path/core 0.36.0 → 0.36.1

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 (185) hide show
  1. package/package.json +5 -1
  2. package/CHANGELOG.md +0 -593
  3. package/dist/deliverables.test.d.ts +0 -2
  4. package/dist/deliverables.test.d.ts.map +0 -1
  5. package/dist/deliverables.test.js +0 -232
  6. package/dist/deliverables.test.js.map +0 -1
  7. package/dist/domain/calendar.test.d.ts +0 -2
  8. package/dist/domain/calendar.test.d.ts.map +0 -1
  9. package/dist/domain/calendar.test.js +0 -181
  10. package/dist/domain/calendar.test.js.map +0 -1
  11. package/dist/domain/cpm.test.d.ts +0 -2
  12. package/dist/domain/cpm.test.d.ts.map +0 -1
  13. package/dist/domain/cpm.test.js +0 -166
  14. package/dist/domain/cpm.test.js.map +0 -1
  15. package/dist/domain/ddd.test.d.ts +0 -2
  16. package/dist/domain/ddd.test.d.ts.map +0 -1
  17. package/dist/domain/ddd.test.js +0 -349
  18. package/dist/domain/ddd.test.js.map +0 -1
  19. package/dist/domain/ladder.test.d.ts +0 -2
  20. package/dist/domain/ladder.test.d.ts.map +0 -1
  21. package/dist/domain/ladder.test.js +0 -213
  22. package/dist/domain/ladder.test.js.map +0 -1
  23. package/dist/domain/metrics.test.d.ts +0 -2
  24. package/dist/domain/metrics.test.d.ts.map +0 -1
  25. package/dist/domain/metrics.test.js +0 -252
  26. package/dist/domain/metrics.test.js.map +0 -1
  27. package/dist/domain/task-duration.test.d.ts +0 -2
  28. package/dist/domain/task-duration.test.d.ts.map +0 -1
  29. package/dist/domain/task-duration.test.js +0 -307
  30. package/dist/domain/task-duration.test.js.map +0 -1
  31. package/dist/domain/workload.test.d.ts +0 -2
  32. package/dist/domain/workload.test.d.ts.map +0 -1
  33. package/dist/domain/workload.test.js +0 -261
  34. package/dist/domain/workload.test.js.map +0 -1
  35. package/dist/engine/actor.test.d.ts +0 -2
  36. package/dist/engine/actor.test.d.ts.map +0 -1
  37. package/dist/engine/actor.test.js +0 -54
  38. package/dist/engine/actor.test.js.map +0 -1
  39. package/dist/engine/authorization.test.d.ts +0 -2
  40. package/dist/engine/authorization.test.d.ts.map +0 -1
  41. package/dist/engine/authorization.test.js +0 -154
  42. package/dist/engine/authorization.test.js.map +0 -1
  43. package/dist/engine/cascade.test.d.ts +0 -2
  44. package/dist/engine/cascade.test.d.ts.map +0 -1
  45. package/dist/engine/cascade.test.js +0 -99
  46. package/dist/engine/cascade.test.js.map +0 -1
  47. package/dist/engine/config.test.d.ts +0 -2
  48. package/dist/engine/config.test.d.ts.map +0 -1
  49. package/dist/engine/config.test.js +0 -46
  50. package/dist/engine/config.test.js.map +0 -1
  51. package/dist/engine/entity-events.test.d.ts +0 -2
  52. package/dist/engine/entity-events.test.d.ts.map +0 -1
  53. package/dist/engine/entity-events.test.js +0 -61
  54. package/dist/engine/entity-events.test.js.map +0 -1
  55. package/dist/index.test.d.ts +0 -2
  56. package/dist/index.test.d.ts.map +0 -1
  57. package/dist/index.test.js +0 -429
  58. package/dist/index.test.js.map +0 -1
  59. package/dist/plugins/plugins.test.d.ts +0 -2
  60. package/dist/plugins/plugins.test.d.ts.map +0 -1
  61. package/dist/plugins/plugins.test.js +0 -137
  62. package/dist/plugins/plugins.test.js.map +0 -1
  63. package/dist/schemas/schemas.test.d.ts +0 -2
  64. package/dist/schemas/schemas.test.d.ts.map +0 -1
  65. package/dist/schemas/schemas.test.js +0 -58
  66. package/dist/schemas/schemas.test.js.map +0 -1
  67. package/dist/status.test.d.ts +0 -2
  68. package/dist/status.test.d.ts.map +0 -1
  69. package/dist/status.test.js +0 -295
  70. package/dist/status.test.js.map +0 -1
  71. package/dist/storage/storage.test.d.ts +0 -2
  72. package/dist/storage/storage.test.d.ts.map +0 -1
  73. package/dist/storage/storage.test.js +0 -236
  74. package/dist/storage/storage.test.js.map +0 -1
  75. package/dist/storage/upload-limits.test.d.ts +0 -2
  76. package/dist/storage/upload-limits.test.d.ts.map +0 -1
  77. package/dist/storage/upload-limits.test.js +0 -31
  78. package/dist/storage/upload-limits.test.js.map +0 -1
  79. package/dist/store/conformance.test.d.ts +0 -2
  80. package/dist/store/conformance.test.d.ts.map +0 -1
  81. package/dist/store/conformance.test.js +0 -15
  82. package/dist/store/conformance.test.js.map +0 -1
  83. package/dist/store/firebase.test.d.ts +0 -2
  84. package/dist/store/firebase.test.d.ts.map +0 -1
  85. package/dist/store/firebase.test.js +0 -103
  86. package/dist/store/firebase.test.js.map +0 -1
  87. package/dist/store/query.test.d.ts +0 -2
  88. package/dist/store/query.test.d.ts.map +0 -1
  89. package/dist/store/query.test.js +0 -89
  90. package/dist/store/query.test.js.map +0 -1
  91. package/dist/store/sqlite.test.d.ts +0 -2
  92. package/dist/store/sqlite.test.d.ts.map +0 -1
  93. package/dist/store/sqlite.test.js +0 -177
  94. package/dist/store/sqlite.test.js.map +0 -1
  95. package/dist/task-state.test.d.ts +0 -2
  96. package/dist/task-state.test.d.ts.map +0 -1
  97. package/dist/task-state.test.js +0 -423
  98. package/dist/task-state.test.js.map +0 -1
  99. package/dist/use-case-validation.test.d.ts +0 -2
  100. package/dist/use-case-validation.test.d.ts.map +0 -1
  101. package/dist/use-case-validation.test.js +0 -281
  102. package/dist/use-case-validation.test.js.map +0 -1
  103. package/dist/utils/fractional-index.test.d.ts +0 -2
  104. package/dist/utils/fractional-index.test.d.ts.map +0 -1
  105. package/dist/utils/fractional-index.test.js +0 -182
  106. package/dist/utils/fractional-index.test.js.map +0 -1
  107. package/dist/utils/key.test.d.ts +0 -2
  108. package/dist/utils/key.test.d.ts.map +0 -1
  109. package/dist/utils/key.test.js +0 -65
  110. package/dist/utils/key.test.js.map +0 -1
  111. package/dist/utils/mentions.test.d.ts +0 -2
  112. package/dist/utils/mentions.test.d.ts.map +0 -1
  113. package/dist/utils/mentions.test.js +0 -114
  114. package/dist/utils/mentions.test.js.map +0 -1
  115. package/dist/webhooks/webhooks.test.d.ts +0 -2
  116. package/dist/webhooks/webhooks.test.d.ts.map +0 -1
  117. package/dist/webhooks/webhooks.test.js +0 -154
  118. package/dist/webhooks/webhooks.test.js.map +0 -1
  119. package/src/deliverables.test.ts +0 -284
  120. package/src/domain/authorization.ts +0 -82
  121. package/src/domain/calendar.test.ts +0 -216
  122. package/src/domain/calendar.ts +0 -502
  123. package/src/domain/cpm.test.ts +0 -189
  124. package/src/domain/cpm.ts +0 -258
  125. package/src/domain/custom-fields.ts +0 -172
  126. package/src/domain/ddd.test.ts +0 -442
  127. package/src/domain/entities.ts +0 -798
  128. package/src/domain/errors.ts +0 -38
  129. package/src/domain/events.ts +0 -369
  130. package/src/domain/graph.ts +0 -70
  131. package/src/domain/index.ts +0 -12
  132. package/src/domain/ladder.test.ts +0 -251
  133. package/src/domain/ladder.ts +0 -474
  134. package/src/domain/metrics.test.ts +0 -288
  135. package/src/domain/metrics.ts +0 -497
  136. package/src/domain/task-duration.test.ts +0 -354
  137. package/src/domain/workload.test.ts +0 -311
  138. package/src/domain/workload.ts +0 -457
  139. package/src/engine/actor.test.ts +0 -63
  140. package/src/engine/authorization.test.ts +0 -199
  141. package/src/engine/cascade.test.ts +0 -121
  142. package/src/engine/config.test.ts +0 -51
  143. package/src/engine/entity-events.test.ts +0 -67
  144. package/src/engine/index.ts +0 -2495
  145. package/src/index.test.ts +0 -514
  146. package/src/index.ts +0 -9
  147. package/src/plugins/index.ts +0 -103
  148. package/src/plugins/plugins.test.ts +0 -161
  149. package/src/schemas/index.ts +0 -402
  150. package/src/schemas/schemas.test.ts +0 -116
  151. package/src/status.test.ts +0 -354
  152. package/src/storage/file-storage.ts +0 -200
  153. package/src/storage/firebase-storage.ts +0 -209
  154. package/src/storage/index.ts +0 -3
  155. package/src/storage/s3.ts +0 -151
  156. package/src/storage/storage.test.ts +0 -274
  157. package/src/storage/upload-limits.test.ts +0 -41
  158. package/src/store/conformance.test.ts +0 -15
  159. package/src/store/firebase.test.ts +0 -131
  160. package/src/store/firebase.ts +0 -658
  161. package/src/store/index.ts +0 -623
  162. package/src/store/query.test.ts +0 -110
  163. package/src/store/query.ts +0 -113
  164. package/src/store/sqlite.test.ts +0 -218
  165. package/src/store/sqlite.ts +0 -1480
  166. package/src/task-state.test.ts +0 -506
  167. package/src/testing/conformance.ts +0 -319
  168. package/src/testing/index.ts +0 -1
  169. package/src/types/index.ts +0 -871
  170. package/src/use-case-validation.test.ts +0 -324
  171. package/src/utils/fractional-index.test.ts +0 -228
  172. package/src/utils/fractional-index.ts +0 -254
  173. package/src/utils/index.ts +0 -7
  174. package/src/utils/key.test.ts +0 -76
  175. package/src/utils/key.ts +0 -62
  176. package/src/utils/mentions.test.ts +0 -132
  177. package/src/utils/mentions.ts +0 -131
  178. package/src/utils/status.ts +0 -419
  179. package/src/utils/workflow.ts +0 -306
  180. package/src/webhooks/dispatcher.ts +0 -190
  181. package/src/webhooks/index.ts +0 -2
  182. package/src/webhooks/signature.ts +0 -57
  183. package/src/webhooks/webhooks.test.ts +0 -201
  184. package/tsconfig.json +0 -8
  185. package/tsconfig.tsbuildinfo +0 -1
@@ -1,254 +0,0 @@
1
- /**
2
- * Fractional Lexical Indexing Utility
3
- *
4
- * Deterministic Base-62 fractional indexing for ordered lists and swimlane task sequences.
5
- * Produces lexicographically sortable strings (`orderIndex`) that allow infinite insertion
6
- * between any two items without floating-point precision loss.
7
- */
8
-
9
- export const BASE_62 = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
10
-
11
- /**
12
- * Encodes a non-negative integer into Base-62.
13
- */
14
- function toBase62(n: number): string {
15
- if (n === 0) return '0';
16
- let s = '';
17
- let curr = n;
18
- while (curr > 0) {
19
- s = BASE_62[curr % 62] + s;
20
- curr = Math.floor(curr / 62);
21
- }
22
- return s;
23
- }
24
-
25
- /**
26
- * Decodes a Base-62 string into a non-negative integer.
27
- */
28
- function fromBase62(s: string): number {
29
- let n = 0;
30
- for (let i = 0; i < s.length; i++) {
31
- const idx = BASE_62.indexOf(s[i]);
32
- if (idx === -1) return 0;
33
- n = n * 62 + idx;
34
- }
35
- return n;
36
- }
37
-
38
- /**
39
- * Encodes an integer into a prefix-encoded string such that standard
40
- * string comparison strictly matches integer comparison.
41
- *
42
- * Non-negative integers (0, 1, 2, ...):
43
- * Prefix 'a'-'z' specifies the digit count (1 to 26 digits).
44
- * 0 -> "a0", 1 -> "a1", 61 -> "az", 62 -> "b10", ...
45
- *
46
- * Negative integers (-1, -2, ...):
47
- * Prefix 'Z'-'A' specifies inverted digit count with inverted digits.
48
- * -1 -> "Zz", -2 -> "Zy", ...
49
- */
50
- export function encodeInteger(n: number): string {
51
- if (n >= 0) {
52
- const digits = toBase62(n);
53
- const prefixCode = 97 + digits.length - 1; // 97 is 'a'
54
- const prefix = String.fromCharCode(Math.min(prefixCode, 122)); // clamp to 'z'
55
- return prefix + digits;
56
- } else {
57
- const pos = -n - 1;
58
- const digits = toBase62(pos);
59
- let inverted = '';
60
- for (let i = 0; i < digits.length; i++) {
61
- const idx = BASE_62.indexOf(digits[i]);
62
- inverted += BASE_62[61 - idx];
63
- }
64
- const prefixCode = 90 - (digits.length - 1); // 90 is 'Z'
65
- const prefix = String.fromCharCode(Math.max(prefixCode, 65)); // clamp to 'A'
66
- return prefix + inverted;
67
- }
68
- }
69
-
70
- /**
71
- * Decodes a prefix-encoded integer string back into a number.
72
- */
73
- export function decodeInteger(s: string): number {
74
- if (!s || s.length < 2) return 0;
75
- const prefix = s[0];
76
- if (prefix >= 'a' && prefix <= 'z') {
77
- const len = prefix.charCodeAt(0) - 97 + 1;
78
- const digits = s.slice(1, 1 + len);
79
- return fromBase62(digits);
80
- } else if (prefix >= 'A' && prefix <= 'Z') {
81
- const len = 90 - prefix.charCodeAt(0) + 1;
82
- const inverted = s.slice(1, 1 + len);
83
- let digits = '';
84
- for (let i = 0; i < inverted.length; i++) {
85
- const idx = BASE_62.indexOf(inverted[i]);
86
- digits += idx !== -1 ? BASE_62[61 - idx] : '0';
87
- }
88
- const pos = fromBase62(digits);
89
- return -pos - 1;
90
- }
91
- return 0;
92
- }
93
-
94
- /**
95
- * Extracts the integer component from an order key.
96
- */
97
- export function getIntegerPart(key: string): string {
98
- if (!key || key.length < 2) return 'a0';
99
- const prefix = key[0];
100
- if (prefix >= 'a' && prefix <= 'z') {
101
- const len = prefix.charCodeAt(0) - 97 + 1;
102
- return key.slice(0, Math.min(key.length, 1 + len));
103
- } else if (prefix >= 'A' && prefix <= 'Z') {
104
- const len = 90 - prefix.charCodeAt(0) + 1;
105
- return key.slice(0, Math.min(key.length, 1 + len));
106
- }
107
- return 'a0';
108
- }
109
-
110
- /**
111
- * Computes a fractional suffix strictly between suffixes `a` and `b` (a < result < b).
112
- * Missing digits in `a` are treated as '0', so `a` may be shorter than `b`.
113
- * `b === null` means there is no upper bound.
114
- */
115
- function midpointSuffix(a: string, b: string | null): string {
116
- if (b !== null) {
117
- let n = 0;
118
- while (n < b.length && (a[n] ?? '0') === b[n]) {
119
- n++;
120
- }
121
- if (n > 0) {
122
- return b.slice(0, n) + midpointSuffix(a.slice(n), b.slice(n));
123
- }
124
- }
125
-
126
- const digitA = a.length > 0 ? BASE_62.indexOf(a[0]) : 0;
127
- const digitB = b !== null ? BASE_62.indexOf(b[0]) : BASE_62.length;
128
-
129
- if (digitB - digitA > 1) {
130
- return BASE_62[Math.floor((digitA + digitB) / 2)];
131
- }
132
-
133
- // Adjacent digits: if b has more digits, its first digit alone already sits between a and b.
134
- if (b !== null && b.length > 1) {
135
- return b[0];
136
- }
137
-
138
- // Otherwise keep a's digit and subdivide the remainder with no upper bound.
139
- return BASE_62[digitA] + midpointSuffix(a.slice(1), null);
140
- }
141
-
142
- /**
143
- * Generates a default initial order key for an index with optional spacing.
144
- * E.g. index 0 -> "a0", index 1 (spacing 2) -> "a2", index 2 -> "a4"
145
- */
146
- export function getInitialKey(index: number, spacing: number = 2): string {
147
- return encodeInteger(Math.max(0, index) * Math.max(1, spacing));
148
- }
149
-
150
- /**
151
- * Generates a single key strictly between keys `a` and `b` (a < key < b).
152
- * Handles null/undefined for lower and upper bounds.
153
- */
154
- export function generateKeyBetween(
155
- a: string | null | undefined,
156
- b: string | null | undefined
157
- ): string {
158
- const hasA = a !== null && a !== undefined && a !== '';
159
- const hasB = b !== null && b !== undefined && b !== '';
160
-
161
- if (!hasA && !hasB) {
162
- return 'a0';
163
- }
164
-
165
- if (!hasA && hasB) {
166
- const intB = getIntegerPart(b!);
167
- if (intB === b) {
168
- const valB = decodeInteger(intB);
169
- return encodeInteger(valB - 1);
170
- }
171
- // If b has fractional suffix (e.g. "a0V"), integer part is already strictly smaller than b
172
- return intB;
173
- }
174
-
175
- if (hasA && !hasB) {
176
- const intA = getIntegerPart(a!);
177
- const valA = decodeInteger(intA);
178
- return encodeInteger(valA + 1);
179
- }
180
-
181
- // Both a and b are present
182
- if (a! >= b!) {
183
- throw new RangeError(`generateKeyBetween: lower bound "${a}" must sort before upper bound "${b}"`);
184
- }
185
-
186
- const intA = getIntegerPart(a!);
187
- const intB = getIntegerPart(b!);
188
-
189
- if (intA !== intB) {
190
- const valA = decodeInteger(intA);
191
- const valB = decodeInteger(intB);
192
-
193
- if (valB - valA > 1) {
194
- const midVal = Math.floor((valA + valB) / 2);
195
- return encodeInteger(midVal);
196
- }
197
-
198
- if (valB - valA === 1) {
199
- const suffixA = a!.slice(intA.length);
200
- return intA + midpointSuffix(suffixA, null);
201
- }
202
- }
203
-
204
- // Same integer part or fractional subdivision
205
- const suffixA = a!.slice(intA.length);
206
- const suffixB = b!.slice(intB.length);
207
- return intA + midpointSuffix(suffixA, suffixB);
208
- }
209
-
210
- /**
211
- * Generates `count` keys in strictly ascending order between keys `a` and `b`.
212
- * Uses a balanced divide-and-conquer partition to guarantee even spacing.
213
- */
214
- export function generateNKeysBetween(
215
- a: string | null | undefined,
216
- b: string | null | undefined,
217
- count: number
218
- ): string[] {
219
- if (count <= 0) return [];
220
- if (count === 1) return [generateKeyBetween(a, b)];
221
-
222
- const result: string[] = new Array(count);
223
-
224
- function fill(
225
- leftKey: string | null | undefined,
226
- rightKey: string | null | undefined,
227
- startIdx: number,
228
- endIdx: number
229
- ) {
230
- if (startIdx > endIdx) return;
231
- const midIdx = Math.floor((startIdx + endIdx) / 2);
232
- const midKey = generateKeyBetween(leftKey, rightKey);
233
- result[midIdx] = midKey;
234
- fill(leftKey, midKey, startIdx, midIdx - 1);
235
- fill(midKey, rightKey, midIdx + 1, endIdx);
236
- }
237
-
238
- fill(a, b, 0, count - 1);
239
- return result;
240
- }
241
-
242
- /**
243
- * Standard comparator for fractional order indices.
244
- * Uses strict code-point comparison matching Firestore, SQLite, and JavaScript array.sort().
245
- */
246
- export function compareOrderIndices(
247
- a: string | null | undefined,
248
- b: string | null | undefined
249
- ): number {
250
- if (!a && !b) return 0;
251
- if (!a) return 1;
252
- if (!b) return -1;
253
- return a < b ? -1 : a > b ? 1 : 0;
254
- }
@@ -1,7 +0,0 @@
1
- export * from './status.js';
2
- export * from './key.js';
3
- export * from './workflow.js';
4
- export * from './mentions.js';
5
- export * from './fractional-index.js';
6
-
7
-
@@ -1,76 +0,0 @@
1
- import { describe, it, expect } from 'vitest';
2
- import { generateProjectKey, validateProjectKey, formatTaskKey, isTempTaskId } from './key.js';
3
-
4
- describe('Project Key Utilities', () => {
5
- describe('generateProjectKey', () => {
6
- it('generates a key for a single word name', () => {
7
- expect(generateProjectKey('Operative')).toBe('OPE');
8
- expect(generateProjectKey('App')).toBe('APP');
9
- expect(generateProjectKey('Go')).toBe('GO');
10
- });
11
-
12
- it('generates a key for multi-word names', () => {
13
- expect(generateProjectKey('Mobile App')).toBe('MA');
14
- expect(generateProjectKey('Frontend Core Platform')).toBe('FCP');
15
- expect(generateProjectKey('Very Long Project Name Here')).toBe('VLPN');
16
- });
17
-
18
- it('handles special characters and whitespace', () => {
19
- expect(generateProjectKey(' v2.0 ')).toBe('V20');
20
- expect(generateProjectKey('Project #1')).toBe('P1');
21
- });
22
-
23
- it('returns default PRJ fallback for empty input', () => {
24
- expect(generateProjectKey('')).toBe('PRJ');
25
- expect(generateProjectKey(' ')).toBe('PRJ');
26
- });
27
- });
28
-
29
- describe('validateProjectKey', () => {
30
- it('returns true for valid keys', () => {
31
- expect(validateProjectKey('CP')).toBe(true);
32
- expect(validateProjectKey('PROJ')).toBe(true);
33
- expect(validateProjectKey('APP123')).toBe(true);
34
- });
35
-
36
- it('returns false for invalid keys', () => {
37
- expect(validateProjectKey('A')).toBe(false); // too short
38
- expect(validateProjectKey('TOOLONGKEY')).toBe(false); // too long
39
- expect(validateProjectKey('proj')).toBe(false); // lowercase
40
- expect(validateProjectKey('P-1')).toBe(false); // special char
41
- expect(validateProjectKey('')).toBe(false);
42
- });
43
- });
44
-
45
- describe('formatTaskKey', () => {
46
- it('formats project key and task number', () => {
47
- expect(formatTaskKey('MOB', 42)).toBe('MOB-42');
48
- expect(formatTaskKey('op', 1)).toBe('OP-1');
49
- });
50
-
51
- it('uses fallback for missing project key', () => {
52
- expect(formatTaskKey('', 10)).toBe('TASK-10');
53
- });
54
- });
55
-
56
- describe('isTempTaskId', () => {
57
- it('detects temp_ prefixed IDs', () => {
58
- expect(isTempTaskId('temp_123456_abc')).toBe(true);
59
- expect(isTempTaskId('#temp_123456_abc')).toBe(true);
60
- });
61
-
62
- it('detects temp- prefixed IDs', () => {
63
- expect(isTempTaskId('temp-task-1')).toBe(true);
64
- expect(isTempTaskId('#temp-task-1')).toBe(true);
65
- });
66
-
67
- it('returns false for permanent or invalid IDs', () => {
68
- expect(isTempTaskId('task_123')).toBe(false);
69
- expect(isTempTaskId('PROJ-1')).toBe(false);
70
- expect(isTempTaskId(null)).toBe(false);
71
- expect(isTempTaskId(undefined)).toBe(false);
72
- expect(isTempTaskId('')).toBe(false);
73
- });
74
- });
75
- });
76
-
package/src/utils/key.ts DELETED
@@ -1,62 +0,0 @@
1
- /**
2
- * Generates a 2-6 character uppercase project short code/key from a project name.
3
- * e.g., "Mobile App" -> "MA", "Frontend Core" -> "FC", "Operative" -> "OPE".
4
- */
5
- export function generateProjectKey(name: string): string {
6
- if (!name || !name.trim()) {
7
- return 'PRJ';
8
- }
9
-
10
- const words = name.trim().split(/\s+/).filter(Boolean);
11
- let rawKey = '';
12
-
13
- if (words.length === 1) {
14
- const word = words[0].replace(/[^a-zA-Z0-9]/g, '');
15
- if (word.length <= 3) {
16
- rawKey = word.toUpperCase();
17
- } else {
18
- rawKey = word.substring(0, 3).toUpperCase();
19
- }
20
- } else {
21
- rawKey = words
22
- .map((w) => w.replace(/[^a-zA-Z0-9]/g, '')[0] || '')
23
- .join('')
24
- .substring(0, 4)
25
- .toUpperCase();
26
- }
27
-
28
- // Ensure key meets basic 2-6 char alphanumeric requirement
29
- const cleanKey = rawKey.replace(/[^A-Z0-9]/g, '');
30
- if (cleanKey.length >= 2 && cleanKey.length <= 6) {
31
- return cleanKey;
32
- }
33
-
34
- return 'PRJ';
35
- }
36
-
37
- /**
38
- * Validates whether a given key meets project key format rules (2-6 uppercase alphanumeric characters).
39
- */
40
- export function validateProjectKey(key: string): boolean {
41
- if (!key) return false;
42
- return /^[A-Z0-9]{2,6}$/.test(key);
43
- }
44
-
45
- /**
46
- * Formats a task key using a project key and task index (e.g. "MOB-12").
47
- */
48
- export function formatTaskKey(projectKey: string, taskNumber: number): string {
49
- const prefix = projectKey ? projectKey.toUpperCase() : 'TASK';
50
- return `${prefix}-${taskNumber}`;
51
- }
52
-
53
- /**
54
- * Checks whether a given task ID represents a temporary/optimistic task
55
- * (e.g. temp_1790... or temp-task-...) while it is actively being created.
56
- */
57
- export function isTempTaskId(id?: string | null): boolean {
58
- if (!id || typeof id !== 'string') return false;
59
- const clean = id.trim().replace(/^#/, '');
60
- return clean.startsWith('temp_') || clean.startsWith('temp-');
61
- }
62
-
@@ -1,132 +0,0 @@
1
- import { describe, it, expect } from 'vitest';
2
- import { extractMentions, parseMentionSegments, stripMarkdownCode } from './mentions.js';
3
-
4
- describe('mentions utility', () => {
5
- describe('extractMentions', () => {
6
- it('returns empty array for empty or non-string input', () => {
7
- expect(extractMentions('')).toEqual([]);
8
- expect(extractMentions(null as any)).toEqual([]);
9
- expect(extractMentions(undefined as any)).toEqual([]);
10
- });
11
-
12
- it('extracts single mention', () => {
13
- expect(extractMentions('Hello @planner, please review.')).toEqual(['planner']);
14
- });
15
-
16
- it('extracts multiple mentions and deduplicates them', () => {
17
- const text = 'Hey @jane and @planner, can @jane check with @coordinator?';
18
- expect(extractMentions(text)).toEqual(['jane', 'planner', 'coordinator']);
19
- });
20
-
21
- it('supports quoted handles with spaces', () => {
22
- const text = 'Assigning to @"Agent Planner" and @"Jane Doe"';
23
- expect(extractMentions(text)).toEqual(['Agent Planner', 'Jane Doe']);
24
- });
25
-
26
- it('ignores email addresses without leading space or boundary', () => {
27
- const text = 'Send mail to user@example.com or ping @alex';
28
- expect(extractMentions(text)).toEqual(['alex']);
29
- });
30
-
31
- it('handles mentions with dashes, underscores, and periods', () => {
32
- const text = 'Call @agent-1, @super_user, and @john.doe';
33
- expect(extractMentions(text)).toEqual(['agent-1', 'super_user', 'john.doe']);
34
- });
35
-
36
- it('correctly ignores trailing punctuation such as periods, commas, and exclamation marks', () => {
37
- const text = 'Check with @turquoise. Then ping @john.doe! Also ask @coordinator, and @"Jane Doe".';
38
- expect(extractMentions(text)).toEqual(['turquoise', 'john.doe', 'coordinator', 'Jane Doe']);
39
- });
40
-
41
- it('suppresses mentions inside fenced code blocks and inline backticks (UCH-128, UCH-138)', () => {
42
- const markdown = `
43
- Hey @alice, please review this test output:
44
- \`\`\`ts
45
- import { describe } from '@vitest/runner';
46
- // mention in code comment: @bob
47
- const handler = () => '@charlie';
48
- \`\`\`
49
- Also do not match \`@david\` in inline backticks or ~~~@eva~~~ in tilde fences.
50
- Only real mentions like @frank should match.
51
- `;
52
- expect(extractMentions(markdown)).toEqual(['alice', 'frank']);
53
- });
54
-
55
- it('suppresses mentions inside HTML <pre> and <code> blocks', () => {
56
- const html = 'Hello @alice! Check <pre>npm i @types/node</pre> and <code>@bob</code>. Thanks @charlie!';
57
- expect(extractMentions(html)).toEqual(['alice', 'charlie']);
58
- });
59
-
60
- it('suppresses handles inside URLs and markdown link destinations', () => {
61
- const text = 'Visit https://github.com/@org/repo and [profile](https://example.com/@jack) then ping @jack';
62
- expect(extractMentions(text)).toEqual(['jack']);
63
- });
64
-
65
- it('preserves rich text HTML mention nodes while ignoring attributes', () => {
66
- const html = '<p>Assigned to <span data-type="mention" data-label="Jane Doe" data-mention-suggestion-char="@">@Jane Doe</span> and ping @coordinator</p>';
67
- expect(extractMentions(html)).toEqual(['Jane Doe', 'coordinator']);
68
- });
69
- });
70
-
71
- describe('stripMarkdownCode', () => {
72
- it('strips code blocks, tilde blocks, inline backticks, pre and code tags', () => {
73
- const raw = 'Before ```code @foo``` and `inline @bar` and <pre>pre @baz</pre> and <code>c @qux</code> after @real';
74
- expect(stripMarkdownCode(raw)).toBe('Before and and and after @real');
75
- });
76
- });
77
-
78
- describe('parseMentionSegments', () => {
79
- it('returns empty array for empty string', () => {
80
- expect(parseMentionSegments('')).toEqual([]);
81
- });
82
-
83
- it('returns single text segment if no mentions', () => {
84
- expect(parseMentionSegments('Just a normal comment without tags.')).toEqual([
85
- { type: 'text', value: 'Just a normal comment without tags.' }
86
- ]);
87
- });
88
-
89
- it('correctly segments text with single mention in the middle', () => {
90
- const result = parseMentionSegments('Hello @planner, please check.');
91
- expect(result).toEqual([
92
- { type: 'text', value: 'Hello ' },
93
- { type: 'mention', value: '@planner', handle: 'planner' },
94
- { type: 'text', value: ', please check.' }
95
- ]);
96
- });
97
-
98
- it('correctly segments mention with trailing period', () => {
99
- const result = parseMentionSegments('Hello @turquoise.');
100
- expect(result).toEqual([
101
- { type: 'text', value: 'Hello ' },
102
- { type: 'mention', value: '@turquoise', handle: 'turquoise' },
103
- { type: 'text', value: '.' }
104
- ]);
105
- });
106
-
107
- it('correctly segments text starting with a mention', () => {
108
- const result = parseMentionSegments('@planner can you take a look?');
109
- expect(result).toEqual([
110
- { type: 'mention', value: '@planner', handle: 'planner' },
111
- { type: 'text', value: ' can you take a look?' }
112
- ]);
113
- });
114
-
115
- it('correctly segments text ending with a mention', () => {
116
- const result = parseMentionSegments('Assigned to @coordinator');
117
- expect(result).toEqual([
118
- { type: 'text', value: 'Assigned to ' },
119
- { type: 'mention', value: '@coordinator', handle: 'coordinator' }
120
- ]);
121
- });
122
-
123
- it('correctly segments quoted mentions', () => {
124
- const result = parseMentionSegments('Ping @"Agent Supervisor" ASAP');
125
- expect(result).toEqual([
126
- { type: 'text', value: 'Ping ' },
127
- { type: 'mention', value: '@"Agent Supervisor"', handle: 'Agent Supervisor' },
128
- { type: 'text', value: ' ASAP' }
129
- ]);
130
- });
131
- });
132
- });
@@ -1,131 +0,0 @@
1
- export interface MentionSegment {
2
- type: 'text' | 'mention';
3
- value: string;
4
- handle?: string;
5
- }
6
-
7
- /**
8
- * Regex matching mentions:
9
- * - Quoted mentions: @"Jane Doe", &quot;Jane Doe&quot;
10
- * - Standard handles: @planner, @user-1, @john.smith
11
- * Unquoted handles exclude trailing punctuation (e.g. @turquoise. matches handle "turquoise" without the dot).
12
- */
13
- export const MENTION_REGEX =
14
- /(?:^|[\s>(*_"';\\/[\]{}~`:]|&quot;|&gt;|&lt;|&amp;)@(?:"([^"]+)"|&quot;([^&]+)&quot;|([a-zA-Z0-9_-]+(?:\.[a-zA-Z0-9_-]+)*))/g;
15
-
16
- /**
17
- * Strips code blocks and inline code from markdown or HTML content:
18
- * - Fenced code blocks: ```...``` and ~~~...~~~
19
- * - Inline backtick code: `...`
20
- * - HTML code/pre tags: <pre>...</pre>, <code>...</code>
21
- * Used to avoid false-positive mention parsing within code snippets, terminal logs, or stack traces.
22
- */
23
- export function stripMarkdownCode(content: string): string {
24
- if (!content || typeof content !== 'string') return '';
25
- return content
26
- .replace(/```[\s\S]*?```/g, '')
27
- .replace(/~~~[\s\S]*?~~~/g, '')
28
- .replace(/<pre[\s\S]*?<\/pre>/gi, '')
29
- .replace(/<code[\s\S]*?<\/code>/gi, '')
30
- .replace(/`[^`\n]*`/g, '');
31
- }
32
-
33
- /**
34
- * Extracts unique mention handles from a text string, ignoring trailing punctuation,
35
- * code blocks or inline code snippets, URLs, markdown link destinations, and pre-existing HTML mention nodes.
36
- * Preserves the order of their first appearance.
37
- */
38
- export function extractMentions(content: string): string[] {
39
- if (!content || typeof content !== 'string') return [];
40
-
41
- // Normalize rich text mention nodes (e.g. from TipTap or custom mention spans)
42
- const normalizedMentionNodes = content.replace(
43
- /<span\b[^>]*\b(?:data-type=["']mention["']|class=["'][^"']*pixerate-mention-node[^"']*["'])[^>]*>([\s\S]*?)<\/span>/gi,
44
- (match, inner) => {
45
- const labelMatch = match.match(/\bdata-label=["']([^"']+)["']/i);
46
- if (labelMatch) {
47
- const val = labelMatch[1].trim();
48
- return val.includes(' ') ? ` @"${val}" ` : ` @${val} `;
49
- }
50
- const idMatch = match.match(/\bdata-id=["']([^"']+)["']/i);
51
- if (idMatch) {
52
- const val = idMatch[1].trim();
53
- return val.includes(' ') ? ` @"${val}" ` : ` @${val} `;
54
- }
55
- return ` ${inner} `;
56
- }
57
- );
58
-
59
- const cleanContent = stripMarkdownCode(normalizedMentionNodes);
60
- // Strip URLs and markdown link destinations so @package or @handles in URLs are not extracted as mentions
61
- const withoutUrls = cleanContent
62
- .replace(/(?:https?|ftp|file):\/\/[^\s<>()]+/gi, '')
63
- .replace(/\]\([^)]*\)/g, ']');
64
- // Strip remaining HTML tags
65
- const textOnly = withoutUrls.replace(/<[^>]+>/g, ' ');
66
-
67
- const mentions: string[] = [];
68
- const seen = new Set<string>();
69
-
70
- const regex = new RegExp(MENTION_REGEX.source, 'g');
71
- let match: RegExpExecArray | null;
72
-
73
- while ((match = regex.exec(textOnly)) !== null) {
74
- const handle = (match[1] ?? match[2] ?? match[3] ?? '').trim();
75
- if (handle && !seen.has(handle)) {
76
- seen.add(handle);
77
- mentions.push(handle);
78
- }
79
- }
80
-
81
- return mentions;
82
- }
83
-
84
- /**
85
- * Segments a text string into plain text parts and mention tokens.
86
- * Useful for rendering highlighted mention badges or links in UI components.
87
- */
88
- export function parseMentionSegments(content: string): MentionSegment[] {
89
- if (!content) return [];
90
-
91
- const segments: MentionSegment[] = [];
92
- const regex = new RegExp(MENTION_REGEX.source, 'g');
93
- let lastIndex = 0;
94
- let match: RegExpExecArray | null;
95
-
96
- while ((match = regex.exec(content)) !== null) {
97
- const fullMatch = match[0];
98
- const atIndex = fullMatch.indexOf('@');
99
- const prefix = atIndex > 0 ? fullMatch.slice(0, atIndex) : '';
100
- const mentionToken = fullMatch.slice(atIndex);
101
- const handle = match[1] ?? match[2] ?? match[3];
102
- const matchStart = match.index + prefix.length;
103
-
104
- // Push text before this mention if any
105
- if (matchStart > lastIndex) {
106
- segments.push({
107
- type: 'text',
108
- value: content.slice(lastIndex, matchStart)
109
- });
110
- }
111
-
112
- // Push the mention token
113
- segments.push({
114
- type: 'mention',
115
- value: mentionToken,
116
- handle
117
- });
118
-
119
- lastIndex = matchStart + mentionToken.length;
120
- }
121
-
122
- // Push any remaining text after the last match
123
- if (lastIndex < content.length) {
124
- segments.push({
125
- type: 'text',
126
- value: content.slice(lastIndex)
127
- });
128
- }
129
-
130
- return segments;
131
- }