agent-inspect 1.4.0 → 1.6.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 (111) hide show
  1. package/CHANGELOG.md +63 -0
  2. package/README.md +34 -6
  3. package/docs/ADAPTERS.md +6 -0
  4. package/docs/API.md +132 -9
  5. package/docs/ARCHITECTURE.md +4 -0
  6. package/docs/CLI.md +98 -5
  7. package/docs/DIFF.md +8 -0
  8. package/docs/EXPORTS.md +13 -0
  9. package/docs/GETTING-STARTED.md +19 -1
  10. package/docs/KNOWN-ISSUES.md +8 -1
  11. package/docs/LIMITATIONS.md +13 -2
  12. package/docs/LOGS.md +22 -0
  13. package/docs/SCHEMA.md +19 -7
  14. package/docs/SCREENSHOTS.md +190 -9
  15. package/package.json +71 -1
  16. package/packages/cli/dist/index.cjs +7121 -3986
  17. package/packages/cli/dist/index.cjs.map +1 -1
  18. package/packages/cli/dist/index.mjs +7122 -3987
  19. package/packages/cli/dist/index.mjs.map +1 -1
  20. package/packages/core/dist/advanced.cjs +2258 -0
  21. package/packages/core/dist/advanced.cjs.map +1 -0
  22. package/packages/core/dist/advanced.d.cts +254 -0
  23. package/packages/core/dist/advanced.d.ts +254 -0
  24. package/packages/core/dist/advanced.mjs +11 -0
  25. package/packages/core/dist/advanced.mjs.map +1 -0
  26. package/packages/core/dist/chunk-57S5D6HR.mjs +655 -0
  27. package/packages/core/dist/chunk-57S5D6HR.mjs.map +1 -0
  28. package/packages/core/dist/chunk-6QSLZCBJ.mjs +743 -0
  29. package/packages/core/dist/chunk-6QSLZCBJ.mjs.map +1 -0
  30. package/packages/core/dist/chunk-6SZPTECC.mjs +342 -0
  31. package/packages/core/dist/chunk-6SZPTECC.mjs.map +1 -0
  32. package/packages/core/dist/chunk-74XZ6N7Q.mjs +409 -0
  33. package/packages/core/dist/chunk-74XZ6N7Q.mjs.map +1 -0
  34. package/packages/core/dist/chunk-7TGZLWEE.mjs +35 -0
  35. package/packages/core/dist/chunk-7TGZLWEE.mjs.map +1 -0
  36. package/packages/core/dist/chunk-BT7CATSD.mjs +497 -0
  37. package/packages/core/dist/chunk-BT7CATSD.mjs.map +1 -0
  38. package/packages/core/dist/chunk-E5F2LQCX.mjs +83 -0
  39. package/packages/core/dist/chunk-E5F2LQCX.mjs.map +1 -0
  40. package/packages/core/dist/chunk-EDTQHZPM.mjs +88 -0
  41. package/packages/core/dist/chunk-EDTQHZPM.mjs.map +1 -0
  42. package/packages/core/dist/chunk-HR7G62IE.mjs +785 -0
  43. package/packages/core/dist/chunk-HR7G62IE.mjs.map +1 -0
  44. package/packages/core/dist/chunk-HY7H3CQM.mjs +127 -0
  45. package/packages/core/dist/chunk-HY7H3CQM.mjs.map +1 -0
  46. package/packages/core/dist/chunk-S4YWKV4G.mjs +48 -0
  47. package/packages/core/dist/chunk-S4YWKV4G.mjs.map +1 -0
  48. package/packages/core/dist/chunk-TFLPUZ56.mjs +1571 -0
  49. package/packages/core/dist/chunk-TFLPUZ56.mjs.map +1 -0
  50. package/packages/core/dist/chunk-TZISEVLQ.mjs +390 -0
  51. package/packages/core/dist/chunk-TZISEVLQ.mjs.map +1 -0
  52. package/packages/core/dist/chunk-U2BGPESY.mjs +150 -0
  53. package/packages/core/dist/chunk-U2BGPESY.mjs.map +1 -0
  54. package/packages/core/dist/chunk-VTIB5MDK.mjs +304 -0
  55. package/packages/core/dist/chunk-VTIB5MDK.mjs.map +1 -0
  56. package/packages/core/dist/chunk-VU6O5QAH.mjs +99 -0
  57. package/packages/core/dist/chunk-VU6O5QAH.mjs.map +1 -0
  58. package/packages/core/dist/chunk-Y56BPA3B.mjs +990 -0
  59. package/packages/core/dist/chunk-Y56BPA3B.mjs.map +1 -0
  60. package/packages/core/dist/chunk-YWAOOXLR.mjs +475 -0
  61. package/packages/core/dist/chunk-YWAOOXLR.mjs.map +1 -0
  62. package/packages/core/dist/diff.cjs +993 -0
  63. package/packages/core/dist/diff.cjs.map +1 -0
  64. package/packages/core/dist/diff.d.cts +82 -0
  65. package/packages/core/dist/diff.d.ts +82 -0
  66. package/packages/core/dist/diff.mjs +5 -0
  67. package/packages/core/dist/diff.mjs.map +1 -0
  68. package/packages/core/dist/exporters.cjs +1228 -0
  69. package/packages/core/dist/exporters.cjs.map +1 -0
  70. package/packages/core/dist/exporters.d.cts +114 -0
  71. package/packages/core/dist/exporters.d.ts +114 -0
  72. package/packages/core/dist/exporters.mjs +6 -0
  73. package/packages/core/dist/exporters.mjs.map +1 -0
  74. package/packages/core/dist/index.cjs +5542 -2218
  75. package/packages/core/dist/index.cjs.map +1 -1
  76. package/packages/core/dist/index.d.cts +113 -908
  77. package/packages/core/dist/index.d.ts +113 -908
  78. package/packages/core/dist/index.mjs +1048 -5403
  79. package/packages/core/dist/index.mjs.map +1 -1
  80. package/packages/core/dist/inspect-event-Des4JDHo.d.cts +41 -0
  81. package/packages/core/dist/inspect-event-Des4JDHo.d.ts +41 -0
  82. package/packages/core/dist/log-config-BnH8Ykcb.d.cts +33 -0
  83. package/packages/core/dist/log-config-C1GcJPIM.d.ts +33 -0
  84. package/packages/core/dist/logs.cjs +1007 -0
  85. package/packages/core/dist/logs.cjs.map +1 -0
  86. package/packages/core/dist/logs.d.cts +138 -0
  87. package/packages/core/dist/logs.d.ts +138 -0
  88. package/packages/core/dist/logs.mjs +6 -0
  89. package/packages/core/dist/logs.mjs.map +1 -0
  90. package/packages/core/dist/persisted-inspect-event-0kaRADsp.d.cts +56 -0
  91. package/packages/core/dist/persisted-inspect-event-DiFto0K2.d.ts +56 -0
  92. package/packages/core/dist/persisted.cjs +1055 -0
  93. package/packages/core/dist/persisted.cjs.map +1 -0
  94. package/packages/core/dist/persisted.d.cts +111 -0
  95. package/packages/core/dist/persisted.d.ts +111 -0
  96. package/packages/core/dist/persisted.mjs +7 -0
  97. package/packages/core/dist/persisted.mjs.map +1 -0
  98. package/packages/core/dist/readers.cjs +2590 -0
  99. package/packages/core/dist/readers.cjs.map +1 -0
  100. package/packages/core/dist/readers.d.cts +80 -0
  101. package/packages/core/dist/readers.d.ts +80 -0
  102. package/packages/core/dist/readers.mjs +9 -0
  103. package/packages/core/dist/readers.mjs.map +1 -0
  104. package/packages/core/dist/types-DB8jB6Jg.d.cts +232 -0
  105. package/packages/core/dist/types-tSix7tfv.d.ts +232 -0
  106. package/packages/core/dist/writers.cjs +997 -0
  107. package/packages/core/dist/writers.cjs.map +1 -0
  108. package/packages/core/dist/writers.d.cts +62 -0
  109. package/packages/core/dist/writers.d.ts +62 -0
  110. package/packages/core/dist/writers.mjs +9 -0
  111. package/packages/core/dist/writers.mjs.map +1 -0
