@critical-path/core 0.36.0 → 0.37.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 (214) hide show
  1. package/README.md +1 -1
  2. package/dist/domain/authorization.d.ts.map +1 -1
  3. package/dist/domain/authorization.js +10 -7
  4. package/dist/domain/authorization.js.map +1 -1
  5. package/dist/engine/index.d.ts +6 -0
  6. package/dist/engine/index.d.ts.map +1 -1
  7. package/dist/engine/index.js +28 -2
  8. package/dist/engine/index.js.map +1 -1
  9. package/dist/schemas/index.d.ts +42 -12
  10. package/dist/schemas/index.d.ts.map +1 -1
  11. package/dist/schemas/index.js +4 -1
  12. package/dist/schemas/index.js.map +1 -1
  13. package/dist/store/firebase.d.ts +2 -2
  14. package/dist/store/firebase.d.ts.map +1 -1
  15. package/dist/store/firebase.js +4 -2
  16. package/dist/store/firebase.js.map +1 -1
  17. package/dist/store/index.d.ts +7 -2
  18. package/dist/store/index.d.ts.map +1 -1
  19. package/dist/store/index.js +3 -2
  20. package/dist/store/index.js.map +1 -1
  21. package/dist/store/sqlite.d.ts +2 -2
  22. package/dist/store/sqlite.d.ts.map +1 -1
  23. package/dist/store/sqlite.js +5 -3
  24. package/dist/store/sqlite.js.map +1 -1
  25. package/dist/testing/conformance.d.ts.map +1 -1
  26. package/dist/testing/conformance.js +9 -0
  27. package/dist/testing/conformance.js.map +1 -1
  28. package/dist/types/index.d.ts +13 -2
  29. package/dist/types/index.d.ts.map +1 -1
  30. package/package.json +5 -1
  31. package/CHANGELOG.md +0 -593
  32. package/dist/deliverables.test.d.ts +0 -2
  33. package/dist/deliverables.test.d.ts.map +0 -1
  34. package/dist/deliverables.test.js +0 -232
  35. package/dist/deliverables.test.js.map +0 -1
  36. package/dist/domain/calendar.test.d.ts +0 -2
  37. package/dist/domain/calendar.test.d.ts.map +0 -1
  38. package/dist/domain/calendar.test.js +0 -181
  39. package/dist/domain/calendar.test.js.map +0 -1
  40. package/dist/domain/cpm.test.d.ts +0 -2
  41. package/dist/domain/cpm.test.d.ts.map +0 -1
  42. package/dist/domain/cpm.test.js +0 -166
  43. package/dist/domain/cpm.test.js.map +0 -1
  44. package/dist/domain/ddd.test.d.ts +0 -2
  45. package/dist/domain/ddd.test.d.ts.map +0 -1
  46. package/dist/domain/ddd.test.js +0 -349
  47. package/dist/domain/ddd.test.js.map +0 -1
  48. package/dist/domain/ladder.test.d.ts +0 -2
  49. package/dist/domain/ladder.test.d.ts.map +0 -1
  50. package/dist/domain/ladder.test.js +0 -213
  51. package/dist/domain/ladder.test.js.map +0 -1
  52. package/dist/domain/metrics.test.d.ts +0 -2
  53. package/dist/domain/metrics.test.d.ts.map +0 -1
  54. package/dist/domain/metrics.test.js +0 -252
  55. package/dist/domain/metrics.test.js.map +0 -1
  56. package/dist/domain/task-duration.test.d.ts +0 -2
  57. package/dist/domain/task-duration.test.d.ts.map +0 -1
  58. package/dist/domain/task-duration.test.js +0 -307
  59. package/dist/domain/task-duration.test.js.map +0 -1
  60. package/dist/domain/workload.test.d.ts +0 -2
  61. package/dist/domain/workload.test.d.ts.map +0 -1
  62. package/dist/domain/workload.test.js +0 -261
  63. package/dist/domain/workload.test.js.map +0 -1
  64. package/dist/engine/actor.test.d.ts +0 -2
  65. package/dist/engine/actor.test.d.ts.map +0 -1
  66. package/dist/engine/actor.test.js +0 -54
  67. package/dist/engine/actor.test.js.map +0 -1
  68. package/dist/engine/authorization.test.d.ts +0 -2
  69. package/dist/engine/authorization.test.d.ts.map +0 -1
  70. package/dist/engine/authorization.test.js +0 -154
  71. package/dist/engine/authorization.test.js.map +0 -1
  72. package/dist/engine/cascade.test.d.ts +0 -2
  73. package/dist/engine/cascade.test.d.ts.map +0 -1
  74. package/dist/engine/cascade.test.js +0 -99
  75. package/dist/engine/cascade.test.js.map +0 -1
  76. package/dist/engine/config.test.d.ts +0 -2
  77. package/dist/engine/config.test.d.ts.map +0 -1
  78. package/dist/engine/config.test.js +0 -46
  79. package/dist/engine/config.test.js.map +0 -1
  80. package/dist/engine/entity-events.test.d.ts +0 -2
  81. package/dist/engine/entity-events.test.d.ts.map +0 -1
  82. package/dist/engine/entity-events.test.js +0 -61
  83. package/dist/engine/entity-events.test.js.map +0 -1
  84. package/dist/index.test.d.ts +0 -2
  85. package/dist/index.test.d.ts.map +0 -1
  86. package/dist/index.test.js +0 -429
  87. package/dist/index.test.js.map +0 -1
  88. package/dist/plugins/plugins.test.d.ts +0 -2
  89. package/dist/plugins/plugins.test.d.ts.map +0 -1
  90. package/dist/plugins/plugins.test.js +0 -137
  91. package/dist/plugins/plugins.test.js.map +0 -1
  92. package/dist/schemas/schemas.test.d.ts +0 -2
  93. package/dist/schemas/schemas.test.d.ts.map +0 -1
  94. package/dist/schemas/schemas.test.js +0 -58
  95. package/dist/schemas/schemas.test.js.map +0 -1
  96. package/dist/status.test.d.ts +0 -2
  97. package/dist/status.test.d.ts.map +0 -1
  98. package/dist/status.test.js +0 -295
  99. package/dist/status.test.js.map +0 -1
  100. package/dist/storage/storage.test.d.ts +0 -2
  101. package/dist/storage/storage.test.d.ts.map +0 -1
  102. package/dist/storage/storage.test.js +0 -236
  103. package/dist/storage/storage.test.js.map +0 -1
  104. package/dist/storage/upload-limits.test.d.ts +0 -2
  105. package/dist/storage/upload-limits.test.d.ts.map +0 -1
  106. package/dist/storage/upload-limits.test.js +0 -31
  107. package/dist/storage/upload-limits.test.js.map +0 -1
  108. package/dist/store/conformance.test.d.ts +0 -2
  109. package/dist/store/conformance.test.d.ts.map +0 -1
  110. package/dist/store/conformance.test.js +0 -15
  111. package/dist/store/conformance.test.js.map +0 -1
  112. package/dist/store/firebase.test.d.ts +0 -2
  113. package/dist/store/firebase.test.d.ts.map +0 -1
  114. package/dist/store/firebase.test.js +0 -103
  115. package/dist/store/firebase.test.js.map +0 -1
  116. package/dist/store/query.test.d.ts +0 -2
  117. package/dist/store/query.test.d.ts.map +0 -1
  118. package/dist/store/query.test.js +0 -89
  119. package/dist/store/query.test.js.map +0 -1
  120. package/dist/store/sqlite.test.d.ts +0 -2
  121. package/dist/store/sqlite.test.d.ts.map +0 -1
  122. package/dist/store/sqlite.test.js +0 -177
  123. package/dist/store/sqlite.test.js.map +0 -1
  124. package/dist/task-state.test.d.ts +0 -2
  125. package/dist/task-state.test.d.ts.map +0 -1
  126. package/dist/task-state.test.js +0 -423
  127. package/dist/task-state.test.js.map +0 -1
  128. package/dist/use-case-validation.test.d.ts +0 -2
  129. package/dist/use-case-validation.test.d.ts.map +0 -1
  130. package/dist/use-case-validation.test.js +0 -281
  131. package/dist/use-case-validation.test.js.map +0 -1
  132. package/dist/utils/fractional-index.test.d.ts +0 -2
  133. package/dist/utils/fractional-index.test.d.ts.map +0 -1
  134. package/dist/utils/fractional-index.test.js +0 -182
  135. package/dist/utils/fractional-index.test.js.map +0 -1
  136. package/dist/utils/key.test.d.ts +0 -2
  137. package/dist/utils/key.test.d.ts.map +0 -1
  138. package/dist/utils/key.test.js +0 -65
  139. package/dist/utils/key.test.js.map +0 -1
  140. package/dist/utils/mentions.test.d.ts +0 -2
  141. package/dist/utils/mentions.test.d.ts.map +0 -1
  142. package/dist/utils/mentions.test.js +0 -114
  143. package/dist/utils/mentions.test.js.map +0 -1
  144. package/dist/webhooks/webhooks.test.d.ts +0 -2
  145. package/dist/webhooks/webhooks.test.d.ts.map +0 -1
  146. package/dist/webhooks/webhooks.test.js +0 -154
  147. package/dist/webhooks/webhooks.test.js.map +0 -1
  148. package/src/deliverables.test.ts +0 -284
  149. package/src/domain/authorization.ts +0 -82
  150. package/src/domain/calendar.test.ts +0 -216
  151. package/src/domain/calendar.ts +0 -502
  152. package/src/domain/cpm.test.ts +0 -189
  153. package/src/domain/cpm.ts +0 -258
  154. package/src/domain/custom-fields.ts +0 -172
  155. package/src/domain/ddd.test.ts +0 -442
  156. package/src/domain/entities.ts +0 -798
  157. package/src/domain/errors.ts +0 -38
  158. package/src/domain/events.ts +0 -369
  159. package/src/domain/graph.ts +0 -70
  160. package/src/domain/index.ts +0 -12
  161. package/src/domain/ladder.test.ts +0 -251
  162. package/src/domain/ladder.ts +0 -474
  163. package/src/domain/metrics.test.ts +0 -288
  164. package/src/domain/metrics.ts +0 -497
  165. package/src/domain/task-duration.test.ts +0 -354
  166. package/src/domain/workload.test.ts +0 -311
  167. package/src/domain/workload.ts +0 -457
  168. package/src/engine/actor.test.ts +0 -63
  169. package/src/engine/authorization.test.ts +0 -199
  170. package/src/engine/cascade.test.ts +0 -121
  171. package/src/engine/config.test.ts +0 -51
  172. package/src/engine/entity-events.test.ts +0 -67
  173. package/src/engine/index.ts +0 -2495
  174. package/src/index.test.ts +0 -514
  175. package/src/index.ts +0 -9
  176. package/src/plugins/index.ts +0 -103
  177. package/src/plugins/plugins.test.ts +0 -161
  178. package/src/schemas/index.ts +0 -402
  179. package/src/schemas/schemas.test.ts +0 -116
  180. package/src/status.test.ts +0 -354
  181. package/src/storage/file-storage.ts +0 -200
  182. package/src/storage/firebase-storage.ts +0 -209
  183. package/src/storage/index.ts +0 -3
  184. package/src/storage/s3.ts +0 -151
  185. package/src/storage/storage.test.ts +0 -274
  186. package/src/storage/upload-limits.test.ts +0 -41
  187. package/src/store/conformance.test.ts +0 -15
  188. package/src/store/firebase.test.ts +0 -131
  189. package/src/store/firebase.ts +0 -658
  190. package/src/store/index.ts +0 -623
  191. package/src/store/query.test.ts +0 -110
  192. package/src/store/query.ts +0 -113
  193. package/src/store/sqlite.test.ts +0 -218
  194. package/src/store/sqlite.ts +0 -1480
  195. package/src/task-state.test.ts +0 -506
  196. package/src/testing/conformance.ts +0 -319
  197. package/src/testing/index.ts +0 -1
  198. package/src/types/index.ts +0 -871
  199. package/src/use-case-validation.test.ts +0 -324
  200. package/src/utils/fractional-index.test.ts +0 -228
  201. package/src/utils/fractional-index.ts +0 -254
  202. package/src/utils/index.ts +0 -7
  203. package/src/utils/key.test.ts +0 -76
  204. package/src/utils/key.ts +0 -62
  205. package/src/utils/mentions.test.ts +0 -132
  206. package/src/utils/mentions.ts +0 -131
  207. package/src/utils/status.ts +0 -419
  208. package/src/utils/workflow.ts +0 -306
  209. package/src/webhooks/dispatcher.ts +0 -190
  210. package/src/webhooks/index.ts +0 -2
  211. package/src/webhooks/signature.ts +0 -57
  212. package/src/webhooks/webhooks.test.ts +0 -201
  213. package/tsconfig.json +0 -8
  214. 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
- }