agent-inspect 4.0.0 → 4.2.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.
- package/CHANGELOG.md +23 -0
- package/docs/CLI.md +37 -6
- package/package.json +2 -2
- package/packages/cli/dist/chunk-5VSPJEZ7.mjs +3487 -0
- package/packages/cli/dist/chunk-5VSPJEZ7.mjs.map +1 -0
- package/packages/cli/dist/index.cjs +2951 -716
- package/packages/cli/dist/index.cjs.map +1 -1
- package/packages/cli/dist/index.mjs +639 -3428
- package/packages/cli/dist/index.mjs.map +1 -1
- package/packages/cli/dist/src-VQT7QLGV.mjs +1157 -0
- package/packages/cli/dist/src-VQT7QLGV.mjs.map +1 -0
- package/packages/core/dist/advanced.cjs +265 -8
- package/packages/core/dist/advanced.cjs.map +1 -1
- package/packages/core/dist/advanced.d.cts +79 -1
- package/packages/core/dist/advanced.d.ts +79 -1
- package/packages/core/dist/advanced.mjs +262 -9
- package/packages/core/dist/advanced.mjs.map +1 -1
|
@@ -462,6 +462,47 @@ interface CriticalPathStep {
|
|
|
462
462
|
source: SessionEdgeSource;
|
|
463
463
|
confidence: SessionConfidence;
|
|
464
464
|
}
|
|
465
|
+
/** Session lifecycle status (v4.2 RFC). */
|
|
466
|
+
type SessionStatus = "running" | "waiting_input" | "idle" | "completed" | "error" | "stale" | "unknown";
|
|
467
|
+
interface SessionLastError {
|
|
468
|
+
runId: string;
|
|
469
|
+
message: string;
|
|
470
|
+
code?: string;
|
|
471
|
+
}
|
|
472
|
+
interface SessionCheckSummary {
|
|
473
|
+
pass: number;
|
|
474
|
+
fail: number;
|
|
475
|
+
warn: number;
|
|
476
|
+
}
|
|
477
|
+
interface EnrichSessionSummaryOptions {
|
|
478
|
+
/** Reference clock for staleness (default Date.now()). */
|
|
479
|
+
nowMs?: number;
|
|
480
|
+
/** Inactivity threshold before marking a session stale (default 24h). */
|
|
481
|
+
staleThresholdMs?: number;
|
|
482
|
+
}
|
|
483
|
+
interface ActivityEntry {
|
|
484
|
+
sessionId: string;
|
|
485
|
+
status: SessionStatus;
|
|
486
|
+
summary: string;
|
|
487
|
+
lastActivity: string;
|
|
488
|
+
runCount: number;
|
|
489
|
+
}
|
|
490
|
+
interface ActivitySummary {
|
|
491
|
+
since: string;
|
|
492
|
+
sessions: number;
|
|
493
|
+
failed: number;
|
|
494
|
+
stale: number;
|
|
495
|
+
guardrailWarnings: number;
|
|
496
|
+
entries: ActivityEntry[];
|
|
497
|
+
}
|
|
498
|
+
interface BuildActivitySummaryOptions {
|
|
499
|
+
/** Duration window (e.g. 7d, 24h). Default 7d. */
|
|
500
|
+
since?: string;
|
|
501
|
+
/** Reference clock (default Date.now()). */
|
|
502
|
+
nowMs?: number;
|
|
503
|
+
/** Max entries returned (default 20). */
|
|
504
|
+
limit?: number;
|
|
505
|
+
}
|
|
465
506
|
interface SessionSummary {
|
|
466
507
|
sessionId: string;
|
|
467
508
|
runIds: string[];
|
|
@@ -469,6 +510,23 @@ interface SessionSummary {
|
|
|
469
510
|
handoffs: HandoffEdge[];
|
|
470
511
|
retries: RetryLink[];
|
|
471
512
|
criticalPath: CriticalPathStep[];
|
|
513
|
+
/** Derived session status (v4.2+). */
|
|
514
|
+
status: SessionStatus;
|
|
515
|
+
/** Earliest run start time in the session. */
|
|
516
|
+
startedAt?: number;
|
|
517
|
+
/** Latest run end time when all runs have ended. */
|
|
518
|
+
endedAt?: number;
|
|
519
|
+
/** endedAt - startedAt when both are present. */
|
|
520
|
+
durationMs?: number;
|
|
521
|
+
correlationId?: string;
|
|
522
|
+
jobId?: string;
|
|
523
|
+
workflowId?: string;
|
|
524
|
+
lastError?: SessionLastError;
|
|
525
|
+
/** ISO-8601 timestamp of the most recent run activity. */
|
|
526
|
+
lastActivity: string;
|
|
527
|
+
retryCount: number;
|
|
528
|
+
observationSummary?: string;
|
|
529
|
+
checkSummary?: SessionCheckSummary;
|
|
472
530
|
}
|
|
473
531
|
interface SessionIndex {
|
|
474
532
|
runs: SessionRunRecord[];
|
|
@@ -479,6 +537,10 @@ interface SessionIndex {
|
|
|
479
537
|
interface BuildSessionIndexOptions {
|
|
480
538
|
/** When true, group runs that share only `groupId` under a synthetic session key. */
|
|
481
539
|
correlateByGroupId?: boolean;
|
|
540
|
+
/** Reference clock for session staleness (v4.2+). */
|
|
541
|
+
nowMs?: number;
|
|
542
|
+
/** Inactivity threshold before marking a session stale (v4.2+, default 24h). */
|
|
543
|
+
staleThresholdMs?: number;
|
|
482
544
|
}
|
|
483
545
|
|
|
484
546
|
/** Extracts session/workflow metadata from a run metadata or attributes bag. */
|
|
@@ -487,6 +549,22 @@ declare function sessionKeyForRun(meta: SessionWorkflowMetadata | undefined, opt
|
|
|
487
549
|
correlateByGroupId?: boolean;
|
|
488
550
|
}): string | undefined;
|
|
489
551
|
|
|
552
|
+
/** Derives session status from run records per the v4.2 RFC (no timestamp-only causality). */
|
|
553
|
+
declare function deriveSessionStatus(runs: readonly SessionRunRecord[], options?: EnrichSessionSummaryOptions): SessionStatus;
|
|
554
|
+
/**
|
|
555
|
+
* Enriches a session summary with v4.2 derived fields (status, timing, errors).
|
|
556
|
+
* Pure function; does not read trace files.
|
|
557
|
+
*/
|
|
558
|
+
declare function enrichSessionSummary(summary: Omit<SessionSummary, "status" | "lastActivity" | "retryCount" | "startedAt" | "endedAt" | "durationMs" | "correlationId" | "jobId" | "workflowId" | "lastError" | "observationSummary" | "checkSummary">, runs: readonly SessionRunRecord[], options?: EnrichSessionSummaryOptions): SessionSummary;
|
|
559
|
+
|
|
560
|
+
/**
|
|
561
|
+
* Builds a deterministic activity summary from a session index (v4.2).
|
|
562
|
+
* Read-only; does not mutate traces or invent relationships.
|
|
563
|
+
*/
|
|
564
|
+
declare function buildActivitySummary(index: SessionIndex, options?: BuildActivitySummaryOptions): ActivitySummary;
|
|
565
|
+
/** Renders a human activity summary for terminal output. */
|
|
566
|
+
declare function renderActivitySummaryHuman(summary: ActivitySummary): string;
|
|
567
|
+
|
|
490
568
|
/** Enriches trace metadata with run_started metadata for session indexing. */
|
|
491
569
|
declare function enrichSessionRunRecord(meta: TraceMetadata): Promise<SessionRunRecord>;
|
|
492
570
|
/** Builds session run records from extracted trace metadata rows. */
|
|
@@ -565,4 +643,4 @@ declare function isAgentInspectTrace(filePath: string): Promise<boolean>;
|
|
|
565
643
|
*/
|
|
566
644
|
declare function parseDuration(duration: string): number;
|
|
567
645
|
|
|
568
|
-
export { type BuildSessionIndexOptions, type CriticalPathStep, DEFAULT_TRACE_DIR_NAME, type DurationStats, ErrorInfo, type ExplainFact, type ExplainInference, type ExplainMode, type ExplainOptions, type ExplainResult, FALLBACK_TRACE_DIR, type GroupSessionCohortsOptions, type HandoffEdge, InspectRunTree, MAX_NAME_LENGTH, MAX_TERMINAL_DEPTH, MAX_TERMINAL_NAME_LENGTH, type ParseTraceJsonlOptions, type ParseTraceJsonlResult, type ParsedDurationFilter, RUNS_DIR_NAME, RedactionProfile, type RenderTimelineOptions, type RenderWhatOptions, type ResolvedRedactionProfile, type RetryLink, RunStatus, RunSummary, type RunTimeline, type RunWhatSummary, SESSION_WORKFLOW_KEYS, type SessionCohort, type SessionCohortKind, type SessionConfidence, type SessionEdgeSource, type SessionGroup, type SessionIndex, type SessionRunRecord, type SessionScopeOptions, type SessionScopeResult, type SessionSummary, type SessionWarning, type SessionWorkflowKey, type SessionWorkflowMetadata, StepStatus, StepType, TERMINAL_INDENT, type TimelineEntry, type TimelineFocus, type TimelineOptions, TraceCorrelationMetadata, TraceDirectory, type TraceDirectoryOptions, TraceEvent, type TraceFilterOptions, type TraceJsonlFormat, TraceMetadata, TraceMetadataStatus, type TraceSearchOptions, type TraceSearchResult, type TraceSessionCheckResult, type TraceStats, type TraceStatsOptions, type TraceStatsRankedRun, type TraceStatsRankedStep, aggregateSessionCheckResults, buildLocalExplanation, buildRunSummary, buildRunTimeline, buildRunWhatSummary, buildSessionIndex, buildTraceStats, createRunId, createStepId, enrichSessionRunRecord, ensureTraceDir, extractMetadata, extractSessionWorkflowMetadata, filterMetasBySessionScope, filterTraces, formatDuration, formatError, formatTerminalName, formatTimestamp, getDefaultTraceDir, getIndent, getRunIdFromTraceFileName, getTraceFilePath, groupSessionCohorts, initializeTraceFile, isAgentInspectTrace, listTraceFiles, loadSessionRunRecords, loadTraceMetadataList, parseDuration, parseDurationFilter, parseTraceJsonl, printError, printFailedAt, printRunComplete, printRunStart, printStepComplete, printStepStart, readTraceEvents, readTraceFile, renderErrorLine, renderRunSummary, renderRunWhat, renderStepLine, renderTimeline, renderTraceStats, resolveRedactionProfile, resolveTraceDir, searchTraces, serializeEvent, sessionKeyForRun, traceMetasToSessionRunRecords, truncateName, unknownTraceFormatMessage, validateEvent, warn, writeTraceEvent };
|
|
646
|
+
export { type ActivityEntry, type ActivitySummary, type BuildActivitySummaryOptions, type BuildSessionIndexOptions, type CriticalPathStep, DEFAULT_TRACE_DIR_NAME, type DurationStats, type EnrichSessionSummaryOptions, ErrorInfo, type ExplainFact, type ExplainInference, type ExplainMode, type ExplainOptions, type ExplainResult, FALLBACK_TRACE_DIR, type GroupSessionCohortsOptions, type HandoffEdge, InspectRunTree, MAX_NAME_LENGTH, MAX_TERMINAL_DEPTH, MAX_TERMINAL_NAME_LENGTH, type ParseTraceJsonlOptions, type ParseTraceJsonlResult, type ParsedDurationFilter, RUNS_DIR_NAME, RedactionProfile, type RenderTimelineOptions, type RenderWhatOptions, type ResolvedRedactionProfile, type RetryLink, RunStatus, RunSummary, type RunTimeline, type RunWhatSummary, SESSION_WORKFLOW_KEYS, type SessionCheckSummary, type SessionCohort, type SessionCohortKind, type SessionConfidence, type SessionEdgeSource, type SessionGroup, type SessionIndex, type SessionLastError, type SessionRunRecord, type SessionScopeOptions, type SessionScopeResult, type SessionStatus, type SessionSummary, type SessionWarning, type SessionWorkflowKey, type SessionWorkflowMetadata, StepStatus, StepType, TERMINAL_INDENT, type TimelineEntry, type TimelineFocus, type TimelineOptions, TraceCorrelationMetadata, TraceDirectory, type TraceDirectoryOptions, TraceEvent, type TraceFilterOptions, type TraceJsonlFormat, TraceMetadata, TraceMetadataStatus, type TraceSearchOptions, type TraceSearchResult, type TraceSessionCheckResult, type TraceStats, type TraceStatsOptions, type TraceStatsRankedRun, type TraceStatsRankedStep, aggregateSessionCheckResults, buildActivitySummary, buildLocalExplanation, buildRunSummary, buildRunTimeline, buildRunWhatSummary, buildSessionIndex, buildTraceStats, createRunId, createStepId, deriveSessionStatus, enrichSessionRunRecord, enrichSessionSummary, ensureTraceDir, extractMetadata, extractSessionWorkflowMetadata, filterMetasBySessionScope, filterTraces, formatDuration, formatError, formatTerminalName, formatTimestamp, getDefaultTraceDir, getIndent, getRunIdFromTraceFileName, getTraceFilePath, groupSessionCohorts, initializeTraceFile, isAgentInspectTrace, listTraceFiles, loadSessionRunRecords, loadTraceMetadataList, parseDuration, parseDurationFilter, parseTraceJsonl, printError, printFailedAt, printRunComplete, printRunStart, printStepComplete, printStepStart, readTraceEvents, readTraceFile, renderActivitySummaryHuman, renderErrorLine, renderRunSummary, renderRunWhat, renderStepLine, renderTimeline, renderTraceStats, resolveRedactionProfile, resolveTraceDir, searchTraces, serializeEvent, sessionKeyForRun, traceMetasToSessionRunRecords, truncateName, unknownTraceFormatMessage, validateEvent, warn, writeTraceEvent };
|
|
@@ -462,6 +462,47 @@ interface CriticalPathStep {
|
|
|
462
462
|
source: SessionEdgeSource;
|
|
463
463
|
confidence: SessionConfidence;
|
|
464
464
|
}
|
|
465
|
+
/** Session lifecycle status (v4.2 RFC). */
|
|
466
|
+
type SessionStatus = "running" | "waiting_input" | "idle" | "completed" | "error" | "stale" | "unknown";
|
|
467
|
+
interface SessionLastError {
|
|
468
|
+
runId: string;
|
|
469
|
+
message: string;
|
|
470
|
+
code?: string;
|
|
471
|
+
}
|
|
472
|
+
interface SessionCheckSummary {
|
|
473
|
+
pass: number;
|
|
474
|
+
fail: number;
|
|
475
|
+
warn: number;
|
|
476
|
+
}
|
|
477
|
+
interface EnrichSessionSummaryOptions {
|
|
478
|
+
/** Reference clock for staleness (default Date.now()). */
|
|
479
|
+
nowMs?: number;
|
|
480
|
+
/** Inactivity threshold before marking a session stale (default 24h). */
|
|
481
|
+
staleThresholdMs?: number;
|
|
482
|
+
}
|
|
483
|
+
interface ActivityEntry {
|
|
484
|
+
sessionId: string;
|
|
485
|
+
status: SessionStatus;
|
|
486
|
+
summary: string;
|
|
487
|
+
lastActivity: string;
|
|
488
|
+
runCount: number;
|
|
489
|
+
}
|
|
490
|
+
interface ActivitySummary {
|
|
491
|
+
since: string;
|
|
492
|
+
sessions: number;
|
|
493
|
+
failed: number;
|
|
494
|
+
stale: number;
|
|
495
|
+
guardrailWarnings: number;
|
|
496
|
+
entries: ActivityEntry[];
|
|
497
|
+
}
|
|
498
|
+
interface BuildActivitySummaryOptions {
|
|
499
|
+
/** Duration window (e.g. 7d, 24h). Default 7d. */
|
|
500
|
+
since?: string;
|
|
501
|
+
/** Reference clock (default Date.now()). */
|
|
502
|
+
nowMs?: number;
|
|
503
|
+
/** Max entries returned (default 20). */
|
|
504
|
+
limit?: number;
|
|
505
|
+
}
|
|
465
506
|
interface SessionSummary {
|
|
466
507
|
sessionId: string;
|
|
467
508
|
runIds: string[];
|
|
@@ -469,6 +510,23 @@ interface SessionSummary {
|
|
|
469
510
|
handoffs: HandoffEdge[];
|
|
470
511
|
retries: RetryLink[];
|
|
471
512
|
criticalPath: CriticalPathStep[];
|
|
513
|
+
/** Derived session status (v4.2+). */
|
|
514
|
+
status: SessionStatus;
|
|
515
|
+
/** Earliest run start time in the session. */
|
|
516
|
+
startedAt?: number;
|
|
517
|
+
/** Latest run end time when all runs have ended. */
|
|
518
|
+
endedAt?: number;
|
|
519
|
+
/** endedAt - startedAt when both are present. */
|
|
520
|
+
durationMs?: number;
|
|
521
|
+
correlationId?: string;
|
|
522
|
+
jobId?: string;
|
|
523
|
+
workflowId?: string;
|
|
524
|
+
lastError?: SessionLastError;
|
|
525
|
+
/** ISO-8601 timestamp of the most recent run activity. */
|
|
526
|
+
lastActivity: string;
|
|
527
|
+
retryCount: number;
|
|
528
|
+
observationSummary?: string;
|
|
529
|
+
checkSummary?: SessionCheckSummary;
|
|
472
530
|
}
|
|
473
531
|
interface SessionIndex {
|
|
474
532
|
runs: SessionRunRecord[];
|
|
@@ -479,6 +537,10 @@ interface SessionIndex {
|
|
|
479
537
|
interface BuildSessionIndexOptions {
|
|
480
538
|
/** When true, group runs that share only `groupId` under a synthetic session key. */
|
|
481
539
|
correlateByGroupId?: boolean;
|
|
540
|
+
/** Reference clock for session staleness (v4.2+). */
|
|
541
|
+
nowMs?: number;
|
|
542
|
+
/** Inactivity threshold before marking a session stale (v4.2+, default 24h). */
|
|
543
|
+
staleThresholdMs?: number;
|
|
482
544
|
}
|
|
483
545
|
|
|
484
546
|
/** Extracts session/workflow metadata from a run metadata or attributes bag. */
|
|
@@ -487,6 +549,22 @@ declare function sessionKeyForRun(meta: SessionWorkflowMetadata | undefined, opt
|
|
|
487
549
|
correlateByGroupId?: boolean;
|
|
488
550
|
}): string | undefined;
|
|
489
551
|
|
|
552
|
+
/** Derives session status from run records per the v4.2 RFC (no timestamp-only causality). */
|
|
553
|
+
declare function deriveSessionStatus(runs: readonly SessionRunRecord[], options?: EnrichSessionSummaryOptions): SessionStatus;
|
|
554
|
+
/**
|
|
555
|
+
* Enriches a session summary with v4.2 derived fields (status, timing, errors).
|
|
556
|
+
* Pure function; does not read trace files.
|
|
557
|
+
*/
|
|
558
|
+
declare function enrichSessionSummary(summary: Omit<SessionSummary, "status" | "lastActivity" | "retryCount" | "startedAt" | "endedAt" | "durationMs" | "correlationId" | "jobId" | "workflowId" | "lastError" | "observationSummary" | "checkSummary">, runs: readonly SessionRunRecord[], options?: EnrichSessionSummaryOptions): SessionSummary;
|
|
559
|
+
|
|
560
|
+
/**
|
|
561
|
+
* Builds a deterministic activity summary from a session index (v4.2).
|
|
562
|
+
* Read-only; does not mutate traces or invent relationships.
|
|
563
|
+
*/
|
|
564
|
+
declare function buildActivitySummary(index: SessionIndex, options?: BuildActivitySummaryOptions): ActivitySummary;
|
|
565
|
+
/** Renders a human activity summary for terminal output. */
|
|
566
|
+
declare function renderActivitySummaryHuman(summary: ActivitySummary): string;
|
|
567
|
+
|
|
490
568
|
/** Enriches trace metadata with run_started metadata for session indexing. */
|
|
491
569
|
declare function enrichSessionRunRecord(meta: TraceMetadata): Promise<SessionRunRecord>;
|
|
492
570
|
/** Builds session run records from extracted trace metadata rows. */
|
|
@@ -565,4 +643,4 @@ declare function isAgentInspectTrace(filePath: string): Promise<boolean>;
|
|
|
565
643
|
*/
|
|
566
644
|
declare function parseDuration(duration: string): number;
|
|
567
645
|
|
|
568
|
-
export { type BuildSessionIndexOptions, type CriticalPathStep, DEFAULT_TRACE_DIR_NAME, type DurationStats, ErrorInfo, type ExplainFact, type ExplainInference, type ExplainMode, type ExplainOptions, type ExplainResult, FALLBACK_TRACE_DIR, type GroupSessionCohortsOptions, type HandoffEdge, InspectRunTree, MAX_NAME_LENGTH, MAX_TERMINAL_DEPTH, MAX_TERMINAL_NAME_LENGTH, type ParseTraceJsonlOptions, type ParseTraceJsonlResult, type ParsedDurationFilter, RUNS_DIR_NAME, RedactionProfile, type RenderTimelineOptions, type RenderWhatOptions, type ResolvedRedactionProfile, type RetryLink, RunStatus, RunSummary, type RunTimeline, type RunWhatSummary, SESSION_WORKFLOW_KEYS, type SessionCohort, type SessionCohortKind, type SessionConfidence, type SessionEdgeSource, type SessionGroup, type SessionIndex, type SessionRunRecord, type SessionScopeOptions, type SessionScopeResult, type SessionSummary, type SessionWarning, type SessionWorkflowKey, type SessionWorkflowMetadata, StepStatus, StepType, TERMINAL_INDENT, type TimelineEntry, type TimelineFocus, type TimelineOptions, TraceCorrelationMetadata, TraceDirectory, type TraceDirectoryOptions, TraceEvent, type TraceFilterOptions, type TraceJsonlFormat, TraceMetadata, TraceMetadataStatus, type TraceSearchOptions, type TraceSearchResult, type TraceSessionCheckResult, type TraceStats, type TraceStatsOptions, type TraceStatsRankedRun, type TraceStatsRankedStep, aggregateSessionCheckResults, buildLocalExplanation, buildRunSummary, buildRunTimeline, buildRunWhatSummary, buildSessionIndex, buildTraceStats, createRunId, createStepId, enrichSessionRunRecord, ensureTraceDir, extractMetadata, extractSessionWorkflowMetadata, filterMetasBySessionScope, filterTraces, formatDuration, formatError, formatTerminalName, formatTimestamp, getDefaultTraceDir, getIndent, getRunIdFromTraceFileName, getTraceFilePath, groupSessionCohorts, initializeTraceFile, isAgentInspectTrace, listTraceFiles, loadSessionRunRecords, loadTraceMetadataList, parseDuration, parseDurationFilter, parseTraceJsonl, printError, printFailedAt, printRunComplete, printRunStart, printStepComplete, printStepStart, readTraceEvents, readTraceFile, renderErrorLine, renderRunSummary, renderRunWhat, renderStepLine, renderTimeline, renderTraceStats, resolveRedactionProfile, resolveTraceDir, searchTraces, serializeEvent, sessionKeyForRun, traceMetasToSessionRunRecords, truncateName, unknownTraceFormatMessage, validateEvent, warn, writeTraceEvent };
|
|
646
|
+
export { type ActivityEntry, type ActivitySummary, type BuildActivitySummaryOptions, type BuildSessionIndexOptions, type CriticalPathStep, DEFAULT_TRACE_DIR_NAME, type DurationStats, type EnrichSessionSummaryOptions, ErrorInfo, type ExplainFact, type ExplainInference, type ExplainMode, type ExplainOptions, type ExplainResult, FALLBACK_TRACE_DIR, type GroupSessionCohortsOptions, type HandoffEdge, InspectRunTree, MAX_NAME_LENGTH, MAX_TERMINAL_DEPTH, MAX_TERMINAL_NAME_LENGTH, type ParseTraceJsonlOptions, type ParseTraceJsonlResult, type ParsedDurationFilter, RUNS_DIR_NAME, RedactionProfile, type RenderTimelineOptions, type RenderWhatOptions, type ResolvedRedactionProfile, type RetryLink, RunStatus, RunSummary, type RunTimeline, type RunWhatSummary, SESSION_WORKFLOW_KEYS, type SessionCheckSummary, type SessionCohort, type SessionCohortKind, type SessionConfidence, type SessionEdgeSource, type SessionGroup, type SessionIndex, type SessionLastError, type SessionRunRecord, type SessionScopeOptions, type SessionScopeResult, type SessionStatus, type SessionSummary, type SessionWarning, type SessionWorkflowKey, type SessionWorkflowMetadata, StepStatus, StepType, TERMINAL_INDENT, type TimelineEntry, type TimelineFocus, type TimelineOptions, TraceCorrelationMetadata, TraceDirectory, type TraceDirectoryOptions, TraceEvent, type TraceFilterOptions, type TraceJsonlFormat, TraceMetadata, TraceMetadataStatus, type TraceSearchOptions, type TraceSearchResult, type TraceSessionCheckResult, type TraceStats, type TraceStatsOptions, type TraceStatsRankedRun, type TraceStatsRankedStep, aggregateSessionCheckResults, buildActivitySummary, buildLocalExplanation, buildRunSummary, buildRunTimeline, buildRunWhatSummary, buildSessionIndex, buildTraceStats, createRunId, createStepId, deriveSessionStatus, enrichSessionRunRecord, enrichSessionSummary, ensureTraceDir, extractMetadata, extractSessionWorkflowMetadata, filterMetasBySessionScope, filterTraces, formatDuration, formatError, formatTerminalName, formatTimestamp, getDefaultTraceDir, getIndent, getRunIdFromTraceFileName, getTraceFilePath, groupSessionCohorts, initializeTraceFile, isAgentInspectTrace, listTraceFiles, loadSessionRunRecords, loadTraceMetadataList, parseDuration, parseDurationFilter, parseTraceJsonl, printError, printFailedAt, printRunComplete, printRunStart, printStepComplete, printStepStart, readTraceEvents, readTraceFile, renderActivitySummaryHuman, renderErrorLine, renderRunSummary, renderRunWhat, renderStepLine, renderTimeline, renderTraceStats, resolveRedactionProfile, resolveTraceDir, searchTraces, serializeEvent, sessionKeyForRun, traceMetasToSessionRunRecords, truncateName, unknownTraceFormatMessage, validateEvent, warn, writeTraceEvent };
|
|
@@ -644,6 +644,252 @@ function sessionKeyForRun(meta, options) {
|
|
|
644
644
|
return void 0;
|
|
645
645
|
}
|
|
646
646
|
|
|
647
|
+
// packages/core/src/sessions/status.ts
|
|
648
|
+
var DEFAULT_STALE_THRESHOLD_MS = 864e5;
|
|
649
|
+
var EXPLICIT_STATUS_PRIORITY = {
|
|
650
|
+
error: 5,
|
|
651
|
+
waiting_input: 4,
|
|
652
|
+
idle: 3,
|
|
653
|
+
stale: 2,
|
|
654
|
+
completed: 1
|
|
655
|
+
};
|
|
656
|
+
var EXPLICIT_SESSION_STATUSES = /* @__PURE__ */ new Set([
|
|
657
|
+
"running",
|
|
658
|
+
"waiting_input",
|
|
659
|
+
"idle",
|
|
660
|
+
"completed",
|
|
661
|
+
"error",
|
|
662
|
+
"stale",
|
|
663
|
+
"unknown"
|
|
664
|
+
]);
|
|
665
|
+
function isExplicitSessionStatus(value) {
|
|
666
|
+
return typeof value === "string" && EXPLICIT_SESSION_STATUSES.has(value);
|
|
667
|
+
}
|
|
668
|
+
function activityMs(run) {
|
|
669
|
+
return run.endedAt ?? run.startedAt ?? 0;
|
|
670
|
+
}
|
|
671
|
+
function latestActivityMs(runs) {
|
|
672
|
+
let latest = 0;
|
|
673
|
+
for (const run of runs) {
|
|
674
|
+
const ms = activityMs(run);
|
|
675
|
+
if (ms > latest) latest = ms;
|
|
676
|
+
}
|
|
677
|
+
return latest;
|
|
678
|
+
}
|
|
679
|
+
function earliestStart(runs) {
|
|
680
|
+
let earliest;
|
|
681
|
+
for (const run of runs) {
|
|
682
|
+
if (run.startedAt === void 0) continue;
|
|
683
|
+
if (earliest === void 0 || run.startedAt < earliest) {
|
|
684
|
+
earliest = run.startedAt;
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
return earliest;
|
|
688
|
+
}
|
|
689
|
+
function latestEndWhenAllEnded(runs) {
|
|
690
|
+
if (runs.length === 0) return void 0;
|
|
691
|
+
let latest;
|
|
692
|
+
for (const run of runs) {
|
|
693
|
+
if (run.endedAt === void 0) return void 0;
|
|
694
|
+
if (latest === void 0 || run.endedAt > latest) latest = run.endedAt;
|
|
695
|
+
}
|
|
696
|
+
return latest;
|
|
697
|
+
}
|
|
698
|
+
function pickExplicitStatus(runs) {
|
|
699
|
+
let best;
|
|
700
|
+
let bestPriority = 0;
|
|
701
|
+
for (const run of runs) {
|
|
702
|
+
const raw = run.metadata?.sessionStatus;
|
|
703
|
+
if (!isExplicitSessionStatus(raw)) continue;
|
|
704
|
+
const priority = EXPLICIT_STATUS_PRIORITY[raw] ?? 0;
|
|
705
|
+
if (priority > bestPriority) {
|
|
706
|
+
bestPriority = priority;
|
|
707
|
+
best = raw;
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
return best;
|
|
711
|
+
}
|
|
712
|
+
function deriveLastError(runs) {
|
|
713
|
+
const errorRuns = runs.filter((run) => run.status === "error").sort((a, b) => activityMs(b) - activityMs(a));
|
|
714
|
+
const latest = errorRuns[0];
|
|
715
|
+
if (!latest) return void 0;
|
|
716
|
+
const meta = latest.metadata ?? {};
|
|
717
|
+
const message = typeof meta.errorMessage === "string" && meta.errorMessage.trim() !== "" ? meta.errorMessage.trim() : latest.name ?? latest.runId;
|
|
718
|
+
const code = typeof meta.errorCode === "string" && meta.errorCode.trim() !== "" ? meta.errorCode.trim() : void 0;
|
|
719
|
+
return { runId: latest.runId, message, code };
|
|
720
|
+
}
|
|
721
|
+
function deriveCheckSummary(runs) {
|
|
722
|
+
let pass = 0;
|
|
723
|
+
let fail = 0;
|
|
724
|
+
let warn2 = 0;
|
|
725
|
+
let found = false;
|
|
726
|
+
for (const run of runs) {
|
|
727
|
+
const summary = run.metadata?.checkSummary;
|
|
728
|
+
if (!summary || typeof summary !== "object") continue;
|
|
729
|
+
const record = summary;
|
|
730
|
+
if (typeof record.pass === "number") {
|
|
731
|
+
pass += record.pass;
|
|
732
|
+
found = true;
|
|
733
|
+
}
|
|
734
|
+
if (typeof record.fail === "number") {
|
|
735
|
+
fail += record.fail;
|
|
736
|
+
found = true;
|
|
737
|
+
}
|
|
738
|
+
if (typeof record.warn === "number") {
|
|
739
|
+
warn2 += record.warn;
|
|
740
|
+
found = true;
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
return found ? { pass, fail, warn: warn2 } : void 0;
|
|
744
|
+
}
|
|
745
|
+
function deriveObservationSummary(runs) {
|
|
746
|
+
for (const run of [...runs].sort((a, b) => activityMs(b) - activityMs(a))) {
|
|
747
|
+
const value = run.metadata?.observationSummary;
|
|
748
|
+
if (typeof value === "string" && value.trim() !== "") {
|
|
749
|
+
return value.trim();
|
|
750
|
+
}
|
|
751
|
+
}
|
|
752
|
+
return void 0;
|
|
753
|
+
}
|
|
754
|
+
function deriveSessionStatus(runs, options = {}) {
|
|
755
|
+
if (runs.length === 0) return "unknown";
|
|
756
|
+
if (runs.some((run) => run.status === "running")) return "running";
|
|
757
|
+
const explicit = pickExplicitStatus(runs);
|
|
758
|
+
if (explicit && explicit !== "running") return explicit;
|
|
759
|
+
if (runs.some((run) => run.status === "error")) return "error";
|
|
760
|
+
if (runs.every((run) => run.status === "success")) return "completed";
|
|
761
|
+
const nowMs = options.nowMs ?? Date.now();
|
|
762
|
+
const staleThresholdMs = options.staleThresholdMs ?? DEFAULT_STALE_THRESHOLD_MS;
|
|
763
|
+
const lastMs = latestActivityMs(runs);
|
|
764
|
+
if (lastMs > 0 && nowMs - lastMs > staleThresholdMs) return "stale";
|
|
765
|
+
return "unknown";
|
|
766
|
+
}
|
|
767
|
+
function enrichSessionSummary(summary, runs, options = {}) {
|
|
768
|
+
const sessionRuns = runs.filter((run) => summary.runIds.includes(run.runId)).sort((a, b) => a.runId.localeCompare(b.runId));
|
|
769
|
+
const startedAt = earliestStart(sessionRuns);
|
|
770
|
+
const endedAt = latestEndWhenAllEnded(sessionRuns);
|
|
771
|
+
const durationMs = startedAt !== void 0 && endedAt !== void 0 ? endedAt - startedAt : void 0;
|
|
772
|
+
let correlationId;
|
|
773
|
+
let jobId;
|
|
774
|
+
let workflowId;
|
|
775
|
+
for (const run of sessionRuns) {
|
|
776
|
+
const meta = extractSessionWorkflowMetadata(run.metadata);
|
|
777
|
+
if (!correlationId && meta?.correlationId) correlationId = meta.correlationId;
|
|
778
|
+
if (!jobId && meta?.jobId) jobId = meta.jobId;
|
|
779
|
+
if (!workflowId && meta?.workflowName) workflowId = meta.workflowName;
|
|
780
|
+
else if (!workflowId && meta?.workflowStep) workflowId = meta.workflowStep;
|
|
781
|
+
}
|
|
782
|
+
const lastMs = latestActivityMs(sessionRuns);
|
|
783
|
+
const lastActivity = lastMs > 0 ? new Date(lastMs).toISOString() : (/* @__PURE__ */ new Date(0)).toISOString();
|
|
784
|
+
const retryCount = summary.retries.filter(
|
|
785
|
+
(retry) => retry.retryOf !== void 0 || (retry.attempt ?? 0) > 1
|
|
786
|
+
).length;
|
|
787
|
+
return {
|
|
788
|
+
...summary,
|
|
789
|
+
status: deriveSessionStatus(sessionRuns, options),
|
|
790
|
+
startedAt,
|
|
791
|
+
endedAt,
|
|
792
|
+
durationMs,
|
|
793
|
+
correlationId,
|
|
794
|
+
jobId,
|
|
795
|
+
workflowId,
|
|
796
|
+
lastError: deriveLastError(sessionRuns),
|
|
797
|
+
lastActivity,
|
|
798
|
+
retryCount,
|
|
799
|
+
observationSummary: deriveObservationSummary(sessionRuns),
|
|
800
|
+
checkSummary: deriveCheckSummary(sessionRuns)
|
|
801
|
+
};
|
|
802
|
+
}
|
|
803
|
+
|
|
804
|
+
// packages/core/src/sessions/activity.ts
|
|
805
|
+
function statusLine(session) {
|
|
806
|
+
const name = session.workflowId ?? session.correlationId ?? session.sessionId;
|
|
807
|
+
const status = session.status;
|
|
808
|
+
if (session.lastError) {
|
|
809
|
+
return `${name} session ${session.sessionId} failed at ${session.lastError.message}`;
|
|
810
|
+
}
|
|
811
|
+
if (session.observationSummary) {
|
|
812
|
+
return `${name} session ${session.sessionId} ${status} with observation warning`;
|
|
813
|
+
}
|
|
814
|
+
return `${name} session ${session.sessionId} ${status}`;
|
|
815
|
+
}
|
|
816
|
+
function parseSinceMs(since, nowMs) {
|
|
817
|
+
if (!since || since.trim() === "") return nowMs - 7 * 864e5;
|
|
818
|
+
const trimmed = since.trim().toLowerCase();
|
|
819
|
+
const match = /^(\d+)([smhd])$/.exec(trimmed);
|
|
820
|
+
if (!match) return nowMs - 7 * 864e5;
|
|
821
|
+
const amount = Number.parseInt(match[1], 10);
|
|
822
|
+
const unit = match[2];
|
|
823
|
+
const mult = unit === "s" ? 1e3 : unit === "m" ? 6e4 : unit === "h" ? 36e5 : 864e5;
|
|
824
|
+
return nowMs - amount * mult;
|
|
825
|
+
}
|
|
826
|
+
function isFailed(status) {
|
|
827
|
+
return status === "error";
|
|
828
|
+
}
|
|
829
|
+
function isStale(status) {
|
|
830
|
+
return status === "stale";
|
|
831
|
+
}
|
|
832
|
+
function guardrailWarnings(session) {
|
|
833
|
+
const summary = session.checkSummary;
|
|
834
|
+
if (!summary) return 0;
|
|
835
|
+
return summary.warn;
|
|
836
|
+
}
|
|
837
|
+
function buildActivitySummary(index, options = {}) {
|
|
838
|
+
const nowMs = options.nowMs ?? Date.now();
|
|
839
|
+
const sinceMs = parseSinceMs(options.since, nowMs);
|
|
840
|
+
const sinceIso = new Date(sinceMs).toISOString();
|
|
841
|
+
const limit = Number.isInteger(options.limit) && options.limit > 0 ? options.limit : 20;
|
|
842
|
+
const inWindow = index.sessions.filter((session) => {
|
|
843
|
+
const activityMs2 = Date.parse(session.lastActivity);
|
|
844
|
+
return Number.isFinite(activityMs2) && activityMs2 >= sinceMs;
|
|
845
|
+
});
|
|
846
|
+
const entries = [...inWindow].sort((a, b) => Date.parse(b.lastActivity) - Date.parse(a.lastActivity)).slice(0, limit).map((session) => ({
|
|
847
|
+
sessionId: session.sessionId,
|
|
848
|
+
status: session.status,
|
|
849
|
+
summary: statusLine(session),
|
|
850
|
+
lastActivity: session.lastActivity,
|
|
851
|
+
runCount: session.runIds.length
|
|
852
|
+
}));
|
|
853
|
+
let failed = 0;
|
|
854
|
+
let stale = 0;
|
|
855
|
+
let guardrailWarningTotal = 0;
|
|
856
|
+
for (const session of inWindow) {
|
|
857
|
+
if (isFailed(session.status)) failed += 1;
|
|
858
|
+
if (isStale(session.status)) stale += 1;
|
|
859
|
+
guardrailWarningTotal += guardrailWarnings(session);
|
|
860
|
+
}
|
|
861
|
+
return {
|
|
862
|
+
since: sinceIso,
|
|
863
|
+
sessions: inWindow.length,
|
|
864
|
+
failed,
|
|
865
|
+
stale,
|
|
866
|
+
guardrailWarnings: guardrailWarningTotal,
|
|
867
|
+
entries
|
|
868
|
+
};
|
|
869
|
+
}
|
|
870
|
+
function renderActivitySummaryHuman(summary) {
|
|
871
|
+
const lines = [];
|
|
872
|
+
const todayStart = /* @__PURE__ */ new Date();
|
|
873
|
+
todayStart.setHours(0, 0, 0, 0);
|
|
874
|
+
const todayMs = todayStart.getTime();
|
|
875
|
+
const today = summary.entries.filter(
|
|
876
|
+
(entry) => Date.parse(entry.lastActivity) >= todayMs
|
|
877
|
+
);
|
|
878
|
+
if (today.length > 0) {
|
|
879
|
+
lines.push("Today");
|
|
880
|
+
for (const entry of today) {
|
|
881
|
+
lines.push(` ${entry.summary}`);
|
|
882
|
+
}
|
|
883
|
+
lines.push("");
|
|
884
|
+
}
|
|
885
|
+
lines.push(`Since ${summary.since}`);
|
|
886
|
+
lines.push(` ${summary.sessions} sessions`);
|
|
887
|
+
lines.push(` ${summary.failed} failed`);
|
|
888
|
+
lines.push(` ${summary.stale} stale`);
|
|
889
|
+
lines.push(` ${summary.guardrailWarnings} guardrail warnings`);
|
|
890
|
+
return lines.join("\n");
|
|
891
|
+
}
|
|
892
|
+
|
|
647
893
|
// packages/core/src/sessions/types.ts
|
|
648
894
|
var SESSION_WORKFLOW_KEYS = [
|
|
649
895
|
"sessionId",
|
|
@@ -1126,14 +1372,21 @@ function buildSessionIndex(inputRuns, options = {}) {
|
|
|
1126
1372
|
sessionId
|
|
1127
1373
|
});
|
|
1128
1374
|
}
|
|
1129
|
-
return
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1375
|
+
return enrichSessionSummary(
|
|
1376
|
+
{
|
|
1377
|
+
sessionId,
|
|
1378
|
+
runIds,
|
|
1379
|
+
groups,
|
|
1380
|
+
handoffs,
|
|
1381
|
+
retries,
|
|
1382
|
+
criticalPath
|
|
1383
|
+
},
|
|
1384
|
+
runs,
|
|
1385
|
+
{
|
|
1386
|
+
nowMs: options.nowMs,
|
|
1387
|
+
staleThresholdMs: options.staleThresholdMs
|
|
1388
|
+
}
|
|
1389
|
+
);
|
|
1137
1390
|
});
|
|
1138
1391
|
if (sessions.length === 0 && runs.length > 0) {
|
|
1139
1392
|
warnings.push({
|
|
@@ -1197,6 +1450,6 @@ async function isAgentInspectTrace(filePath) {
|
|
|
1197
1450
|
}
|
|
1198
1451
|
}
|
|
1199
1452
|
|
|
1200
|
-
export { SESSION_WORKFLOW_KEYS, aggregateSessionCheckResults, buildLocalExplanation, buildSessionIndex, buildTraceStats, enrichSessionRunRecord, extractSessionWorkflowMetadata, filterMetasBySessionScope, filterTraces, groupSessionCohorts, isAgentInspectTrace, loadSessionRunRecords, loadTraceMetadataList, parseDurationFilter, renderTraceStats, searchTraces, sessionKeyForRun, traceMetasToSessionRunRecords };
|
|
1453
|
+
export { SESSION_WORKFLOW_KEYS, aggregateSessionCheckResults, buildActivitySummary, buildLocalExplanation, buildSessionIndex, buildTraceStats, deriveSessionStatus, enrichSessionRunRecord, enrichSessionSummary, extractSessionWorkflowMetadata, filterMetasBySessionScope, filterTraces, groupSessionCohorts, isAgentInspectTrace, loadSessionRunRecords, loadTraceMetadataList, parseDurationFilter, renderActivitySummaryHuman, renderTraceStats, searchTraces, sessionKeyForRun, traceMetasToSessionRunRecords };
|
|
1201
1454
|
//# sourceMappingURL=advanced.mjs.map
|
|
1202
1455
|
//# sourceMappingURL=advanced.mjs.map
|