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