@critical-path/core 0.20.2 → 0.21.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 (57) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/README.md +41 -0
  3. package/dist/domain/task-duration.test.js +32 -0
  4. package/dist/domain/task-duration.test.js.map +1 -1
  5. package/dist/engine/index.d.ts.map +1 -1
  6. package/dist/engine/index.js +40 -9
  7. package/dist/engine/index.js.map +1 -1
  8. package/dist/status.test.js +97 -1
  9. package/dist/status.test.js.map +1 -1
  10. package/dist/store/sqlite.d.ts.map +1 -1
  11. package/dist/store/sqlite.js +14 -5
  12. package/dist/store/sqlite.js.map +1 -1
  13. package/dist/types/index.d.ts +1 -0
  14. package/dist/types/index.d.ts.map +1 -1
  15. package/dist/utils/fractional-index.d.ts +50 -0
  16. package/dist/utils/fractional-index.d.ts.map +1 -0
  17. package/dist/utils/fractional-index.js +230 -0
  18. package/dist/utils/fractional-index.js.map +1 -0
  19. package/dist/utils/fractional-index.test.d.ts +2 -0
  20. package/dist/utils/fractional-index.test.d.ts.map +1 -0
  21. package/dist/utils/fractional-index.test.js +151 -0
  22. package/dist/utils/fractional-index.test.js.map +1 -0
  23. package/dist/utils/index.d.ts +1 -0
  24. package/dist/utils/index.d.ts.map +1 -1
  25. package/dist/utils/index.js +1 -0
  26. package/dist/utils/index.js.map +1 -1
  27. package/dist/utils/key.d.ts +5 -0
  28. package/dist/utils/key.d.ts.map +1 -1
  29. package/dist/utils/key.js +10 -0
  30. package/dist/utils/key.js.map +1 -1
  31. package/dist/utils/key.test.js +18 -1
  32. package/dist/utils/key.test.js.map +1 -1
  33. package/dist/utils/mentions.d.ts +13 -5
  34. package/dist/utils/mentions.d.ts.map +1 -1
  35. package/dist/utils/mentions.js +52 -16
  36. package/dist/utils/mentions.js.map +1 -1
  37. package/dist/utils/mentions.test.js +32 -1
  38. package/dist/utils/mentions.test.js.map +1 -1
  39. package/dist/utils/status.d.ts +80 -1
  40. package/dist/utils/status.d.ts.map +1 -1
  41. package/dist/utils/status.js +194 -0
  42. package/dist/utils/status.js.map +1 -1
  43. package/package.json +1 -1
  44. package/src/domain/task-duration.test.ts +36 -0
  45. package/src/engine/index.ts +39 -9
  46. package/src/status.test.ts +130 -2
  47. package/src/store/sqlite.ts +14 -3
  48. package/src/types/index.ts +1 -0
  49. package/src/utils/fractional-index.test.ts +191 -0
  50. package/src/utils/fractional-index.ts +260 -0
  51. package/src/utils/index.ts +2 -0
  52. package/src/utils/key.test.ts +22 -1
  53. package/src/utils/key.ts +11 -0
  54. package/src/utils/mentions.test.ts +37 -1
  55. package/src/utils/mentions.ts +58 -16
  56. package/src/utils/status.ts +247 -0
  57. package/tsconfig.tsbuildinfo +1 -1
@@ -3,6 +3,7 @@ import type {
3
3
  StatusDefinition,
4
4
  SemanticStatus,
5
5
  TaskDerivedStatus,
6
+ Workflow
6
7
  } from '../types/index.js';
7
8
 
8
9
  export const DEFAULT_STATUS_DEFINITIONS: Record<string, StatusDefinition> = {
@@ -170,3 +171,249 @@ export function deriveTaskLifecycleState(
170
171
  isCancelled
171
172
  };
172
173
  }