@@ -0,0 +1,254 @@
1
+ import { E as ErrorInfo, e as RedactionProfile, n as StepMetadata, T as TraceEvent, I as InspectRunOptions, g as ExecutionContext, d as TraceCorrelationMetadata, S as StepType, k as RunStatus, c as StepStatus } from './types-DB8jB6Jg.cjs';
2
+ import { R as RedactionRule } from './log-config-BnH8Ykcb.cjs';
3
+ import { P as PersistedInspectEvent } from './persisted-inspect-event-0kaRADsp.cjs';
4
+ import { TraceWriterStats, TraceWriter } from './writers.cjs';
5
+ import './inspect-event-Des4JDHo.cjs';
6
+
7
+ /** Default folder under the user home for AgentInspect data. */
8
+ declare const DEFAULT_TRACE_DIR_NAME = ".agent-inspect";
9
+ /** Subfolder where JSONL run traces are stored. */
10
+ declare const RUNS_DIR_NAME = "runs";
11
+ /** Writable trace root when the default home path cannot be used. */
12
+ declare const FALLBACK_TRACE_DIR: string;
13
+ /** Maximum display length for run/step names before truncation. */
14
+ declare const MAX_NAME_LENGTH = 100;
15
+ /** Returns `run_` + a 10-character nanoid segment. */
16
+ declare function createRunId(): string;
17
+ /** Returns `step_` + a 10-character nanoid segment. */
18
+ declare function createStepId(): string;
19
+ /** Formats a duration for CLI display (v0.2 rules). */
20
+ declare function formatDuration(ms: number): string;
21
+ /**
22
+ * Formats a Unix timestamp (ms) as local `YYYY-MM-DD HH:mm:ss`.
23
+ * Invalid values yield `"Invalid date"` (no throw).
24
+ */
25
+ declare function formatTimestamp(timestamp: number): string;
26
+ /**
27
+ * Default directory for trace files: `~/DEFAULT_TRACE_DIR_NAME/RUNS_DIR_NAME`.
28
+ * Falls back to {@link FALLBACK_TRACE_DIR} when home cannot be resolved.
29
+ */
30
+ declare function getDefaultTraceDir(): string;
31
+ /**
32
+ * Full path to the JSONL trace file for a run.
33
+ * `runId` is passed through `path.basename` to avoid traversal; empty ids become `run_unknown`.
34
+ */
35
+ declare function getTraceFilePath(runId: string, traceDir?: string): string;
36
+ /**
37
+ * Ensures a trace directory exists (recursive). Tries {@link FALLBACK_TRACE_DIR} on failure.
38
+ * Returns the directory path that callers should prefer: primary, fallback, or original if both mkdir attempts fail.
39
+ * Emits concise `[AgentInspect]` warnings on failure; never throws.
40
+ */
41
+ declare function ensureTraceDir(traceDir: string): Promise<string>;
42
+ /**
43
+ * Normalizes any thrown/caught value into {@link ErrorInfo}.
44
+ * Never throws (circular structures and non-JSON values fall back to a generic message).
45
+ */
46
+ declare function formatError(error: unknown): ErrorInfo;
47
+ /**
48
+ * Truncates a display name to `maxLength`, appending `"..."` when shortened.
49
+ * Empty or non-string input becomes `"unnamed"`.
50
+ */
51
+ declare function truncateName(name: string, maxLength?: number): string;
52
+ /**
53
+ * Instrumentation-only warning to stderr. Not a general-purpose logger.
54
+ * Optional `error` is summarized via {@link formatError} (message only).
55
+ */
56
+ declare function warn(message: string, error?: unknown): void;
57
+
58
+ interface ResolvedRedactionProfile {
59
+ profile: RedactionProfile;
60
+ extraKeys: readonly string[];
61
+ maxMetadataValueLengthCap?: number;
62
+ maxPreviewLengthCap?: number;
63
+ }
64
+ /** Resolves named profile behavior (keys + metadata string caps). */
65
+ declare function resolveRedactionProfile(profile?: RedactionProfile): ResolvedRedactionProfile;
66
+
67
+ /** Default max length for string metadata values (non-preview keys). */
68
+ declare const DEFAULT_MAX_METADATA_VALUE_LENGTH = 2000;
69
+ /** Default max length for preview-like metadata keys (contains `preview`, case-insensitive). */
70
+ declare const DEFAULT_MAX_PREVIEW_LENGTH = 500;
71
+ /** Default max serialized JSONL line size in bytes (UTF-8). */
72
+ declare const DEFAULT_MAX_EVENT_BYTES = 65536;
73
+ /** Resolved trace safety settings used at write time. */
74
+ interface TraceSafetyOptions {
75
+ redactEnabled: boolean;
76
+ redactionRules?: RedactionRule[];
77
+ redactionProfile: RedactionProfile;
78
+ profileExtraKeys: readonly string[];
79
+ maxMetadataValueLength: number;
80
+ maxPreviewLength: number;
81
+ maxEventBytes: number;
82
+ }
83
+
84
+ /** Resolves {@link InspectRunOptions} trace safety fields with safe defaults. */
85
+ declare function resolveTraceSafetyOptions(options?: Pick<InspectRunOptions, "redact" | "redactionProfile" | "maxEventBytes" | "maxMetadataValueLength" | "maxPreviewLength">): TraceSafetyOptions;
86
+ /** Redacts (when enabled) and truncates metadata values for disk persistence. */
87
+ declare function prepareMetadataForDisk(metadata: Record<string, unknown> | StepMetadata, opts: TraceSafetyOptions): Record<string, unknown>;
88
+ /**
89
+ * Applies redaction, metadata truncation, and final serialized size bounds.
90
+ * Never throws; returns a schema-valid event or a minimally truncated variant.
91
+ */
92
+ declare function prepareTraceEventForDisk(event: TraceEvent, opts: TraceSafetyOptions): TraceEvent;
93
+
94
+ /** Returns the active run context, without internal step fields. */
95
+ declare function getCurrentContext(): ExecutionContext | undefined;
96
+ /** Active `runId` when inside `runWithContext`, else `undefined`. */
97
+ declare function getCurrentRunId(): string | undefined;
98
+ /**
99
+ * Correlation metadata for the active run (`correlationId`, `requestId`, `decisionId`, `groupId`).
100
+ * `undefined` outside `inspectRun` / `maybeInspectRun` or when no correlation fields were set.
101
+ */
102
+ declare function getCurrentCorrelationMetadata(): TraceCorrelationMetadata | undefined;
103
+ /** Active `runName` when inside `runWithContext`, else `undefined`. */
104
+ declare function getCurrentRunName(): string | undefined;
105
+ /**
106
+ * Active step id in this async scope (parent for nested `step()` calls).
107
+ * `undefined` at run root or outside any run.
108
+ */
109
+ declare function getCurrentStepId(): string | undefined;
110
+ /** Alias of {@link getCurrentStepId} for readability in step instrumentation. */
111
+ declare function getParentStepId(): string | undefined;
112
+ /**
113
+ * Nesting depth: `0` at run root, increments by one per nested `runWithStepContext`.
114
+ * Returns `0` outside any run.
115
+ */
116
+ declare function getCurrentDepth(): number;
117
+ declare function hasActiveContext(): boolean;
118
+ declare function getTraceDirFromContext(): string | undefined;
119
+ declare function isSilentContext(): boolean;
120
+ /** Resolved trace safety settings for the active run (redaction + size bounds). */
121
+ declare function getTraceSafetyFromContext(): TraceSafetyOptions | undefined;
122
+ /**
123
+ * Runs `fn` with a fresh AgentInspect run context (depth 0, no active step).
124
+ * Propagates sync/async results and rejections; does not swallow user errors.
125
+ */
126
+ declare function runWithContext<T>(context: ExecutionContext, fn: () => Promise<T> | T, traceSafety?: TraceSafetyOptions): Promise<T>;
127
+ /**
128
+ * Runs `fn` with `stepId` as the active step (incremented depth).
129
+ * If no run is active, runs `fn` without altering async context.
130
+ */
131
+ declare function runWithStepContext<T>(stepId: string, fn: () => Promise<T> | T): Promise<T>;
132
+
133
+ interface InspectorRuntimeOptions {
134
+ enabled?: boolean;
135
+ writer?: TraceWriter;
136
+ traceSafety?: TraceSafetyOptions;
137
+ }
138
+ interface InspectorRuntimeContext extends ExecutionContext {
139
+ runtimeId: string;
140
+ }
141
+ interface InspectorRuntimeDiagnostics {
142
+ instrumentationErrors: number;
143
+ lastInstrumentationError?: string;
144
+ writerStats?: TraceWriterStats;
145
+ }
146
+ interface InspectorRuntime {
147
+ readonly runtimeId: string;
148
+ readonly enabled: boolean;
149
+ runWithContext<T>(context: ExecutionContext, fn: () => Promise<T> | T): Promise<T>;
150
+ runWithStepContext<T>(stepId: string, fn: () => Promise<T> | T): Promise<T>;
151
+ getCurrentContext(): InspectorRuntimeContext | undefined;
152
+ getCurrentCorrelationMetadata(): TraceCorrelationMetadata | undefined;
153
+ getCurrentStepId(): string | undefined;
154
+ getCurrentDepth(): number;
155
+ getTraceSafety(): TraceSafetyOptions;
156
+ write(event: PersistedInspectEvent): Promise<void>;
157
+ flush(): Promise<void>;
158
+ close(): Promise<void>;
159
+ getDiagnostics(): InspectorRuntimeDiagnostics;
160
+ }
161
+ declare function createInspectorRuntime(options?: InspectorRuntimeOptions): InspectorRuntime;
162
+
163
+ interface InspectorCaptureOptions {
164
+ onSuccess?: "none" | "metadata-only";
165
+ onError?: "none" | "metadata-only";
166
+ }
167
+ interface CreateInspectorOptions {
168
+ enabled?: boolean;
169
+ writer?: TraceWriter;
170
+ /**
171
+ * Context metadata only. Does not configure writer output; use
172
+ * `fileWriter({ dir })` or another explicit writer for persistence paths.
173
+ *
174
+ * @experimental
175
+ */
176
+ traceDir?: string;
177
+ /**
178
+ * Context metadata only for compatibility with existing terminal helpers.
179
+ * `createInspector()` does not print lifecycle output.
180
+ *
181
+ * @experimental
182
+ */
183
+ silent?: boolean;
184
+ metadata?: Record<string, unknown>;
185
+ redactionProfile?: RedactionProfile;
186
+ /**
187
+ * Metadata-only summaries for persisted run/step completion rows.
188
+ * This never stores raw return values, prompts, outputs, or thrown objects.
189
+ *
190
+ * @experimental
191
+ */
192
+ capture?: InspectorCaptureOptions;
193
+ traceSafety?: TraceSafetyOptions;
194
+ }
195
+ interface InspectorRunOptions {
196
+ runId?: string;
197
+ traceDir?: string;
198
+ silent?: boolean;
199
+ metadata?: Record<string, unknown>;
200
+ }
201
+ interface InspectorStepOptions {
202
+ type?: StepType;
203
+ metadata?: StepMetadata;
204
+ }
205
+ type InspectorObserveOptions = InspectorStepOptions;
206
+ interface Inspector {
207
+ /**
208
+ * Low-level runtime access is retained for v1.6 compatibility. Prefer
209
+ * `getDiagnostics()` unless you need advanced runtime context primitives.
210
+ *
211
+ * @experimental
212
+ */
213
+ readonly runtime: InspectorRuntime;
214
+ run<T>(name: string, fn: () => T | Promise<T>, options?: InspectorRunOptions): Promise<T>;
215
+ step<T>(name: string, fn: () => T | Promise<T>, options?: InspectorStepOptions): Promise<T>;
216
+ tool<T>(name: string, fn: () => T | Promise<T>, options?: InspectorStepOptions): Promise<T>;
217
+ llm<T>(name: string, fn: () => T | Promise<T>, options?: InspectorStepOptions): Promise<T>;
218
+ observe<TFunction extends (...args: any[]) => any>(name: string, fn: TFunction, options?: InspectorObserveOptions): (...args: Parameters<TFunction>) => Promise<Awaited<ReturnType<TFunction>>>;
219
+ getDiagnostics(): ReturnType<InspectorRuntime["getDiagnostics"]>;
220
+ flush(): Promise<void>;
221
+ close(): Promise<void>;
222
+ }
223
+ declare function createInspector(options?: CreateInspectorOptions): Inspector;
224
+
225
+ /** Two spaces per nesting level in terminal output. */
226
+ declare const TERMINAL_INDENT = " ";
227
+ /** Max display length for names in terminal output. */
228
+ declare const MAX_TERMINAL_NAME_LENGTH = 80;
229
+ /** Max nesting depth used for indentation (prevents huge indents). */
230
+ declare const MAX_TERMINAL_DEPTH = 10;
231
+ /** Indentation string for a nesting depth (capped, never negative). */
232
+ declare function getIndent(depth: number): string;
233
+ /** Truncates a display name for terminal use; invalid input becomes `"unnamed"`. */
234
+ declare function formatTerminalName(name: string): string;
235
+ /** Renders a single step line (colored); does not consult silent mode. */
236
+ declare function renderStepLine(name: string, durationMs: number | undefined, status: StepStatus, depth?: number): string;
237
+ /** Renders an error summary line (no stack in MVP). */
238
+ declare function renderErrorLine(error: ErrorInfo, depth?: number): string;
239
+ /** Plain-text run summary lines (no chalk) for stable testing and CLI reuse. */
240
+ declare function renderRunSummary(durationMs: number, status: RunStatus, traceFilePath?: string): string[];
241
+ /** Prints run header with icon and dim run id. */
242
+ declare function printRunStart(runId: string, name: string): void;
243
+ /** Prints a running step line. */
244
+ declare function printStepStart(name: string, depth?: number): void;
245
+ /** Prints a completed step line with duration and status icon. */
246
+ declare function printStepComplete(name: string, durationMs: number, status: StepStatus, depth?: number): void;
247
+ /** Prints a structured error line (message only, no stack). */
248
+ declare function printError(error: ErrorInfo, depth?: number): void;
249
+ /** Prints run completion summary and optional trace path. */
250
+ declare function printRunComplete(_name: string, _runId: string, durationMs: number, status: RunStatus, traceFilePath?: string): void;
251
+ /** Prints which step failed. */
252
+ declare function printFailedAt(stepName: string): void;
253
+
254
+ export { type CreateInspectorOptions, DEFAULT_MAX_EVENT_BYTES, DEFAULT_MAX_METADATA_VALUE_LENGTH, DEFAULT_MAX_PREVIEW_LENGTH, DEFAULT_TRACE_DIR_NAME, FALLBACK_TRACE_DIR, type Inspector, type InspectorCaptureOptions, type InspectorObserveOptions, type InspectorRunOptions, type InspectorRuntime, type InspectorRuntimeContext, type InspectorRuntimeDiagnostics, type InspectorRuntimeOptions, type InspectorStepOptions, MAX_NAME_LENGTH, MAX_TERMINAL_DEPTH, MAX_TERMINAL_NAME_LENGTH, RUNS_DIR_NAME, type ResolvedRedactionProfile, TERMINAL_INDENT, type TraceSafetyOptions, createInspector, createInspectorRuntime, createRunId, createStepId, ensureTraceDir, formatDuration, formatError, formatTerminalName, formatTimestamp, getCurrentContext, getCurrentCorrelationMetadata, getCurrentDepth, getCurrentRunId, getCurrentRunName, getCurrentStepId, getDefaultTraceDir, getIndent, getParentStepId, getTraceDirFromContext, getTraceFilePath, getTraceSafetyFromContext, hasActiveContext, isSilentContext, prepareMetadataForDisk, prepareTraceEventForDisk, printError, printFailedAt, printRunComplete, printRunStart, printStepComplete, printStepStart, renderErrorLine, renderRunSummary, renderStepLine, resolveRedactionProfile, resolveTraceSafetyOptions, runWithContext, runWithStepContext, truncateName, warn };
@@ -0,0 +1,254 @@
1
+ import { E as ErrorInfo, e as RedactionProfile, n as StepMetadata, T as TraceEvent, I as InspectRunOptions, g as ExecutionContext, d as TraceCorrelationMetadata, S as StepType, k as RunStatus, c as StepStatus } from './types-tSix7tfv.js';
2
+ import { R as RedactionRule } from './log-config-C1GcJPIM.js';
3
+ import { P as PersistedInspectEvent } from './persisted-inspect-event-DiFto0K2.js';
4
+ import { TraceWriterStats, TraceWriter } from './writers.js';
5
+ import './inspect-event-Des4JDHo.js';
6
+
7
+ /** Default folder under the user home for AgentInspect data. */
8
+ declare const DEFAULT_TRACE_DIR_NAME = ".agent-inspect";
9
+ /** Subfolder where JSONL run traces are stored. */
10
+ declare const RUNS_DIR_NAME = "runs";
11
+ /** Writable trace root when the default home path cannot be used. */
12
+ declare const FALLBACK_TRACE_DIR: string;
13
+ /** Maximum display length for run/step names before truncation. */
14
+ declare const MAX_NAME_LENGTH = 100;
15
+ /** Returns `run_` + a 10-character nanoid segment. */
16
+ declare function createRunId(): string;
17
+ /** Returns `step_` + a 10-character nanoid segment. */
18
+ declare function createStepId(): string;
19
+ /** Formats a duration for CLI display (v0.2 rules). */
20
+ declare function formatDuration(ms: number): string;
21
+ /**
22
+ * Formats a Unix timestamp (ms) as local `YYYY-MM-DD HH:mm:ss`.
23
+ * Invalid values yield `"Invalid date"` (no throw).
24
+ */
25
+ declare function formatTimestamp(timestamp: number): string;
26
+ /**
27
+ * Default directory for trace files: `~/DEFAULT_TRACE_DIR_NAME/RUNS_DIR_NAME`.
28
+ * Falls back to {@link FALLBACK_TRACE_DIR} when home cannot be resolved.
29
+ */
30
+ declare function getDefaultTraceDir(): string;
31
+ /**
32
+ * Full path to the JSONL trace file for a run.
33
+ * `runId` is passed through `path.basename` to avoid traversal; empty ids become `run_unknown`.
34
+ */
35
+ declare function getTraceFilePath(runId: string, traceDir?: string): string;
36
+ /**
37
+ * Ensures a trace directory exists (recursive). Tries {@link FALLBACK_TRACE_DIR} on failure.
38
+ * Returns the directory path that callers should prefer: primary, fallback, or original if both mkdir attempts fail.
39
+ * Emits concise `[AgentInspect]` warnings on failure; never throws.
40
+ */
41
+ declare function ensureTraceDir(traceDir: string): Promise<string>;
42
+ /**
43
+ * Normalizes any thrown/caught value into {@link ErrorInfo}.
44
+ * Never throws (circular structures and non-JSON values fall back to a generic message).
45
+ */
46
+ declare function formatError(error: unknown): ErrorInfo;
47
+ /**
48
+ * Truncates a display name to `maxLength`, appending `"..."` when shortened.
49
+ * Empty or non-string input becomes `"unnamed"`.
50
+ */
51
+ declare function truncateName(name: string, maxLength?: number): string;
52
+ /**
53
+ * Instrumentation-only warning to stderr. Not a general-purpose logger.
54
+ * Optional `error` is summarized via {@link formatError} (message only).
55
+ */
56
+ declare function warn(message: string, error?: unknown): void;
57
+
58
+ interface ResolvedRedactionProfile {
59
+ profile: RedactionProfile;
60
+ extraKeys: readonly string[];
61
+ maxMetadataValueLengthCap?: number;
62
+ maxPreviewLengthCap?: number;
63
+ }
64
+ /** Resolves named profile behavior (keys + metadata string caps). */
65
+ declare function resolveRedactionProfile(profile?: RedactionProfile): ResolvedRedactionProfile;
66
+
67
+ /** Default max length for string metadata values (non-preview keys). */
68
+ declare const DEFAULT_MAX_METADATA_VALUE_LENGTH = 2000;
69
+ /** Default max length for preview-like metadata keys (contains `preview`, case-insensitive). */
70
+ declare const DEFAULT_MAX_PREVIEW_LENGTH = 500;
71
+ /** Default max serialized JSONL line size in bytes (UTF-8). */
72
+ declare const DEFAULT_MAX_EVENT_BYTES = 65536;
73
+ /** Resolved trace safety settings used at write time. */
74
+ interface TraceSafetyOptions {
75
+ redactEnabled: boolean;
76
+ redactionRules?: RedactionRule[];
77
+ redactionProfile: RedactionProfile;
78
+ profileExtraKeys: readonly string[];
79
+ maxMetadataValueLength: number;
80
+ maxPreviewLength: number;
81
+ maxEventBytes: number;
82
+ }
83
+
84
+ /** Resolves {@link InspectRunOptions} trace safety fields with safe defaults. */
85
+ declare function resolveTraceSafetyOptions(options?: Pick<InspectRunOptions, "redact" | "redactionProfile" | "maxEventBytes" | "maxMetadataValueLength" | "maxPreviewLength">): TraceSafetyOptions;
86
+ /** Redacts (when enabled) and truncates metadata values for disk persistence. */
87
+ declare function prepareMetadataForDisk(metadata: Record<string, unknown> | StepMetadata, opts: TraceSafetyOptions): Record<string, unknown>;
88
+ /**
89
+ * Applies redaction, metadata truncation, and final serialized size bounds.
90
+ * Never throws; returns a schema-valid event or a minimally truncated variant.
91
+ */
92
+ declare function prepareTraceEventForDisk(event: TraceEvent, opts: TraceSafetyOptions): TraceEvent;
93
+
94
+ /** Returns the active run context, without internal step fields. */
95
+ declare function getCurrentContext(): ExecutionContext | undefined;
96
+ /** Active `runId` when inside `runWithContext`, else `undefined`. */
97
+ declare function getCurrentRunId(): string | undefined;
98
+ /**
99
+ * Correlation metadata for the active run (`correlationId`, `requestId`, `decisionId`, `groupId`).
100
+ * `undefined` outside `inspectRun` / `maybeInspectRun` or when no correlation fields were set.
101
+ */
102
+ declare function getCurrentCorrelationMetadata(): TraceCorrelationMetadata | undefined;
103
+ /** Active `runName` when inside `runWithContext`, else `undefined`. */
104
+ declare function getCurrentRunName(): string | undefined;
105
+ /**
106
+ * Active step id in this async scope (parent for nested `step()` calls).
107
+ * `undefined` at run root or outside any run.
108
+ */
109
+ declare function getCurrentStepId(): string | undefined;
110
+ /** Alias of {@link getCurrentStepId} for readability in step instrumentation. */
111
+ declare function getParentStepId(): string | undefined;
112
+ /**
113
+ * Nesting depth: `0` at run root, increments by one per nested `runWithStepContext`.
114
+ * Returns `0` outside any run.
115
+ */
116
+ declare function getCurrentDepth(): number;
117
+ declare function hasActiveContext(): boolean;
118
+ declare function getTraceDirFromContext(): string | undefined;
119
+ declare function isSilentContext(): boolean;
120
+ /** Resolved trace safety settings for the active run (redaction + size bounds). */
121
+ declare function getTraceSafetyFromContext(): TraceSafetyOptions | undefined;
122
+ /**
123
+ * Runs `fn` with a fresh AgentInspect run context (depth 0, no active step).
124
+ * Propagates sync/async results and rejections; does not swallow user errors.
125
+ */
126
+ declare function runWithContext<T>(context: ExecutionContext, fn: () => Promise<T> | T, traceSafety?: TraceSafetyOptions): Promise<T>;
127
+ /**
128
+ * Runs `fn` with `stepId` as the active step (incremented depth).
129
+ * If no run is active, runs `fn` without altering async context.
130
+ */
131
+ declare function runWithStepContext<T>(stepId: string, fn: () => Promise<T> | T): Promise<T>;
132
+
133
+ interface InspectorRuntimeOptions {
134
+ enabled?: boolean;
135
+ writer?: TraceWriter;
136
+ traceSafety?: TraceSafetyOptions;
137
+ }
138
+ interface InspectorRuntimeContext extends ExecutionContext {
139
+ runtimeId: string;
140
+ }
141
+ interface InspectorRuntimeDiagnostics {
142
+ instrumentationErrors: number;
143
+ lastInstrumentationError?: string;
144
+ writerStats?: TraceWriterStats;
145
+ }
146
+ interface InspectorRuntime {
147
+ readonly runtimeId: string;
148
+ readonly enabled: boolean;
149
+ runWithContext<T>(context: ExecutionContext, fn: () => Promise<T> | T): Promise<T>;
150
+ runWithStepContext<T>(stepId: string, fn: () => Promise<T> | T): Promise<T>;
151
+ getCurrentContext(): InspectorRuntimeContext | undefined;
152
+ getCurrentCorrelationMetadata(): TraceCorrelationMetadata | undefined;
153
+ getCurrentStepId(): string | undefined;
154
+ getCurrentDepth(): number;
155
+ getTraceSafety(): TraceSafetyOptions;
156
+ write(event: PersistedInspectEvent): Promise<void>;
157
+ flush(): Promise<void>;
158
+ close(): Promise<void>;
159
+ getDiagnostics(): InspectorRuntimeDiagnostics;
160
+ }
161
+ declare function createInspectorRuntime(options?: InspectorRuntimeOptions): InspectorRuntime;
162
+
163
+ interface InspectorCaptureOptions {
164
+ onSuccess?: "none" | "metadata-only";
165
+ onError?: "none" | "metadata-only";
166
+ }
167
+ interface CreateInspectorOptions {
168
+ enabled?: boolean;
169
+ writer?: TraceWriter;
170
+ /**
171
+ * Context metadata only. Does not configure writer output; use
172
+ * `fileWriter({ dir })` or another explicit writer for persistence paths.
173
+ *
174
+ * @experimental
175
+ */
176
+ traceDir?: string;
177
+ /**
178
+ * Context metadata only for compatibility with existing terminal helpers.
179
+ * `createInspector()` does not print lifecycle output.
180
+ *
181
+ * @experimental
182
+ */
183
+ silent?: boolean;
184
+ metadata?: Record<string, unknown>;
185
+ redactionProfile?: RedactionProfile;
186
+ /**
187
+ * Metadata-only summaries for persisted run/step completion rows.
188
+ * This never stores raw return values, prompts, outputs, or thrown objects.
189
+ *
190
+ * @experimental
191
+ */
192
+ capture?: InspectorCaptureOptions;
193
+ traceSafety?: TraceSafetyOptions;
194
+ }
195
+ interface InspectorRunOptions {
196
+ runId?: string;
197
+ traceDir?: string;
198
+ silent?: boolean;
199
+ metadata?: Record<string, unknown>;
200
+ }
201
+ interface InspectorStepOptions {
202
+ type?: StepType;
203
+ metadata?: StepMetadata;
204
+ }
205
+ type InspectorObserveOptions = InspectorStepOptions;
206
+ interface Inspector {
207
+ /**
208
+ * Low-level runtime access is retained for v1.6 compatibility. Prefer
209
+ * `getDiagnostics()` unless you need advanced runtime context primitives.
210
+ *
211
+ * @experimental
212
+ */
213
+ readonly runtime: InspectorRuntime;
214
+ run<T>(name: string, fn: () => T | Promise<T>, options?: InspectorRunOptions): Promise<T>;
215
+ step<T>(name: string, fn: () => T | Promise<T>, options?: InspectorStepOptions): Promise<T>;
216
+ tool<T>(name: string, fn: () => T | Promise<T>, options?: InspectorStepOptions): Promise<T>;
217
+ llm<T>(name: string, fn: () => T | Promise<T>, options?: InspectorStepOptions): Promise<T>;
218
+ observe<TFunction extends (...args: any[]) => any>(name: string, fn: TFunction, options?: InspectorObserveOptions): (...args: Parameters<TFunction>) => Promise<Awaited<ReturnType<TFunction>>>;
219
+ getDiagnostics(): ReturnType<InspectorRuntime["getDiagnostics"]>;
220
+ flush(): Promise<void>;
221
+ close(): Promise<void>;
222
+ }
223
+ declare function createInspector(options?: CreateInspectorOptions): Inspector;
224
+
225
+ /** Two spaces per nesting level in terminal output. */
226
+ declare const TERMINAL_INDENT = " ";
227
+ /** Max display length for names in terminal output. */
228
+ declare const MAX_TERMINAL_NAME_LENGTH = 80;
229
+ /** Max nesting depth used for indentation (prevents huge indents). */
230
+ declare const MAX_TERMINAL_DEPTH = 10;
231
+ /** Indentation string for a nesting depth (capped, never negative). */
232
+ declare function getIndent(depth: number): string;
233
+ /** Truncates a display name for terminal use; invalid input becomes `"unnamed"`. */
234
+ declare function formatTerminalName(name: string): string;
235
+ /** Renders a single step line (colored); does not consult silent mode. */
236
+ declare function renderStepLine(name: string, durationMs: number | undefined, status: StepStatus, depth?: number): string;
237
+ /** Renders an error summary line (no stack in MVP). */
238
+ declare function renderErrorLine(error: ErrorInfo, depth?: number): string;
239
+ /** Plain-text run summary lines (no chalk) for stable testing and CLI reuse. */
240
+ declare function renderRunSummary(durationMs: number, status: RunStatus, traceFilePath?: string): string[];
241
+ /** Prints run header with icon and dim run id. */
242
+ declare function printRunStart(runId: string, name: string): void;
243
+ /** Prints a running step line. */
244
+ declare function printStepStart(name: string, depth?: number): void;
245
+ /** Prints a completed step line with duration and status icon. */
246
+ declare function printStepComplete(name: string, durationMs: number, status: StepStatus, depth?: number): void;
247
+ /** Prints a structured error line (message only, no stack). */
248
+ declare function printError(error: ErrorInfo, depth?: number): void;
249
+ /** Prints run completion summary and optional trace path. */
250
+ declare function printRunComplete(_name: string, _runId: string, durationMs: number, status: RunStatus, traceFilePath?: string): void;
251
+ /** Prints which step failed. */
252
+ declare function printFailedAt(stepName: string): void;
253
+
254
+ export { type CreateInspectorOptions, DEFAULT_MAX_EVENT_BYTES, DEFAULT_MAX_METADATA_VALUE_LENGTH, DEFAULT_MAX_PREVIEW_LENGTH, DEFAULT_TRACE_DIR_NAME, FALLBACK_TRACE_DIR, type Inspector, type InspectorCaptureOptions, type InspectorObserveOptions, type InspectorRunOptions, type InspectorRuntime, type InspectorRuntimeContext, type InspectorRuntimeDiagnostics, type InspectorRuntimeOptions, type InspectorStepOptions, MAX_NAME_LENGTH, MAX_TERMINAL_DEPTH, MAX_TERMINAL_NAME_LENGTH, RUNS_DIR_NAME, type ResolvedRedactionProfile, TERMINAL_INDENT, type TraceSafetyOptions, createInspector, createInspectorRuntime, createRunId, createStepId, ensureTraceDir, formatDuration, formatError, formatTerminalName, formatTimestamp, getCurrentContext, getCurrentCorrelationMetadata, getCurrentDepth, getCurrentRunId, getCurrentRunName, getCurrentStepId, getDefaultTraceDir, getIndent, getParentStepId, getTraceDirFromContext, getTraceFilePath, getTraceSafetyFromContext, hasActiveContext, isSilentContext, prepareMetadataForDisk, prepareTraceEventForDisk, printError, printFailedAt, printRunComplete, printRunStart, printStepComplete, printStepStart, renderErrorLine, renderRunSummary, renderStepLine, resolveRedactionProfile, resolveTraceSafetyOptions, runWithContext, runWithStepContext, truncateName, warn };
@@ -0,0 +1,11 @@
1
+ export { MAX_TERMINAL_DEPTH, MAX_TERMINAL_NAME_LENGTH, TERMINAL_INDENT, createInspector, createInspectorRuntime, formatTerminalName, getCurrentContext, getCurrentCorrelationMetadata, getCurrentDepth, getCurrentRunId, getCurrentRunName, getCurrentStepId, getIndent, getParentStepId, getTraceDirFromContext, getTraceSafetyFromContext, hasActiveContext, isSilentContext, printError, printFailedAt, printRunComplete, printRunStart, printStepComplete, printStepStart, renderErrorLine, renderRunSummary, renderStepLine, runWithContext, runWithStepContext } from './chunk-6QSLZCBJ.mjs';
2
+ import './chunk-BT7CATSD.mjs';
3
+ export { DEFAULT_MAX_EVENT_BYTES, DEFAULT_MAX_METADATA_VALUE_LENGTH, DEFAULT_MAX_PREVIEW_LENGTH, prepareMetadataForDisk, prepareTraceEventForDisk, resolveTraceSafetyOptions } from './chunk-57S5D6HR.mjs';
4
+ export { resolveRedactionProfile } from './chunk-EDTQHZPM.mjs';
5
+ import './chunk-VU6O5QAH.mjs';
6
+ import './chunk-S4YWKV4G.mjs';
7
+ export { DEFAULT_TRACE_DIR_NAME, FALLBACK_TRACE_DIR, MAX_NAME_LENGTH, RUNS_DIR_NAME, createRunId, createStepId, ensureTraceDir, formatDuration, formatError, formatTimestamp, getDefaultTraceDir, getTraceFilePath, truncateName, warn } from './chunk-VTIB5MDK.mjs';
8
+ import './chunk-74XZ6N7Q.mjs';
9
+ import './chunk-7TGZLWEE.mjs';
10
+ //# sourceMappingURL=advanced.mjs.map
11
+ //# sourceMappingURL=advanced.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"advanced.mjs"}