@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,419 +0,0 @@
1
- import type {
2
- Task,
3
- StatusDefinition,
4
- SemanticStatus,
5
- TaskDerivedStatus,
6
- Workflow
7
- } from '../types/index.js';
8
-
9
- export const DEFAULT_STATUS_DEFINITIONS: Record<string, StatusDefinition> = {
10
- backlog: { key: 'backlog', label: 'Backlog', category: 'not_started' },
11
- todo: { key: 'todo', label: 'To Do', category: 'not_started' },
12
- in_progress: { key: 'in_progress', label: 'In Progress', category: 'in_progress' },
13
- in_review: { key: 'in_review', label: 'In Review', category: 'in_progress' },
14
- done: { key: 'done', label: 'Done', category: 'completed' },
15
- canceled: { key: 'canceled', label: 'Canceled', category: 'canceled' }
16
- };
17
-
18
- export interface DeriveTaskLifecycleOptions {
19
- customDefinitions?: StatusDefinition[];
20
- referenceDate?: Date;
21
- upstreamTasks?: Task[];
22
- stalledThresholdDays?: number;
23
- }
24
-
25
- export function resolveStatusDefinition(
26
- statusKey: string,
27
- customDefinitions?: StatusDefinition[]
28
- ): StatusDefinition {
29
- if (customDefinitions) {
30
- const found = customDefinitions.find((def) => def.key === statusKey);
31
- if (found) return found;
32
- }
33
- if (DEFAULT_STATUS_DEFINITIONS[statusKey]) {
34
- return DEFAULT_STATUS_DEFINITIONS[statusKey];
35
- }
36
-
37
- // Fallback heuristic for unknown custom statuses:
38
- const lower = statusKey.toLowerCase();
39
- let category: SemanticStatus = 'not_started';
40
- if (['canceled', 'cancelled', 'rejected', 'abandoned', 'void', 'dropped'].some((k) => lower.includes(k))) {
41
- category = 'canceled';
42
- } else if (['done', 'completed', 'finished', 'closed', 'approved', 'final', 'delivered', 'shipped'].some((k) => lower.includes(k))) {
43
- category = 'completed';
44
- } else if (['in_progress', 'active', 'working', 'in_review', 'review', 'testing', 'qa', 'building', 'editing'].some((k) => lower.includes(k))) {
45
- category = 'in_progress';
46
- }
47
-
48
- return {
49
- key: statusKey,
50
- label: statusKey,
51
- category
52
- };
53
- }
54
-
55
- export function deriveTaskLifecycleState(
56
- task: Task,
57
- customDefinitionsOrOptions?: StatusDefinition[] | DeriveTaskLifecycleOptions,
58
- legacyReferenceDate?: Date
59
- ): TaskDerivedStatus {
60
- let customDefinitions: StatusDefinition[] | undefined;
61
- let referenceDate = legacyReferenceDate ?? new Date();
62
- let upstreamTasks: Task[] = [];
63
- let stalledThresholdDays = 5;
64
-
65
- if (Array.isArray(customDefinitionsOrOptions)) {
66
- customDefinitions = customDefinitionsOrOptions;
67
- } else if (customDefinitionsOrOptions) {
68
- customDefinitions = customDefinitionsOrOptions.customDefinitions;
69
- if (customDefinitionsOrOptions.referenceDate) {
70
- referenceDate = customDefinitionsOrOptions.referenceDate;
71
- }
72
- if (customDefinitionsOrOptions.upstreamTasks) {
73
- upstreamTasks = customDefinitionsOrOptions.upstreamTasks;
74
- }
75
- if (customDefinitionsOrOptions.stalledThresholdDays !== undefined) {
76
- stalledThresholdDays = customDefinitionsOrOptions.stalledThresholdDays;
77
- }
78
- }
79
-
80
- const def = resolveStatusDefinition(task.status, customDefinitions);
81
- const semanticStatus: SemanticStatus = def.category;
82
- const isDone = semanticStatus === 'completed' || semanticStatus === 'canceled';
83
- const isActive = semanticStatus === 'in_progress';
84
- const isCancelled = semanticStatus === 'canceled';
85
-
86
- // Dependency & Flow Indicators
87
- const blockingTasks = upstreamTasks.filter((t) => {
88
- const upstreamDef = resolveStatusDefinition(t.status, customDefinitions);
89
- return upstreamDef.category !== 'completed';
90
- });
91
- const blockingTaskIds = blockingTasks.map((t) => t.id);
92
- const isExplicitlyBlocked = Boolean(task.isBlocked === true);
93
- const isBlocked = !isDone && (blockingTaskIds.length > 0 || isExplicitlyBlocked);
94
- const isReady = semanticStatus === 'not_started' && !isBlocked;
95
-
96
- // Time & Schedule Indicators
97
- let isOverdue = false;
98
- if (!isDone && task.dueDate) {
99
- const due = new Date(task.dueDate);
100
- if (!isNaN(due.getTime()) && due < referenceDate) {
101
- isOverdue = true;
102
- }
103
- }
104
-
105
- let isUpcoming = false;
106
- if (semanticStatus === 'not_started' && task.plannedStartDate) {
107
- const plannedStart = new Date(task.plannedStartDate);
108
- if (!isNaN(plannedStart.getTime()) && plannedStart > referenceDate) {
109
- isUpcoming = true;
110
- }
111
- }
112
-
113
- const isUnplanned = semanticStatus === 'not_started' && !task.iterationId && !task.plannedStartDate && !task.dueDate;
114
-
115
- // Resource & Activity Indicators
116
- const hasAssignee = Boolean(task.assigneeId || (task.assignees && task.assignees.length > 0));
117
- const isUnassigned = !isDone && !hasAssignee;
118
-
119
- let isStalled = false;
120
- if (semanticStatus === 'in_progress') {
121
- const lastActivity = task.updatedAt ? new Date(task.updatedAt) : (task.createdAt ? new Date(task.createdAt) : null);
122
- if (lastActivity && !isNaN(lastActivity.getTime())) {
123
- const thresholdMs = stalledThresholdDays * 24 * 60 * 60 * 1000;
124
- if (referenceDate.getTime() - lastActivity.getTime() > thresholdMs) {
125
- isStalled = true;
126
- }
127
- }
128
- }
129
-
130
- // Effort & Estimate Indicators
131
- let isOverEstimate = false;
132
- const loggedH = task.loggedHours ?? task.actualHours;
133
- const estimatedH = task.estimatedHours;
134
- if (estimatedH !== undefined && estimatedH > 0 && loggedH !== undefined && loggedH > estimatedH) {
135
- isOverEstimate = true;
136
- }
137
- const actualM = task.actualDurationMinutes;
138
- const estimatedM = task.estimatedDurationMinutes;
139
- if (estimatedM !== undefined && estimatedM > 0 && actualM !== undefined && actualM > estimatedM) {
140
- isOverEstimate = true;
141
- }
142
-
143
- let isPaceWarning = false;
144
- if (semanticStatus === 'in_progress' && task.actualStartDate) {
145
- const start = new Date(task.actualStartDate);
146
- if (!isNaN(start.getTime())) {
147
- const elapsedMs = referenceDate.getTime() - start.getTime();
148
- const elapsedHours = elapsedMs / (1000 * 60 * 60);
149
- if (estimatedH !== undefined && estimatedH > 0 && elapsedHours > estimatedH) {
150
- isPaceWarning = true;
151
- } else if (estimatedM !== undefined && estimatedM > 0 && (elapsedMs / (1000 * 60)) > estimatedM) {
152
- isPaceWarning = true;
153
- }
154
- }
155
- }
156
-
157
- return {
158
- semanticStatus,
159
- isReady,
160
- isBlocked,
161
- blockingTaskIds,
162
- isOverdue,
163
- isUpcoming,
164
- isUnplanned,
165
- isUnassigned,
166
- isStalled,
167
- isOverEstimate,
168
- isPaceWarning,
169
- isDone,
170
- isActive,
171
- isCancelled
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
-