174
+
175
+ export type TaskLike = {
176
+ status?: string | null;
177
+ semanticStatus?: SemanticStatus | string | null;
178
+ trashed?: boolean | null;
179
+ trashedAt?: string | null;
180
+ archived?: boolean | null;
181
+ archivedAt?: string | null;
182
+ isDraft?: boolean | null;
183
+ assigneeId?: string | null;
184
+ assignees?: Array<{ id?: string; name?: string } | string> | null;
185
+ customFields?: Record<string, unknown> | null;
186
+ [key: string]: unknown;
187
+ };
188
+
189
+ /**
190
+ * Extracts a list of StatusDefinitions from either a Workflow or an array of definitions.
191
+ */
192
+ export function extractStatusDefinitions(
193
+ workflowOrStatuses?: Workflow | StatusDefinition[] | unknown
194
+ ): StatusDefinition[] | undefined {
195
+ if (!workflowOrStatuses) return undefined;
196
+ if (Array.isArray(workflowOrStatuses)) {
197
+ return workflowOrStatuses as StatusDefinition[];
198
+ }
199
+ if (typeof workflowOrStatuses === 'object' && workflowOrStatuses !== null) {
200
+ const statuses = (workflowOrStatuses as any).statuses;
201
+ if (Array.isArray(statuses)) {
202
+ return statuses as StatusDefinition[];
203
+ }
204
+ }
205
+ return undefined;
206
+ }
207
+
208
+ /**
209
+ * Checks whether a task is flagged as a draft outside the active workflow.
210
+ */
211
+ export function isDraftTask(task: TaskLike | null | undefined): boolean {
212
+ if (!task) return false;
213
+ return Boolean(task.isDraft);
214
+ }
215
+
216
+ /**
217
+ * Checks whether a task is archived.
218
+ */
219
+ export function isArchivedTask(task: TaskLike | null | undefined): boolean {
220
+ if (!task) return false;
221
+ return (
222
+ Boolean(task.archived) ||
223
+ Boolean(task.archivedAt) ||
224
+ task.status === 'archived' ||
225
+ Boolean((task.customFields as any)?.isArchived)
226
+ );
227
+ }
228
+
229
+ /**
230
+ * Checks whether a task is soft-deleted / trashed.
231
+ */
232
+ export function isTrashedTask(task: TaskLike | null | undefined): boolean {
233
+ if (!task) return false;
234
+ return (
235
+ Boolean(task.trashed) ||
236
+ Boolean(task.trashedAt) ||
237
+ task.status === 'trashed' ||
238
+ Boolean((task.customFields as any)?.isTrashed)
239
+ );
240
+ }
241
+
242
+ /**
243
+ * Checks whether a task is trashed, archived, or soft-deleted.
244
+ */
245
+ export function isTrashedOrArchivedTask(task: TaskLike | null | undefined): boolean {
246
+ if (!task) return false;
247
+ return isTrashedTask(task) || isArchivedTask(task);
248
+ }
249
+
250
+ /**
251
+ * Determines whether a task is part of the legitimate project workflow.
252
+ * A workflow task is not trashed, not archived, and not a draft.
253
+ */
254
+ export function isWorkflowTask(task: TaskLike | null | undefined): boolean {
255
+ if (!task) return false;
256
+ return !isTrashedTask(task) && !isArchivedTask(task) && !isDraftTask(task);
257
+ }
258
+
259
+ export const isTaskDraft = isDraftTask;
260
+ export const isTaskArchived = isArchivedTask;
261
+ export const isTaskTrashed = isTrashedTask;
262
+ export const isTaskTrashedOrArchived = isTrashedOrArchivedTask;
263
+ export const isTaskWorkflow = isWorkflowTask;
264
+
265
+ /**
266
+ * Resolves the canonical SemanticStatus for a task based on the project's workflow or default heuristics.
267
+ */
268
+ export function getTaskSemanticStatus(
269
+ task: TaskLike | null | undefined,
270
+ workflowOrStatuses?: Workflow | StatusDefinition[] | unknown
271
+ ): SemanticStatus {
272
+ if (!task) return 'not_started';
273
+
274
+ const customDefs = extractStatusDefinitions(workflowOrStatuses);
275
+
276
+ // 1. Look up the task's status in custom workflow definitions
277
+ if (task.status) {
278
+ if (customDefs) {
279
+ const match = customDefs.find((s) => s.key === task.status);
280
+ if (match?.category) return match.category;
281
+ if (match) {
282
+ if ((match as any).completionState === 'done') {
283
+ return (match as any).isCancelled ? 'canceled' : 'completed';
284
+ }
285
+ if ((match as any).executionState === 'active') {
286
+ return 'in_progress';
287
+ }
288
+ if ((match as any).completionState === 'not_done') {
289
+ return 'not_started';
290
+ }
291
+ }
292
+ }
293
+
294
+ // 2. Default status definition lookup from @critical-path/core for standard statuses
295
+ const normalizedKey = task.status.toLowerCase().replace(/[-\s]+/g, '_');
296
+ const defaultDef =
297
+ DEFAULT_STATUS_DEFINITIONS[task.status] || DEFAULT_STATUS_DEFINITIONS[normalizedKey];
298
+ if (defaultDef?.category) {
299
+ return defaultDef.category;
300
+ }
301
+ }
302
+
303
+ // 3. If task has an explicit valid semanticStatus (for custom/unknown status), use it
304
+ if (task.semanticStatus) {
305
+ const raw = String(task.semanticStatus).toLowerCase();
306
+ if (
307
+ raw === 'completed' ||
308
+ raw === 'in_progress' ||
309
+ raw === 'not_started' ||
310
+ raw === 'canceled' ||
311
+ raw === 'cancelled'
312
+ ) {
313
+ return raw === 'cancelled' ? 'canceled' : (raw as SemanticStatus);
314
+ }
315
+ }
316
+
317
+ // 4. Fallback to resolveStatusDefinition for general fallback or 'not_started'
318
+ if (task.status) {
319
+ const def = resolveStatusDefinition(task.status, customDefs);
320
+ if (def?.category) {
321
+ return def.category;
322
+ }
323
+ }
324
+
325
+ return 'not_started';
326
+ }
327
+
328
+ /**
329
+ * Determines whether a task has reached completion in its lifecycle.
330
+ */
331
+ export function isTaskCompleted(
332
+ task: TaskLike | null | undefined,
333
+ workflowOrStatuses?: Workflow | StatusDefinition[] | unknown
334
+ ): boolean {
335
+ if (!task) return false;
336
+ return getTaskSemanticStatus(task, workflowOrStatuses) === 'completed';
337
+ }
338
+
339
+ export const isTaskDone = isTaskCompleted;
340
+
341
+ /**
342
+ * Determines whether a task is actively in progress.
343
+ */
344
+ export function isTaskInProgress(
345
+ task: TaskLike | null | undefined,
346
+ workflowOrStatuses?: Workflow | StatusDefinition[] | unknown
347
+ ): boolean {
348
+ if (!task) return false;
349
+ return getTaskSemanticStatus(task, workflowOrStatuses) === 'in_progress';
350
+ }
351
+
352
+ /**
353
+ * Determines whether a task is pending or not yet started.
354
+ */
355
+ export function isTaskNotStarted(
356
+ task: TaskLike | null | undefined,
357
+ workflowOrStatuses?: Workflow | StatusDefinition[] | unknown
358
+ ): boolean {
359
+ if (!task) return false;
360
+ return getTaskSemanticStatus(task, workflowOrStatuses) === 'not_started';
361
+ }
362
+
363
+ /**
364
+ * Determines whether a task has been canceled or abandoned.
365
+ */
366
+ export function isTaskCanceled(
367
+ task: TaskLike | null | undefined,
368
+ workflowOrStatuses?: Workflow | StatusDefinition[] | unknown
369
+ ): boolean {
370
+ if (!task) return false;
371
+ return getTaskSemanticStatus(task, workflowOrStatuses) === 'canceled';
372
+ }
373
+
374
+ /**
375
+ * Determines whether a task is active in an ongoing project workflow.
376
+ * An active task:
377
+ * 1. Is not trashed or archived.
378
+ * 2. Is not a draft (exists within the active workflow).
379
+ * 3. Has not reached terminal completion ('completed') or terminal abandonment ('canceled').
380
+ */
381
+ export function isTaskActive(
382
+ task: TaskLike | null | undefined,
383
+ workflowOrStatuses?: Workflow | StatusDefinition[] | unknown
384
+ ): boolean {
385
+ if (!task) return false;
386
+ if (isTrashedOrArchivedTask(task)) return false;
387
+ if (isDraftTask(task)) return false;
388
+ const sem = getTaskSemanticStatus(task, workflowOrStatuses);
389
+ return sem !== 'completed' && sem !== 'canceled';
390
+ }
391
+
392
+ /**
393
+ * Checks whether a task currently has no assigned owner.
394
+ */
395
+ export function isTaskUnassigned(task: TaskLike | null | undefined): boolean {
396
+ if (!task) return true;
397
+
398
+ const rawId = task.assigneeId ? String(task.assigneeId).trim() : '';
399
+ const hasAssigneeId = rawId !== '' && rawId.toLowerCase() !== 'unassigned';
400
+
401
+ const hasValidAssignees =
402
+ Array.isArray(task.assignees) &&
403
+ task.assignees.some((a: any) => {
404
+ if (!a) return false;
405
+ if (typeof a === 'string') {
406
+ const s = a.trim();
407
+ return s !== '' && s.toLowerCase() !== 'unassigned';
408
+ }
409
+ const id = a.id ? String(a.id).trim() : '';
410
+ const name = a.name ? String(a.name).trim() : '';
411
+ return (
412
+ (id !== '' && id.toLowerCase() !== 'unassigned') ||
413
+ (name !== '' && name.toLowerCase() !== 'unassigned')
414
+ );
415
+ });
416
+
417
+ return !hasAssigneeId && !hasValidAssignees;
418
+ }
419
+
@@ -1 +1 @@
1
- {"root":["./src/deliverables.test.ts","./src/index.test.ts","./src/index.ts","./src/status.test.ts","./src/task-state.test.ts","./src/use-case-validation.test.ts","./src/domain/calendar.test.ts","./src/domain/calendar.ts","./src/domain/cpm.test.ts","./src/domain/cpm.ts","./src/domain/custom-fields.ts","./src/domain/ddd.test.ts","./src/domain/entities.ts","./src/domain/events.ts","./src/domain/graph.ts","./src/domain/index.ts","./src/domain/ladder.test.ts","./src/domain/ladder.ts","./src/domain/metrics.test.ts","./src/domain/metrics.ts","./src/domain/task-duration.test.ts","./src/domain/workload.test.ts","./src/domain/workload.ts","./src/engine/index.ts","./src/plugins/index.ts","./src/storage/file-storage.ts","./src/storage/firebase-storage.ts","./src/storage/index.ts","./src/storage/s3.ts","./src/storage/storage.test.ts","./src/store/firebase.test.ts","./src/store/firebase.ts","./src/store/index.ts","./src/store/sqlite.test.ts","./src/store/sqlite.ts","./src/types/index.ts","./src/utils/index.ts","./src/utils/key.test.ts","./src/utils/key.ts","./src/utils/mentions.test.ts","./src/utils/mentions.ts","./src/utils/status.ts","./src/utils/workflow.ts"],"version":"5.9.3"}
1
+ {"root":["./src/deliverables.test.ts","./src/index.test.ts","./src/index.ts","./src/status.test.ts","./src/task-state.test.ts","./src/use-case-validation.test.ts","./src/domain/calendar.test.ts","./src/domain/calendar.ts","./src/domain/cpm.test.ts","./src/domain/cpm.ts","./src/domain/custom-fields.ts","./src/domain/ddd.test.ts","./src/domain/entities.ts","./src/domain/events.ts","./src/domain/graph.ts","./src/domain/index.ts","./src/domain/ladder.test.ts","./src/domain/ladder.ts","./src/domain/metrics.test.ts","./src/domain/metrics.ts","./src/domain/task-duration.test.ts","./src/domain/workload.test.ts","./src/domain/workload.ts","./src/engine/index.ts","./src/plugins/index.ts","./src/storage/file-storage.ts","./src/storage/firebase-storage.ts","./src/storage/index.ts","./src/storage/s3.ts","./src/storage/storage.test.ts","./src/store/firebase.test.ts","./src/store/firebase.ts","./src/store/index.ts","./src/store/sqlite.test.ts","./src/store/sqlite.ts","./src/types/index.ts","./src/utils/fractional-index.test.ts","./src/utils/fractional-index.ts","./src/utils/index.ts","./src/utils/key.test.ts","./src/utils/key.ts","./src/utils/mentions.test.ts","./src/utils/mentions.ts","./src/utils/status.ts","./src/utils/workflow.ts"],"version":"5.9.3"}