@@ -6,11 +6,22 @@ import {
66 getTaskById ,
77 updateTaskNotifyPolicyById ,
88} from "../tasks/runtime-internal.js" ;
9+ import {
10+ listTaskFlowAuditFindings ,
11+ summarizeTaskFlowAuditFindings ,
12+ type TaskFlowAuditCode ,
13+ type TaskFlowAuditSeverity ,
14+ } from "../tasks/task-flow-registry.audit.js" ;
15+ import {
16+ getInspectableTaskFlowAuditSummary ,
17+ previewTaskFlowRegistryMaintenance ,
18+ runTaskFlowRegistryMaintenance ,
19+ } from "../tasks/task-flow-registry.maintenance.js" ;
20+ import type { TaskFlowRecord } from "../tasks/task-flow-registry.types.js" ;
921import {
1022 listTaskAuditFindings ,
1123 summarizeTaskAuditFindings ,
1224 type TaskAuditCode ,
13- type TaskAuditFinding ,
1425 type TaskAuditSeverity ,
1526} from "../tasks/task-registry.audit.js" ;
1627import {
@@ -126,29 +137,47 @@ function formatAgeMs(ageMs: number | undefined): string {
126137 return `${ totalSeconds } s` ;
127138}
128139
129- function formatAuditRows ( findings : TaskAuditFinding [ ] , rich : boolean ) {
140+ type TaskSystemAuditCode = TaskAuditCode | TaskFlowAuditCode ;
141+ type TaskSystemAuditSeverity = TaskAuditSeverity | TaskFlowAuditSeverity ;
142+
143+ type TaskSystemAuditFinding = {
144+ kind : "task" | "task_flow" ;
145+ severity : TaskSystemAuditSeverity ;
146+ code : TaskSystemAuditCode ;
147+ detail : string ;
148+ ageMs ?: number ;
149+ status ?: string ;
150+ token ?: string ;
151+ task ?: TaskRecord ;
152+ flow ?: TaskFlowRecord ;
153+ } ;
154+
155+ function formatAuditRows ( findings : TaskSystemAuditFinding [ ] , rich : boolean ) {
130156 const header = [
157+ "Scope" . padEnd ( 8 ) ,
131158 "Severity" . padEnd ( 8 ) ,
132159 "Code" . padEnd ( 22 ) ,
133- "Task " . padEnd ( ID_PAD ) ,
160+ "Item " . padEnd ( ID_PAD ) ,
134161 "Status" . padEnd ( STATUS_PAD ) ,
135162 "Age" . padEnd ( 8 ) ,
136163 "Detail" ,
137164 ] . join ( " " ) ;
138165 const lines = [ rich ? theme . heading ( header ) : header ] ;
139166 for ( const finding of findings ) {
140167 const severity = finding . severity . padEnd ( 8 ) ;
141- const status = formatTaskStatusCell ( finding . task . status , rich ) ;
168+ const status = formatTaskStatusCell ( finding . status ?? "n/a" , rich ) ;
142169 const severityCell = ! rich
143170 ? severity
144171 : finding . severity === "error"
145172 ? theme . error ( severity )
146173 : theme . warn ( severity ) ;
174+ const scope = finding . kind === "task" ? "Task" : "TaskFlow" ;
147175 lines . push (
148176 [
177+ scope . padEnd ( 8 ) ,
149178 severityCell ,
150179 finding . code . padEnd ( 22 ) ,
151- shortToken ( finding . task . taskId ) . padEnd ( ID_PAD ) ,
180+ shortToken ( finding . token ) . padEnd ( ID_PAD ) ,
152181 status ,
153182 formatAgeMs ( finding . ageMs ) . padEnd ( 8 ) ,
154183 truncate ( finding . detail , 88 ) ,
@@ -160,6 +189,56 @@ function formatAuditRows(findings: TaskAuditFinding[], rich: boolean) {
160189 return lines ;
161190}
162191
192+ function toSystemAuditFindings ( params : {
193+ severityFilter ?: TaskSystemAuditSeverity ;
194+ codeFilter ?: TaskSystemAuditCode ;
195+ } ) {
196+ const taskFindings = listTaskAuditFindings ( ) ;
197+ const flowFindings = listTaskFlowAuditFindings ( ) ;
198+ const allFindings : TaskSystemAuditFinding [ ] = [
199+ ...taskFindings . map ( ( finding ) => ( {
200+ kind : "task" as const ,
201+ severity : finding . severity ,
202+ code : finding . code ,
203+ detail : finding . detail ,
204+ ageMs : finding . ageMs ,
205+ status : finding . task . status ,
206+ token : finding . task . taskId ,
207+ task : finding . task ,
208+ } ) ) ,
209+ ...flowFindings . map ( ( finding ) => ( {
210+ kind : "task_flow" as const ,
211+ severity : finding . severity ,
212+ code : finding . code ,
213+ detail : finding . detail ,
214+ ageMs : finding . ageMs ,
215+ status : finding . flow ?. status ?? "n/a" ,
216+ token : finding . flow ?. flowId ,
217+ ...( finding . flow ? { flow : finding . flow } : { } ) ,
218+ } ) ) ,
219+ ] ;
220+ const filteredFindings = allFindings . filter ( ( finding ) => {
221+ if ( params . severityFilter && finding . severity !== params . severityFilter ) {
222+ return false ;
223+ }
224+ if ( params . codeFilter && finding . code !== params . codeFilter ) {
225+ return false ;
226+ }
227+ return true ;
228+ } ) ;
229+ return {
230+ allFindings,
231+ filteredFindings,
232+ summary : {
233+ total : allFindings . length ,
234+ errors : allFindings . filter ( ( finding ) => finding . severity === "error" ) . length ,
235+ warnings : allFindings . filter ( ( finding ) => finding . severity !== "error" ) . length ,
236+ tasks : summarizeTaskAuditFindings ( taskFindings ) ,
237+ taskFlows : summarizeTaskFlowAuditFindings ( flowFindings ) ,
238+ } ,
239+ } ;
240+ }
241+
163242export async function tasksListCommand (
164243 opts : { json ?: boolean ; runtime ?: string ; status ?: string } ,
165244 runtime : RuntimeEnv ,
@@ -308,34 +387,27 @@ export async function tasksCancelCommand(opts: { lookup: string }, runtime: Runt
308387export async function tasksAuditCommand (
309388 opts : {
310389 json ?: boolean ;
311- severity ?: TaskAuditSeverity ;
312- code ?: TaskAuditCode ;
390+ severity ?: TaskSystemAuditSeverity ;
391+ code ?: TaskSystemAuditCode ;
313392 limit ?: number ;
314393 } ,
315394 runtime : RuntimeEnv ,
316395) {
317- const severityFilter = opts . severity ?. trim ( ) as TaskAuditSeverity | undefined ;
318- const codeFilter = opts . code ?. trim ( ) as TaskAuditCode | undefined ;
319- const allFindings = listTaskAuditFindings ( ) ;
320- const findings = allFindings . filter ( ( finding ) => {
321- if ( severityFilter && finding . severity !== severityFilter ) {
322- return false ;
323- }
324- if ( codeFilter && finding . code !== codeFilter ) {
325- return false ;
326- }
327- return true ;
396+ const severityFilter = opts . severity ?. trim ( ) as TaskSystemAuditSeverity | undefined ;
397+ const codeFilter = opts . code ?. trim ( ) as TaskSystemAuditCode | undefined ;
398+ const { allFindings, filteredFindings, summary } = toSystemAuditFindings ( {
399+ severityFilter,
400+ codeFilter,
328401 } ) ;
329402 const limit = typeof opts . limit === "number" && opts . limit > 0 ? opts . limit : undefined ;
330- const displayed = limit ? findings . slice ( 0 , limit ) : findings ;
331- const summary = summarizeTaskAuditFindings ( allFindings ) ;
403+ const displayed = limit ? filteredFindings . slice ( 0 , limit ) : filteredFindings ;
332404
333405 if ( opts . json ) {
334406 runtime . log (
335407 JSON . stringify (
336408 {
337409 count : allFindings . length ,
338- filteredCount : findings . length ,
410+ filteredCount : filteredFindings . length ,
339411 displayed : displayed . length ,
340412 filters : {
341413 severity : severityFilter ?? null ,
@@ -354,11 +426,11 @@ export async function tasksAuditCommand(
354426
355427 runtime . log (
356428 info (
357- `Task audit: ${ summary . total } findings · ${ summary . errors } errors · ${ summary . warnings } warnings` ,
429+ `Tasks audit: ${ summary . total } findings · ${ summary . errors } errors · ${ summary . warnings } warnings` ,
358430 ) ,
359431 ) ;
360432 if ( severityFilter || codeFilter ) {
361- runtime . log ( info ( `Showing ${ findings . length } matching findings.` ) ) ;
433+ runtime . log ( info ( `Showing ${ filteredFindings . length } matching findings.` ) ) ;
362434 }
363435 if ( severityFilter ) {
364436 runtime . log ( info ( `Severity filter: ${ severityFilter } ` ) ) ;
@@ -369,8 +441,11 @@ export async function tasksAuditCommand(
369441 if ( limit ) {
370442 runtime . log ( info ( `Limit: ${ limit } ` ) ) ;
371443 }
444+ runtime . log (
445+ info ( `Task findings: ${ summary . tasks . total } · TaskFlow findings: ${ summary . taskFlows . total } ` ) ,
446+ ) ;
372447 if ( displayed . length === 0 ) {
373- runtime . log ( "No task audit findings." ) ;
448+ runtime . log ( "No tasks audit findings." ) ;
374449 return ;
375450 }
376451 const rich = isRich ( ) ;
@@ -384,21 +459,35 @@ export async function tasksMaintenanceCommand(
384459 runtime : RuntimeEnv ,
385460) {
386461 const auditBefore = getInspectableTaskAuditSummary ( ) ;
387- const maintenance = opts . apply
462+ const flowAuditBefore = getInspectableTaskFlowAuditSummary ( ) ;
463+ const taskMaintenance = opts . apply
388464 ? await runTaskRegistryMaintenance ( )
389465 : previewTaskRegistryMaintenance ( ) ;
466+ const flowMaintenance = opts . apply
467+ ? await runTaskFlowRegistryMaintenance ( )
468+ : previewTaskFlowRegistryMaintenance ( ) ;
390469 const summary = getInspectableTaskRegistrySummary ( ) ;
391470 const auditAfter = opts . apply ? getInspectableTaskAuditSummary ( ) : auditBefore ;
471+ const flowAuditAfter = opts . apply ? getInspectableTaskFlowAuditSummary ( ) : flowAuditBefore ;
392472
393473 if ( opts . json ) {
394474 runtime . log (
395475 JSON . stringify (
396476 {
397477 mode : opts . apply ? "apply" : "preview" ,
398- maintenance,
478+ maintenance : {
479+ tasks : taskMaintenance ,
480+ taskFlows : flowMaintenance ,
481+ } ,
399482 tasks : summary ,
400- auditBefore,
401- auditAfter,
483+ auditBefore : {
484+ tasks : auditBefore ,
485+ taskFlows : flowAuditBefore ,
486+ } ,
487+ auditAfter : {
488+ tasks : auditAfter ,
489+ taskFlows : flowAuditAfter ,
490+ } ,
402491 } ,
403492 null ,
404493 2 ,
@@ -409,18 +498,18 @@ export async function tasksMaintenanceCommand(
409498
410499 runtime . log (
411500 info (
412- `Task maintenance (${ opts . apply ? "applied" : "preview" } ): ${ maintenance . reconciled } reconcile · ${ maintenance . cleanupStamped } cleanup stamp · ${ maintenance . pruned } prune` ,
501+ `Tasks maintenance (${ opts . apply ? "applied" : "preview" } ): tasks ${ taskMaintenance . reconciled } reconcile · ${ taskMaintenance . cleanupStamped } cleanup stamp · ${ taskMaintenance . pruned } prune; task-flows ${ flowMaintenance . reconciled } reconcile · ${ flowMaintenance . pruned } prune` ,
413502 ) ,
414503 ) ;
415504 runtime . log (
416505 info (
417- `${ opts . apply ? "Task health after apply" : "Task health" } : ${ summary . byStatus . queued } queued · ${ summary . byStatus . running } running · ${ auditAfter . errors } audit errors · ${ auditAfter . warnings } audit warnings` ,
506+ `${ opts . apply ? "Tasks health after apply" : "Tasks health" } : ${ summary . byStatus . queued } queued · ${ summary . byStatus . running } running · ${ auditAfter . errors + flowAuditAfter . errors } audit errors · ${ auditAfter . warnings + flowAuditAfter . warnings } audit warnings` ,
418507 ) ,
419508 ) ;
420509 if ( opts . apply ) {
421510 runtime . log (
422511 info (
423- `Task health before apply: ${ auditBefore . errors } audit errors · ${ auditBefore . warnings } audit warnings` ,
512+ `Tasks health before apply: ${ auditBefore . errors + flowAuditBefore . errors } audit errors · ${ auditBefore . warnings + flowAuditBefore . warnings } audit warnings` ,
424513 ) ,
425514 ) ;
426515 }
0 commit comments