@tracegraph/shared-types 0.1.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/LICENSE ADDED
@@ -0,0 +1,181 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship made available under
36
+ the License, as indicated by a copyright notice that is included in
37
+ or attached to the work (an example is provided in the Appendix below).
38
+
39
+ "Derivative Works" shall mean any work, whether in Source or Object
40
+ form, that is based on (or derived from) the Work and for which the
41
+ editorial revisions, annotations, elaborations, or other derivative
42
+ works represent, as a whole, an original work of authorship. For the
43
+ purposes of this License, Derivative Works shall not include works
44
+ that remain separable from, or merely link (or bind by name) to the
45
+ interfaces of, the Work and Derivative Works thereof.
46
+
47
+ "Contribution" shall mean, as submitted to the Licensor for inclusion
48
+ in the Work by the copyright owner or by an individual or Legal Entity
49
+ authorized to submit on behalf of the copyright owner. For the
50
+ purposes of this definition, "submitted" means any form of electronic,
51
+ verbal, or written communication sent to the Licensor or its
52
+ representatives, including but not limited to communication on
53
+ electronic mailing lists, source code control systems, and issue
54
+ tracking systems that are managed by, or on behalf of, the Licensor
55
+ for the purpose of discussing and improving the Work, but excluding
56
+ communication that is conspicuously marked or designated in writing
57
+ by the copyright owner as "Not a Contribution."
58
+
59
+ "Contributor" shall mean Licensor and any Legal Entity on behalf of
60
+ whom a Contribution has been received by the Licensor and included
61
+ within the Work.
62
+
63
+ 2. Grant of Copyright License. Subject to the terms and conditions of
64
+ this License, each Contributor hereby grants to You a perpetual,
65
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
66
+ copyright license to reproduce, prepare Derivative Works of,
67
+ publicly display, publicly perform, sublicense, and distribute the
68
+ Work and such Derivative Works in Source or Object form.
69
+
70
+ 3. Grant of Patent License. Subject to the terms and conditions of
71
+ this License, each Contributor hereby grants to You a perpetual,
72
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
73
+ (except as stated in this section) patent license to make, have made,
74
+ use, offer to sell, sell, import, and otherwise transfer the Work,
75
+ where such license applies only to those patent claims licensable
76
+ by such Contributor that are necessarily infringed by their
77
+ Contribution(s) alone or by the combined work to with their
78
+ Contribution(s) was submitted. If You institute patent litigation
79
+ against any entity (including a cross-claim or counterclaim in a
80
+ lawsuit) alleging that the Work or any Contribution embodied within
81
+ the Work constitutes direct or contributory patent infringement,
82
+ then any patent licenses granted to You under this License for that
83
+ Work shall terminate as of the date such litigation is filed.
84
+
85
+ 4. Redistribution. You may reproduce and distribute copies of the
86
+ Work or Derivative Works thereof in any medium, with or without
87
+ modifications, and in Source or Object form, provided that You
88
+ meet the following conditions:
89
+
90
+ (a) You must give any other recipients of the Work or Derivative
91
+ Works a copy of this License; and
92
+
93
+ (b) You must cause any modified files to carry prominent notices
94
+ stating that You changed the files; and
95
+
96
+ (c) You must retain, in the Source form of any Derivative Works
97
+ that You distribute, all copyright, patent, trademark, and
98
+ attribution notices from the Source form of the Work,
99
+ excluding those notices that do not pertain to any part of
100
+ the Derivative Works; and
101
+
102
+ (d) If the Work includes a "NOTICE" text file as part of its
103
+ distribution, You must include a readable copy of the
104
+ attribution notices contained within such NOTICE file, in
105
+ at least one of the following places: within a NOTICE text
106
+ file distributed as part of the Derivative Works; within
107
+ the Source form or documentation, if provided along with the
108
+ Derivative Works; or, within a display generated by the
109
+ Derivative Works, if and wherever such third-party notices
110
+ normally appear. The contents of the NOTICE file are for
111
+ informational purposes only and do not modify the License.
112
+ You may add Your own attribution notices within Derivative
113
+ Works that You distribute, alongside or as an addendum to
114
+ the NOTICE text from the Work, provided that such additional
115
+ attribution notices cannot be construed as modifying the License.
116
+
117
+ You may add Your own license statement for Your modifications and
118
+ may provide additional grant of rights to use, copy, modify, merge,
119
+ publish, distribute, sublicense, and/or sell copies of the
120
+ Derivative Works, and to permit persons to whom the Derivative
121
+ Works is furnished to do so.
122
+
123
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
124
+ any Contribution intentionally submitted for inclusion in the Work
125
+ by You to the Licensor shall be under the terms and conditions of
126
+ this License, without any additional terms or conditions.
127
+ Notwithstanding the above, nothing herein shall supersede or modify
128
+ the terms of any separate license agreement you may have executed
129
+ with Licensor regarding such Contributions.
130
+
131
+ 6. Trademarks. This License does not grant permission to use the trade
132
+ names, trademarks, service marks, or product names of the Licensor,
133
+ except as required for reasonable and customary use in describing the
134
+ origin of the Work and reproducing the content of the NOTICE file.
135
+
136
+ 7. Disclaimer of Warranty. Unless required by applicable law or
137
+ agreed to in writing, Licensor provides the Work (and each
138
+ Contributor provides its Contributions) on an "AS IS" BASIS,
139
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
140
+ implied, including, without limitation, any conditions of TITLE,
141
+ NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR
142
+ PURPOSE. You are solely responsible for determining the
143
+ appropriateness of using or reproducing the Work and assume any
144
+ risks associated with Your exercise of permissions under this License.
145
+
146
+ 8. Limitation of Liability. In no event and under no legal theory,
147
+ whether in tort (including negligence), contract, or otherwise,
148
+ unless required by applicable law (such as deliberate and grossly
149
+ negligent acts) or agreed to in writing, shall any Contributor be
150
+ liable to You for damages, including any direct, indirect, special,
151
+ incidental, or exemplary damages of any character arising as a
152
+ result of this License or out of the use or inability to use the
153
+ Work (including but not limited to damages for loss of goodwill,
154
+ work stoppage, computer failure or malfunction, or all other
155
+ commercial damages or losses), even if such Contributor has been
156
+ advised of the possibility of such damages.
157
+
158
+ 9. Accepting Warranty or Additional Liability. While redistributing
159
+ the Work or Derivative Works thereof, You may choose to offer,
160
+ and charge a fee for, acceptance of support, warranty, indemnity,
161
+ or other liability obligations and/or rights consistent with this
162
+ License. However, in accepting such obligations, You may offer
163
+ only conditions consistent with this License, in a way that does
164
+ not create a new obligation for any Contributor to provide such
165
+ acceptance.
166
+
167
+ END OF TERMS AND CONDITIONS
168
+
169
+ Copyright 2026 TraceGraph Contributors
170
+
171
+ Licensed under the Apache License, Version 2.0 (the "License");
172
+ you may not use this file except in compliance with the License.
173
+ You may obtain a copy of the License at
174
+
175
+ http://www.apache.org/licenses/LICENSE-2.0
176
+
177
+ Unless required by applicable law or agreed to in writing, software
178
+ distributed under the License is distributed on an "AS IS" BASIS,
179
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
180
+ See the License for the specific language governing permissions and
181
+ limitations under the License.
@@ -0,0 +1,529 @@
1
+ declare const SCHEMA_VERSIONS: {
2
+ readonly trace: "tracegraph.trace.v1";
3
+ readonly event: "tracegraph.event.v1";
4
+ readonly baseline: "tracegraph.baseline.v1";
5
+ readonly bundle: "tracegraph.bundle.v1";
6
+ readonly report: "tracegraph.report.v1";
7
+ readonly diff: "tracegraph.diff.v1";
8
+ readonly suppression: "tracegraph.suppressions.v1";
9
+ readonly findingApproval: "tracegraph.finding-approvals.v1";
10
+ readonly scenario: "tracegraph.scenario.v1";
11
+ readonly index: "tracegraph.index.v1";
12
+ readonly coverage: "tracegraph.coverage.v1";
13
+ };
14
+ type SchemaVersions = typeof SCHEMA_VERSIONS;
15
+ type TraceEntrypoint = {
16
+ type: 'http_request';
17
+ method: string;
18
+ path: string;
19
+ handler?: string;
20
+ } | {
21
+ type: 'test_case';
22
+ testName: string;
23
+ testFile?: string;
24
+ } | {
25
+ type: 'function';
26
+ functionName: string;
27
+ file?: string;
28
+ line?: number;
29
+ } | {
30
+ type: 'cli_command';
31
+ command: string;
32
+ };
33
+ /**
34
+ * Levels:
35
+ * 0 = runner metadata only (zero config)
36
+ * 1 = framework adapters (Express middleware, Laravel hooks)
37
+ * 2 = manual traceFunction wrappers
38
+ * 3 = CJS require hook auto-instrumentation
39
+ * 4 = ESM --import hook (limited — cannot replace live bindings)
40
+ * 5 = build-time transform (Vitest reporter, Babel/SWC plugin)
41
+ */
42
+ type CaptureLevelValue = 0 | 1 | 2 | 3 | 4 | 5;
43
+ type AdapterCaptureInfo = {
44
+ level: number;
45
+ mode: string;
46
+ captured: string[];
47
+ notCaptured: string[];
48
+ recommendation?: string;
49
+ };
50
+ type CaptureLevel = {
51
+ overall: CaptureLevelValue;
52
+ label: string;
53
+ adapters: Record<string, AdapterCaptureInfo>;
54
+ };
55
+ type TraceEventType = 'trace_start' | 'trace_end' | 'http_request' | 'http_response' | 'function_call' | 'method_call' | 'db_query' | 'external_http_call' | 'file_operation' | 'cache_operation' | 'queue_event' | 'log' | 'error' | 'branch' | 'return' | 'auth_check' | 'authorization_check' | 'rate_limit_check' | 'lock_acquire' | 'lock_release' | 'transaction_start' | 'transaction_commit' | 'transaction_rollback'
56
+ /** One per test file; parent = trace_start. */
57
+ | 'test_file'
58
+ /** One per describe() block; parent = test_file or enclosing test_suite. */
59
+ | 'test_suite'
60
+ /** One per it()/test() call; parent = nearest test_suite or test_file. */
61
+ | 'test_run';
62
+ type ConcurrencyType = 'sequential' | 'parallel' | 'promise_all' | 'race' | 'background';
63
+ type LanguageId = 'typescript' | 'javascript' | 'php';
64
+ type FrameworkId = 'express' | 'nestjs' | 'nextjs' | 'fastify' | 'laravel' | 'symfony' | 'vitest' | 'jest' | 'xdebug' | 'plain';
65
+ /** Cross-trace event reference for causal links (e.g. HTTP request → dispatched job). */
66
+ type EventRef = {
67
+ traceId: string;
68
+ eventId: string;
69
+ };
70
+ type TraceError = {
71
+ type: string;
72
+ message: string;
73
+ stack?: string;
74
+ };
75
+ type TraceResource = {
76
+ type: string;
77
+ key: string;
78
+ operation: string;
79
+ };
80
+ type SanitizedValue = Record<string, unknown> | unknown[] | string | number | null;
81
+ type SecurityMetadata = Record<string, unknown>;
82
+ type ReliabilityMetadata = Record<string, unknown>;
83
+ type TraceEvent = {
84
+ schemaVersion: 'tracegraph.event.v1';
85
+ eventId: string;
86
+ traceId: string;
87
+ /** Structural parent: the containing call in the call stack. */
88
+ parentEventId?: string | null;
89
+ /**
90
+ * Causal parent: the event that caused this one.
91
+ * Same as parentEventId for synchronous calls; different for async/queue scenarios.
92
+ */
93
+ causalParentEventId?: string | null;
94
+ /**
95
+ * Cross-trace causal reference.
96
+ * Used when a job's causal parent is an event in a different trace (e.g. HTTP → queue worker).
97
+ */
98
+ causalParentRef?: EventRef | null;
99
+ /** Parallel execution grouping (Promise.all, concurrent requests). */
100
+ asyncGroupId?: string;
101
+ branchId?: string;
102
+ concurrencyType?: ConcurrencyType;
103
+ type: TraceEventType;
104
+ language: LanguageId;
105
+ name: string;
106
+ displayName?: string;
107
+ file?: string;
108
+ line?: number;
109
+ column?: number;
110
+ className?: string;
111
+ functionName?: string;
112
+ moduleName?: string;
113
+ framework?: FrameworkId;
114
+ startTime: number;
115
+ endTime?: number;
116
+ durationMs?: number;
117
+ input?: SanitizedValue;
118
+ output?: SanitizedValue;
119
+ error?: TraceError;
120
+ resource?: TraceResource;
121
+ security?: SecurityMetadata;
122
+ reliability?: ReliabilityMetadata;
123
+ tags?: string[];
124
+ metadata?: Record<string, unknown>;
125
+ };
126
+ type DetailStreams = {
127
+ xdebug?: {
128
+ events: TraceEvent[];
129
+ /** Map from semantic event ID → attached Xdebug event IDs. */
130
+ attachedTo: Record<string, string[]>;
131
+ };
132
+ };
133
+ type TraceSessionStatus = 'running' | 'passed' | 'failed' | 'error';
134
+ type TraceSession = {
135
+ schemaVersion: 'tracegraph.trace.v1';
136
+ traceId: string;
137
+ sessionId: string;
138
+ runId: string;
139
+ scenarioId?: string;
140
+ projectId?: string;
141
+ workspaceRoot: string;
142
+ language: LanguageId;
143
+ framework?: string;
144
+ entrypoint: TraceEntrypoint;
145
+ startedAt: number;
146
+ endedAt?: number;
147
+ status: TraceSessionStatus;
148
+ captureLevel: CaptureLevel;
149
+ events: TraceEvent[];
150
+ detailStreams?: DetailStreams;
151
+ metadata?: Record<string, unknown>;
152
+ };
153
+ type TraceIndexEntry = {
154
+ traceId: string;
155
+ runId: string;
156
+ file: string;
157
+ status: TraceSessionStatus;
158
+ createdAt: number;
159
+ entrypoint: TraceEntrypoint;
160
+ };
161
+ type TraceIndex = {
162
+ schemaVersion: 'tracegraph.index.v1';
163
+ traces: TraceIndexEntry[];
164
+ };
165
+ type BundleLink = {
166
+ source: EventRef;
167
+ target: EventRef;
168
+ type: 'causes' | 'correlates' | 'spawns';
169
+ correlationId: string;
170
+ };
171
+ type TraceBundle = {
172
+ schemaVersion: 'tracegraph.bundle.v1';
173
+ bundleId: string;
174
+ scenarioId: string;
175
+ createdAt: number;
176
+ traces: Array<{
177
+ language: LanguageId;
178
+ traceId: string;
179
+ file: string;
180
+ }>;
181
+ links: BundleLink[];
182
+ };
183
+ type CliEventType = 'run.started' | 'run.progress' | 'run.completed' | 'trace.started' | 'trace.progress' | 'trace.completed' | 'finding' | 'report.created' | 'approval.required' | 'error';
184
+ type CliEventEnvelope = {
185
+ protocol: 'tracegraph.cli.v1';
186
+ type: CliEventType;
187
+ runId: string;
188
+ traceId?: string;
189
+ timestamp: number;
190
+ captureLevel?: Pick<CaptureLevel, 'overall' | 'label'>;
191
+ payload?: Record<string, unknown>;
192
+ };
193
+ type EventRole = 'validation' | 'authorization' | 'business_logic' | 'db' | 'external_call';
194
+ type SemanticSignature = {
195
+ eventType: string;
196
+ language: LanguageId;
197
+ framework?: string;
198
+ className?: string;
199
+ methodName?: string;
200
+ functionName?: string;
201
+ moduleName?: string;
202
+ routeMethod?: string;
203
+ routePathPattern?: string;
204
+ resourceType?: string;
205
+ resourceKey?: string;
206
+ resourceOperation?: 'read' | 'write' | 'update' | 'delete';
207
+ role?: EventRole;
208
+ };
209
+ type JsonShape = {
210
+ type: 'string' | 'number' | 'boolean' | 'object' | 'array' | 'null' | 'unknown';
211
+ properties?: Record<string, JsonShape>;
212
+ items?: JsonShape;
213
+ };
214
+ type CompactBaseline = {
215
+ schemaVersion: 'tracegraph.baseline.v1';
216
+ baselineId: string;
217
+ testId: string;
218
+ entrypoint: TraceEntrypoint;
219
+ approvedAt: number;
220
+ approvedBy: string;
221
+ reason: string;
222
+ captureLevel: number;
223
+ events: Array<{
224
+ signature: SemanticSignature;
225
+ role: string;
226
+ count: number;
227
+ critical?: boolean;
228
+ }>;
229
+ resources: Array<{
230
+ type: string;
231
+ key: string;
232
+ operation: string;
233
+ count: number;
234
+ }>;
235
+ responseShape: JsonShape;
236
+ };
237
+ type FindingSeverity = 'info' | 'low' | 'medium' | 'high' | 'critical';
238
+ type FindingCategory = 'behavior_change' | 'race_condition' | 'rate_limit' | 'idempotency' | 'retry_storm' | 'security_authentication' | 'security_authorization' | 'security_sensitive_data' | 'security_injection' | 'security_mass_assignment' | 'performance' | 'data_integrity' | 'tracegraph_policy_change';
239
+ type Finding = {
240
+ id: string;
241
+ /** Stable hash of (ruleId + semantic target + risk resource/action) — never includes file path. */
242
+ fingerprint: string;
243
+ ruleId: string;
244
+ severity: FindingSeverity;
245
+ category: FindingCategory;
246
+ title: string;
247
+ description: string;
248
+ evidence: Array<{
249
+ traceId: string;
250
+ eventIds: string[];
251
+ file?: string;
252
+ line?: number;
253
+ }>;
254
+ recommendation?: string;
255
+ };
256
+ type FindingFingerprintInput = {
257
+ ruleId: string;
258
+ semanticTarget: {
259
+ routeMethod?: string;
260
+ routePathPattern?: string;
261
+ resourceType?: string;
262
+ resourceKey?: string;
263
+ resourceOperation?: 'read' | 'write' | 'update' | 'delete';
264
+ className?: string;
265
+ methodName?: string;
266
+ functionName?: string;
267
+ role?: EventRole;
268
+ };
269
+ findingKind: string;
270
+ };
271
+ type Suppression = {
272
+ id: string;
273
+ ruleId: string;
274
+ semanticTarget: Partial<SemanticSignature>;
275
+ requiresEvidence?: Array<{
276
+ type: string;
277
+ name: string;
278
+ }>;
279
+ reason: string;
280
+ expiresAt: string;
281
+ approvedBy: string;
282
+ createdAt: string;
283
+ };
284
+ type SuppressionsFile = {
285
+ schemaVersion: 'tracegraph.suppressions.v1';
286
+ suppressions: Suppression[];
287
+ };
288
+ type FindingApproval = {
289
+ findingFingerprint: string;
290
+ ruleId: string;
291
+ semanticTarget: Partial<SemanticSignature>;
292
+ approvedBy: string;
293
+ reason: string;
294
+ expiresAt: string;
295
+ createdAt: string;
296
+ };
297
+ type FindingApprovalsFile = {
298
+ schemaVersion: 'tracegraph.finding-approvals.v1';
299
+ approvals: FindingApproval[];
300
+ };
301
+ type SignatureChange = {
302
+ signature: SemanticSignature;
303
+ identityHash: string;
304
+ role: EventRole;
305
+ critical: boolean;
306
+ /** Present for added signatures (candidate eventId). */
307
+ eventId?: string;
308
+ eventName?: string;
309
+ };
310
+ type ResourceChange = {
311
+ type: string;
312
+ key: string;
313
+ operation: string;
314
+ baselineCount: number;
315
+ candidateCount: number;
316
+ };
317
+ type ResponseShapeChange = {
318
+ addedFields: string[];
319
+ removedFields: string[];
320
+ typeChanges: Array<{
321
+ field: string;
322
+ from: string;
323
+ to: string;
324
+ }>;
325
+ };
326
+ type BehaviorDiff = {
327
+ traceId: string;
328
+ baselineId: string;
329
+ addedSignatures: SignatureChange[];
330
+ removedSignatures: SignatureChange[];
331
+ changedResources: ResourceChange[];
332
+ responseShapeChange?: ResponseShapeChange;
333
+ };
334
+ type FindingStatus = 'open' | 'approved' | 'suppressed';
335
+ type EvaluatedFinding = Finding & {
336
+ status: FindingStatus;
337
+ suppressedBy?: string;
338
+ approvedBy?: string;
339
+ approvedReason?: string;
340
+ };
341
+ type ReportSummary = {
342
+ tracesCompared: number;
343
+ findingsBySeverity: Record<FindingSeverity, number>;
344
+ hasOpenCritical: boolean;
345
+ suppressionsModified: boolean;
346
+ };
347
+ type TraceReport = {
348
+ schemaVersion: 'tracegraph.report.v1';
349
+ reportId: string;
350
+ createdAt: number;
351
+ baselineDir: string;
352
+ candidateFiles: string[];
353
+ diffs: BehaviorDiff[];
354
+ findings: EvaluatedFinding[];
355
+ summary: ReportSummary;
356
+ };
357
+ /**
358
+ * Written to `.tracegraph/latest.json` after every successful `tracegraph run`.
359
+ * Provides a stable, cross-platform pointer to the most recent run's artifacts
360
+ * without relying on symlinks (Windows-safe).
361
+ */
362
+ type LatestPointer = {
363
+ /** The run ID of the most recent `tracegraph run` invocation. */
364
+ latestRunId: string;
365
+ /** All trace IDs produced by the latest run (main + per-test). */
366
+ latestTraceIds: string[];
367
+ /** Report ID written by the most recent `tracegraph compare`, or null. */
368
+ latestReportId: string | null;
369
+ /** Unix epoch ms when this file was last written. */
370
+ updatedAt: number;
371
+ };
372
+ /**
373
+ * A TraceGraph scenario — a declarative definition of one or more servers to
374
+ * start plus an ordered sequence of HTTP steps to execute against them.
375
+ *
376
+ * Stored in `.tracegraph/scenarios/<name>.scenario.json`.
377
+ */
378
+ type ScenarioDefinition = {
379
+ schemaVersion: 'tracegraph.scenario.v1';
380
+ scenarioId: string;
381
+ name: string;
382
+ description?: string;
383
+ servers?: ScenarioServer[];
384
+ steps: ScenarioStep[];
385
+ tags?: string[];
386
+ };
387
+ /**
388
+ * A server that the scenario runner will start and manage.
389
+ * The process is spawned with `TRACEGRAPH_ENABLED=1` and related env vars so
390
+ * that the server's instrumentation can write trace files automatically.
391
+ */
392
+ type ScenarioServer = {
393
+ name: string;
394
+ /** Shell command to start the server (e.g. "node dist/server.js"). */
395
+ command: string;
396
+ port: number;
397
+ env?: Record<string, string>;
398
+ /** Maximum milliseconds to wait for the server to pass its health check. Default 30000. */
399
+ readyTimeoutMs?: number;
400
+ healthCheck?: {
401
+ /** URL path to poll (e.g. "/health"). Default "/health". */
402
+ path: string;
403
+ method?: string;
404
+ /** Expected HTTP status code. Default 200. */
405
+ expectedStatus?: number;
406
+ /** Poll interval in milliseconds. Default 500. */
407
+ intervalMs?: number;
408
+ /** Maximum number of poll attempts before giving up. Default 60. */
409
+ maxAttempts?: number;
410
+ };
411
+ };
412
+ /** One HTTP step in a scenario. */
413
+ type ScenarioStep = {
414
+ name: string;
415
+ description?: string;
416
+ http: {
417
+ method: string;
418
+ url: string;
419
+ headers?: Record<string, string>;
420
+ body?: unknown;
421
+ /** Request timeout in milliseconds. Default 30000. */
422
+ timeoutMs?: number;
423
+ };
424
+ assert?: {
425
+ /** Expected HTTP status code. */
426
+ status?: number;
427
+ /** String that must appear in the response body. */
428
+ bodyContains?: string;
429
+ };
430
+ /** Milliseconds to pause after this step before continuing. */
431
+ delayMs?: number;
432
+ };
433
+ /** Result of a single scenario step execution. */
434
+ type ScenarioStepResult = {
435
+ name: string;
436
+ status: 'passed' | 'failed' | 'skipped';
437
+ statusCode?: number;
438
+ durationMs: number;
439
+ error?: string;
440
+ };
441
+ /** Aggregate result of a full scenario run. */
442
+ type ScenarioRunResult = {
443
+ scenarioId: string;
444
+ runId: string;
445
+ bundleFile?: string;
446
+ steps: ScenarioStepResult[];
447
+ passed: boolean;
448
+ durationMs: number;
449
+ };
450
+ /**
451
+ * A function or method identified as changed by a git diff.
452
+ * Either `functionName` (standalone) or `className`+`methodName` (class method) is set.
453
+ */
454
+ type ChangedFunction = {
455
+ /** File path relative to workspace root (forward slashes). */
456
+ file: string;
457
+ /** Standalone function name — mutually exclusive with className/methodName. */
458
+ functionName?: string;
459
+ /** Class that owns the method — set together with methodName. */
460
+ className?: string;
461
+ /** Method name within the class — set together with className. */
462
+ methodName?: string;
463
+ /** Line number within the new (post-diff) file where the declaration starts. */
464
+ startLine: number;
465
+ };
466
+ /**
467
+ * A changed function that was matched by at least one runtime trace event.
468
+ */
469
+ type CoverageEntry = {
470
+ changed: ChangedFunction;
471
+ coveredBy: Array<{
472
+ traceId: string;
473
+ eventId: string;
474
+ traceFile: string;
475
+ }>;
476
+ };
477
+ /**
478
+ * Output of the AI change coverage analysis.
479
+ * Stored in `.tracegraph/reports/<id>.coverage.json`.
480
+ */
481
+ type ChangeCoverageReport = {
482
+ schemaVersion: 'tracegraph.coverage.v1';
483
+ reportId: string;
484
+ createdAt: number;
485
+ /** Git ref used as the diff base (e.g. "HEAD~1", "main"). */
486
+ baseRef: string;
487
+ /** Git ref used as the diff head (e.g. "HEAD"). */
488
+ headRef: string;
489
+ covered: CoverageEntry[];
490
+ uncovered: ChangedFunction[];
491
+ summary: {
492
+ changedFunctions: number;
493
+ coveredCount: number;
494
+ uncoveredCount: number;
495
+ /** 0–100, integer. */
496
+ coveragePercent: number;
497
+ };
498
+ };
499
+ /** AI tool format that the pack targets. */
500
+ type PromptPackFormat = 'cursor' | 'claude-code' | 'copilot' | 'mcp';
501
+ /**
502
+ * A generated AI context pack for a specific tool format.
503
+ */
504
+ type PromptPack = {
505
+ format: PromptPackFormat;
506
+ /** Rendered pack content (markdown, XML, or JSON). */
507
+ content: string;
508
+ /** Conventional file name for the pack (e.g. ".cursor/tracegraph-context.md"). */
509
+ fileName: string;
510
+ };
511
+ declare const EXIT_CODES: {
512
+ /** Wrapped command and compare both passed cleanly. */
513
+ readonly SUCCESS: 0;
514
+ /** Wrapped command (npm test, etc.) exited with non-zero. */
515
+ readonly COMMAND_FAILURE: 1;
516
+ /** Bad arguments, missing file, or internal CLI error. */
517
+ readonly CLI_ERROR: 2;
518
+ /** Open findings at or above the severity threshold (--fail-on-critical). */
519
+ readonly FINDINGS_THRESHOLD: 3;
520
+ /** Suppressions file was modified since the last approved baseline. */
521
+ readonly POLICY_REVIEW: 4;
522
+ /** Trace or baseline schema version does not match the current CLI. */
523
+ readonly SCHEMA_MIGRATION: 5;
524
+ /** Capture level is below the project-configured minimum requirement. */
525
+ readonly CAPTURE_LEVEL_INSUFFICIENT: 6;
526
+ };
527
+ type ExitCode = typeof EXIT_CODES[keyof typeof EXIT_CODES];
528
+
529
+ export { type AdapterCaptureInfo, type BehaviorDiff, type BundleLink, type CaptureLevel, type CaptureLevelValue, type ChangeCoverageReport, type ChangedFunction, type CliEventEnvelope, type CliEventType, type CompactBaseline, type ConcurrencyType, type CoverageEntry, type DetailStreams, EXIT_CODES, type EvaluatedFinding, type EventRef, type EventRole, type ExitCode, type Finding, type FindingApproval, type FindingApprovalsFile, type FindingCategory, type FindingFingerprintInput, type FindingSeverity, type FindingStatus, type FrameworkId, type JsonShape, type LanguageId, type LatestPointer, type PromptPack, type PromptPackFormat, type ReliabilityMetadata, type ReportSummary, type ResourceChange, type ResponseShapeChange, SCHEMA_VERSIONS, type SanitizedValue, type ScenarioDefinition, type ScenarioRunResult, type ScenarioServer, type ScenarioStep, type ScenarioStepResult, type SchemaVersions, type SecurityMetadata, type SemanticSignature, type SignatureChange, type Suppression, type SuppressionsFile, type TraceBundle, type TraceEntrypoint, type TraceError, type TraceEvent, type TraceEventType, type TraceIndex, type TraceIndexEntry, type TraceReport, type TraceResource, type TraceSession, type TraceSessionStatus };
@@ -0,0 +1,529 @@
1
+ declare const SCHEMA_VERSIONS: {
2
+ readonly trace: "tracegraph.trace.v1";
3
+ readonly event: "tracegraph.event.v1";
4
+ readonly baseline: "tracegraph.baseline.v1";
5
+ readonly bundle: "tracegraph.bundle.v1";
6
+ readonly report: "tracegraph.report.v1";
7
+ readonly diff: "tracegraph.diff.v1";
8
+ readonly suppression: "tracegraph.suppressions.v1";
9
+ readonly findingApproval: "tracegraph.finding-approvals.v1";
10
+ readonly scenario: "tracegraph.scenario.v1";
11
+ readonly index: "tracegraph.index.v1";
12
+ readonly coverage: "tracegraph.coverage.v1";
13
+ };
14
+ type SchemaVersions = typeof SCHEMA_VERSIONS;
15
+ type TraceEntrypoint = {
16
+ type: 'http_request';
17
+ method: string;
18
+ path: string;
19
+ handler?: string;
20
+ } | {
21
+ type: 'test_case';
22
+ testName: string;
23
+ testFile?: string;
24
+ } | {
25
+ type: 'function';
26
+ functionName: string;
27
+ file?: string;
28
+ line?: number;
29
+ } | {
30
+ type: 'cli_command';
31
+ command: string;
32
+ };
33
+ /**
34
+ * Levels:
35
+ * 0 = runner metadata only (zero config)
36
+ * 1 = framework adapters (Express middleware, Laravel hooks)
37
+ * 2 = manual traceFunction wrappers
38
+ * 3 = CJS require hook auto-instrumentation
39
+ * 4 = ESM --import hook (limited — cannot replace live bindings)
40
+ * 5 = build-time transform (Vitest reporter, Babel/SWC plugin)
41
+ */
42
+ type CaptureLevelValue = 0 | 1 | 2 | 3 | 4 | 5;
43
+ type AdapterCaptureInfo = {
44
+ level: number;
45
+ mode: string;
46
+ captured: string[];
47
+ notCaptured: string[];
48
+ recommendation?: string;
49
+ };
50
+ type CaptureLevel = {
51
+ overall: CaptureLevelValue;
52
+ label: string;
53
+ adapters: Record<string, AdapterCaptureInfo>;
54
+ };
55
+ type TraceEventType = 'trace_start' | 'trace_end' | 'http_request' | 'http_response' | 'function_call' | 'method_call' | 'db_query' | 'external_http_call' | 'file_operation' | 'cache_operation' | 'queue_event' | 'log' | 'error' | 'branch' | 'return' | 'auth_check' | 'authorization_check' | 'rate_limit_check' | 'lock_acquire' | 'lock_release' | 'transaction_start' | 'transaction_commit' | 'transaction_rollback'
56
+ /** One per test file; parent = trace_start. */
57
+ | 'test_file'
58
+ /** One per describe() block; parent = test_file or enclosing test_suite. */
59
+ | 'test_suite'
60
+ /** One per it()/test() call; parent = nearest test_suite or test_file. */
61
+ | 'test_run';
62
+ type ConcurrencyType = 'sequential' | 'parallel' | 'promise_all' | 'race' | 'background';
63
+ type LanguageId = 'typescript' | 'javascript' | 'php';
64
+ type FrameworkId = 'express' | 'nestjs' | 'nextjs' | 'fastify' | 'laravel' | 'symfony' | 'vitest' | 'jest' | 'xdebug' | 'plain';
65
+ /** Cross-trace event reference for causal links (e.g. HTTP request → dispatched job). */
66
+ type EventRef = {
67
+ traceId: string;
68
+ eventId: string;
69
+ };
70
+ type TraceError = {
71
+ type: string;
72
+ message: string;
73
+ stack?: string;
74
+ };
75
+ type TraceResource = {
76
+ type: string;
77
+ key: string;
78
+ operation: string;
79
+ };
80
+ type SanitizedValue = Record<string, unknown> | unknown[] | string | number | null;
81
+ type SecurityMetadata = Record<string, unknown>;
82
+ type ReliabilityMetadata = Record<string, unknown>;
83
+ type TraceEvent = {
84
+ schemaVersion: 'tracegraph.event.v1';
85
+ eventId: string;
86
+ traceId: string;
87
+ /** Structural parent: the containing call in the call stack. */
88
+ parentEventId?: string | null;
89
+ /**
90
+ * Causal parent: the event that caused this one.
91
+ * Same as parentEventId for synchronous calls; different for async/queue scenarios.
92
+ */
93
+ causalParentEventId?: string | null;
94
+ /**
95
+ * Cross-trace causal reference.
96
+ * Used when a job's causal parent is an event in a different trace (e.g. HTTP → queue worker).
97
+ */
98
+ causalParentRef?: EventRef | null;
99
+ /** Parallel execution grouping (Promise.all, concurrent requests). */
100
+ asyncGroupId?: string;
101
+ branchId?: string;
102
+ concurrencyType?: ConcurrencyType;
103
+ type: TraceEventType;
104
+ language: LanguageId;
105
+ name: string;
106
+ displayName?: string;
107
+ file?: string;
108
+ line?: number;
109
+ column?: number;
110
+ className?: string;
111
+ functionName?: string;
112
+ moduleName?: string;
113
+ framework?: FrameworkId;
114
+ startTime: number;
115
+ endTime?: number;
116
+ durationMs?: number;
117
+ input?: SanitizedValue;
118
+ output?: SanitizedValue;
119
+ error?: TraceError;
120
+ resource?: TraceResource;
121
+ security?: SecurityMetadata;
122
+ reliability?: ReliabilityMetadata;
123
+ tags?: string[];
124
+ metadata?: Record<string, unknown>;
125
+ };
126
+ type DetailStreams = {
127
+ xdebug?: {
128
+ events: TraceEvent[];
129
+ /** Map from semantic event ID → attached Xdebug event IDs. */
130
+ attachedTo: Record<string, string[]>;
131
+ };
132
+ };
133
+ type TraceSessionStatus = 'running' | 'passed' | 'failed' | 'error';
134
+ type TraceSession = {
135
+ schemaVersion: 'tracegraph.trace.v1';
136
+ traceId: string;
137
+ sessionId: string;
138
+ runId: string;
139
+ scenarioId?: string;
140
+ projectId?: string;
141
+ workspaceRoot: string;
142
+ language: LanguageId;
143
+ framework?: string;
144
+ entrypoint: TraceEntrypoint;
145
+ startedAt: number;
146
+ endedAt?: number;
147
+ status: TraceSessionStatus;
148
+ captureLevel: CaptureLevel;
149
+ events: TraceEvent[];
150
+ detailStreams?: DetailStreams;
151
+ metadata?: Record<string, unknown>;
152
+ };
153
+ type TraceIndexEntry = {
154
+ traceId: string;
155
+ runId: string;
156
+ file: string;
157
+ status: TraceSessionStatus;
158
+ createdAt: number;
159
+ entrypoint: TraceEntrypoint;
160
+ };
161
+ type TraceIndex = {
162
+ schemaVersion: 'tracegraph.index.v1';
163
+ traces: TraceIndexEntry[];
164
+ };
165
+ type BundleLink = {
166
+ source: EventRef;
167
+ target: EventRef;
168
+ type: 'causes' | 'correlates' | 'spawns';
169
+ correlationId: string;
170
+ };
171
+ type TraceBundle = {
172
+ schemaVersion: 'tracegraph.bundle.v1';
173
+ bundleId: string;
174
+ scenarioId: string;
175
+ createdAt: number;
176
+ traces: Array<{
177
+ language: LanguageId;
178
+ traceId: string;
179
+ file: string;
180
+ }>;
181
+ links: BundleLink[];
182
+ };
183
+ type CliEventType = 'run.started' | 'run.progress' | 'run.completed' | 'trace.started' | 'trace.progress' | 'trace.completed' | 'finding' | 'report.created' | 'approval.required' | 'error';
184
+ type CliEventEnvelope = {
185
+ protocol: 'tracegraph.cli.v1';
186
+ type: CliEventType;
187
+ runId: string;
188
+ traceId?: string;
189
+ timestamp: number;
190
+ captureLevel?: Pick<CaptureLevel, 'overall' | 'label'>;
191
+ payload?: Record<string, unknown>;
192
+ };
193
+ type EventRole = 'validation' | 'authorization' | 'business_logic' | 'db' | 'external_call';
194
+ type SemanticSignature = {
195
+ eventType: string;
196
+ language: LanguageId;
197
+ framework?: string;
198
+ className?: string;
199
+ methodName?: string;
200
+ functionName?: string;
201
+ moduleName?: string;
202
+ routeMethod?: string;
203
+ routePathPattern?: string;
204
+ resourceType?: string;
205
+ resourceKey?: string;
206
+ resourceOperation?: 'read' | 'write' | 'update' | 'delete';
207
+ role?: EventRole;
208
+ };
209
+ type JsonShape = {
210
+ type: 'string' | 'number' | 'boolean' | 'object' | 'array' | 'null' | 'unknown';
211
+ properties?: Record<string, JsonShape>;
212
+ items?: JsonShape;
213
+ };
214
+ type CompactBaseline = {
215
+ schemaVersion: 'tracegraph.baseline.v1';
216
+ baselineId: string;
217
+ testId: string;
218
+ entrypoint: TraceEntrypoint;
219
+ approvedAt: number;
220
+ approvedBy: string;
221
+ reason: string;
222
+ captureLevel: number;
223
+ events: Array<{
224
+ signature: SemanticSignature;
225
+ role: string;
226
+ count: number;
227
+ critical?: boolean;
228
+ }>;
229
+ resources: Array<{
230
+ type: string;
231
+ key: string;
232
+ operation: string;
233
+ count: number;
234
+ }>;
235
+ responseShape: JsonShape;
236
+ };
237
+ type FindingSeverity = 'info' | 'low' | 'medium' | 'high' | 'critical';
238
+ type FindingCategory = 'behavior_change' | 'race_condition' | 'rate_limit' | 'idempotency' | 'retry_storm' | 'security_authentication' | 'security_authorization' | 'security_sensitive_data' | 'security_injection' | 'security_mass_assignment' | 'performance' | 'data_integrity' | 'tracegraph_policy_change';
239
+ type Finding = {
240
+ id: string;
241
+ /** Stable hash of (ruleId + semantic target + risk resource/action) — never includes file path. */
242
+ fingerprint: string;
243
+ ruleId: string;
244
+ severity: FindingSeverity;
245
+ category: FindingCategory;
246
+ title: string;
247
+ description: string;
248
+ evidence: Array<{
249
+ traceId: string;
250
+ eventIds: string[];
251
+ file?: string;
252
+ line?: number;
253
+ }>;
254
+ recommendation?: string;
255
+ };
256
+ type FindingFingerprintInput = {
257
+ ruleId: string;
258
+ semanticTarget: {
259
+ routeMethod?: string;
260
+ routePathPattern?: string;
261
+ resourceType?: string;
262
+ resourceKey?: string;
263
+ resourceOperation?: 'read' | 'write' | 'update' | 'delete';
264
+ className?: string;
265
+ methodName?: string;
266
+ functionName?: string;
267
+ role?: EventRole;
268
+ };
269
+ findingKind: string;
270
+ };
271
+ type Suppression = {
272
+ id: string;
273
+ ruleId: string;
274
+ semanticTarget: Partial<SemanticSignature>;
275
+ requiresEvidence?: Array<{
276
+ type: string;
277
+ name: string;
278
+ }>;
279
+ reason: string;
280
+ expiresAt: string;
281
+ approvedBy: string;
282
+ createdAt: string;
283
+ };
284
+ type SuppressionsFile = {
285
+ schemaVersion: 'tracegraph.suppressions.v1';
286
+ suppressions: Suppression[];
287
+ };
288
+ type FindingApproval = {
289
+ findingFingerprint: string;
290
+ ruleId: string;
291
+ semanticTarget: Partial<SemanticSignature>;
292
+ approvedBy: string;
293
+ reason: string;
294
+ expiresAt: string;
295
+ createdAt: string;
296
+ };
297
+ type FindingApprovalsFile = {
298
+ schemaVersion: 'tracegraph.finding-approvals.v1';
299
+ approvals: FindingApproval[];
300
+ };
301
+ type SignatureChange = {
302
+ signature: SemanticSignature;
303
+ identityHash: string;
304
+ role: EventRole;
305
+ critical: boolean;
306
+ /** Present for added signatures (candidate eventId). */
307
+ eventId?: string;
308
+ eventName?: string;
309
+ };
310
+ type ResourceChange = {
311
+ type: string;
312
+ key: string;
313
+ operation: string;
314
+ baselineCount: number;
315
+ candidateCount: number;
316
+ };
317
+ type ResponseShapeChange = {
318
+ addedFields: string[];
319
+ removedFields: string[];
320
+ typeChanges: Array<{
321
+ field: string;
322
+ from: string;
323
+ to: string;
324
+ }>;
325
+ };
326
+ type BehaviorDiff = {
327
+ traceId: string;
328
+ baselineId: string;
329
+ addedSignatures: SignatureChange[];
330
+ removedSignatures: SignatureChange[];
331
+ changedResources: ResourceChange[];
332
+ responseShapeChange?: ResponseShapeChange;
333
+ };
334
+ type FindingStatus = 'open' | 'approved' | 'suppressed';
335
+ type EvaluatedFinding = Finding & {
336
+ status: FindingStatus;
337
+ suppressedBy?: string;
338
+ approvedBy?: string;
339
+ approvedReason?: string;
340
+ };
341
+ type ReportSummary = {
342
+ tracesCompared: number;
343
+ findingsBySeverity: Record<FindingSeverity, number>;
344
+ hasOpenCritical: boolean;
345
+ suppressionsModified: boolean;
346
+ };
347
+ type TraceReport = {
348
+ schemaVersion: 'tracegraph.report.v1';
349
+ reportId: string;
350
+ createdAt: number;
351
+ baselineDir: string;
352
+ candidateFiles: string[];
353
+ diffs: BehaviorDiff[];
354
+ findings: EvaluatedFinding[];
355
+ summary: ReportSummary;
356
+ };
357
+ /**
358
+ * Written to `.tracegraph/latest.json` after every successful `tracegraph run`.
359
+ * Provides a stable, cross-platform pointer to the most recent run's artifacts
360
+ * without relying on symlinks (Windows-safe).
361
+ */
362
+ type LatestPointer = {
363
+ /** The run ID of the most recent `tracegraph run` invocation. */
364
+ latestRunId: string;
365
+ /** All trace IDs produced by the latest run (main + per-test). */
366
+ latestTraceIds: string[];
367
+ /** Report ID written by the most recent `tracegraph compare`, or null. */
368
+ latestReportId: string | null;
369
+ /** Unix epoch ms when this file was last written. */
370
+ updatedAt: number;
371
+ };
372
+ /**
373
+ * A TraceGraph scenario — a declarative definition of one or more servers to
374
+ * start plus an ordered sequence of HTTP steps to execute against them.
375
+ *
376
+ * Stored in `.tracegraph/scenarios/<name>.scenario.json`.
377
+ */
378
+ type ScenarioDefinition = {
379
+ schemaVersion: 'tracegraph.scenario.v1';
380
+ scenarioId: string;
381
+ name: string;
382
+ description?: string;
383
+ servers?: ScenarioServer[];
384
+ steps: ScenarioStep[];
385
+ tags?: string[];
386
+ };
387
+ /**
388
+ * A server that the scenario runner will start and manage.
389
+ * The process is spawned with `TRACEGRAPH_ENABLED=1` and related env vars so
390
+ * that the server's instrumentation can write trace files automatically.
391
+ */
392
+ type ScenarioServer = {
393
+ name: string;
394
+ /** Shell command to start the server (e.g. "node dist/server.js"). */
395
+ command: string;
396
+ port: number;
397
+ env?: Record<string, string>;
398
+ /** Maximum milliseconds to wait for the server to pass its health check. Default 30000. */
399
+ readyTimeoutMs?: number;
400
+ healthCheck?: {
401
+ /** URL path to poll (e.g. "/health"). Default "/health". */
402
+ path: string;
403
+ method?: string;
404
+ /** Expected HTTP status code. Default 200. */
405
+ expectedStatus?: number;
406
+ /** Poll interval in milliseconds. Default 500. */
407
+ intervalMs?: number;
408
+ /** Maximum number of poll attempts before giving up. Default 60. */
409
+ maxAttempts?: number;
410
+ };
411
+ };
412
+ /** One HTTP step in a scenario. */
413
+ type ScenarioStep = {
414
+ name: string;
415
+ description?: string;
416
+ http: {
417
+ method: string;
418
+ url: string;
419
+ headers?: Record<string, string>;
420
+ body?: unknown;
421
+ /** Request timeout in milliseconds. Default 30000. */
422
+ timeoutMs?: number;
423
+ };
424
+ assert?: {
425
+ /** Expected HTTP status code. */
426
+ status?: number;
427
+ /** String that must appear in the response body. */
428
+ bodyContains?: string;
429
+ };
430
+ /** Milliseconds to pause after this step before continuing. */
431
+ delayMs?: number;
432
+ };
433
+ /** Result of a single scenario step execution. */
434
+ type ScenarioStepResult = {
435
+ name: string;
436
+ status: 'passed' | 'failed' | 'skipped';
437
+ statusCode?: number;
438
+ durationMs: number;
439
+ error?: string;
440
+ };
441
+ /** Aggregate result of a full scenario run. */
442
+ type ScenarioRunResult = {
443
+ scenarioId: string;
444
+ runId: string;
445
+ bundleFile?: string;
446
+ steps: ScenarioStepResult[];
447
+ passed: boolean;
448
+ durationMs: number;
449
+ };
450
+ /**
451
+ * A function or method identified as changed by a git diff.
452
+ * Either `functionName` (standalone) or `className`+`methodName` (class method) is set.
453
+ */
454
+ type ChangedFunction = {
455
+ /** File path relative to workspace root (forward slashes). */
456
+ file: string;
457
+ /** Standalone function name — mutually exclusive with className/methodName. */
458
+ functionName?: string;
459
+ /** Class that owns the method — set together with methodName. */
460
+ className?: string;
461
+ /** Method name within the class — set together with className. */
462
+ methodName?: string;
463
+ /** Line number within the new (post-diff) file where the declaration starts. */
464
+ startLine: number;
465
+ };
466
+ /**
467
+ * A changed function that was matched by at least one runtime trace event.
468
+ */
469
+ type CoverageEntry = {
470
+ changed: ChangedFunction;
471
+ coveredBy: Array<{
472
+ traceId: string;
473
+ eventId: string;
474
+ traceFile: string;
475
+ }>;
476
+ };
477
+ /**
478
+ * Output of the AI change coverage analysis.
479
+ * Stored in `.tracegraph/reports/<id>.coverage.json`.
480
+ */
481
+ type ChangeCoverageReport = {
482
+ schemaVersion: 'tracegraph.coverage.v1';
483
+ reportId: string;
484
+ createdAt: number;
485
+ /** Git ref used as the diff base (e.g. "HEAD~1", "main"). */
486
+ baseRef: string;
487
+ /** Git ref used as the diff head (e.g. "HEAD"). */
488
+ headRef: string;
489
+ covered: CoverageEntry[];
490
+ uncovered: ChangedFunction[];
491
+ summary: {
492
+ changedFunctions: number;
493
+ coveredCount: number;
494
+ uncoveredCount: number;
495
+ /** 0–100, integer. */
496
+ coveragePercent: number;
497
+ };
498
+ };
499
+ /** AI tool format that the pack targets. */
500
+ type PromptPackFormat = 'cursor' | 'claude-code' | 'copilot' | 'mcp';
501
+ /**
502
+ * A generated AI context pack for a specific tool format.
503
+ */
504
+ type PromptPack = {
505
+ format: PromptPackFormat;
506
+ /** Rendered pack content (markdown, XML, or JSON). */
507
+ content: string;
508
+ /** Conventional file name for the pack (e.g. ".cursor/tracegraph-context.md"). */
509
+ fileName: string;
510
+ };
511
+ declare const EXIT_CODES: {
512
+ /** Wrapped command and compare both passed cleanly. */
513
+ readonly SUCCESS: 0;
514
+ /** Wrapped command (npm test, etc.) exited with non-zero. */
515
+ readonly COMMAND_FAILURE: 1;
516
+ /** Bad arguments, missing file, or internal CLI error. */
517
+ readonly CLI_ERROR: 2;
518
+ /** Open findings at or above the severity threshold (--fail-on-critical). */
519
+ readonly FINDINGS_THRESHOLD: 3;
520
+ /** Suppressions file was modified since the last approved baseline. */
521
+ readonly POLICY_REVIEW: 4;
522
+ /** Trace or baseline schema version does not match the current CLI. */
523
+ readonly SCHEMA_MIGRATION: 5;
524
+ /** Capture level is below the project-configured minimum requirement. */
525
+ readonly CAPTURE_LEVEL_INSUFFICIENT: 6;
526
+ };
527
+ type ExitCode = typeof EXIT_CODES[keyof typeof EXIT_CODES];
528
+
529
+ export { type AdapterCaptureInfo, type BehaviorDiff, type BundleLink, type CaptureLevel, type CaptureLevelValue, type ChangeCoverageReport, type ChangedFunction, type CliEventEnvelope, type CliEventType, type CompactBaseline, type ConcurrencyType, type CoverageEntry, type DetailStreams, EXIT_CODES, type EvaluatedFinding, type EventRef, type EventRole, type ExitCode, type Finding, type FindingApproval, type FindingApprovalsFile, type FindingCategory, type FindingFingerprintInput, type FindingSeverity, type FindingStatus, type FrameworkId, type JsonShape, type LanguageId, type LatestPointer, type PromptPack, type PromptPackFormat, type ReliabilityMetadata, type ReportSummary, type ResourceChange, type ResponseShapeChange, SCHEMA_VERSIONS, type SanitizedValue, type ScenarioDefinition, type ScenarioRunResult, type ScenarioServer, type ScenarioStep, type ScenarioStepResult, type SchemaVersions, type SecurityMetadata, type SemanticSignature, type SignatureChange, type Suppression, type SuppressionsFile, type TraceBundle, type TraceEntrypoint, type TraceError, type TraceEvent, type TraceEventType, type TraceIndex, type TraceIndexEntry, type TraceReport, type TraceResource, type TraceSession, type TraceSessionStatus };
package/dist/index.js ADDED
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ EXIT_CODES: () => EXIT_CODES,
24
+ SCHEMA_VERSIONS: () => SCHEMA_VERSIONS
25
+ });
26
+ module.exports = __toCommonJS(index_exports);
27
+ var SCHEMA_VERSIONS = {
28
+ trace: "tracegraph.trace.v1",
29
+ event: "tracegraph.event.v1",
30
+ baseline: "tracegraph.baseline.v1",
31
+ bundle: "tracegraph.bundle.v1",
32
+ report: "tracegraph.report.v1",
33
+ diff: "tracegraph.diff.v1",
34
+ suppression: "tracegraph.suppressions.v1",
35
+ findingApproval: "tracegraph.finding-approvals.v1",
36
+ scenario: "tracegraph.scenario.v1",
37
+ index: "tracegraph.index.v1",
38
+ coverage: "tracegraph.coverage.v1"
39
+ };
40
+ var EXIT_CODES = {
41
+ /** Wrapped command and compare both passed cleanly. */
42
+ SUCCESS: 0,
43
+ /** Wrapped command (npm test, etc.) exited with non-zero. */
44
+ COMMAND_FAILURE: 1,
45
+ /** Bad arguments, missing file, or internal CLI error. */
46
+ CLI_ERROR: 2,
47
+ /** Open findings at or above the severity threshold (--fail-on-critical). */
48
+ FINDINGS_THRESHOLD: 3,
49
+ /** Suppressions file was modified since the last approved baseline. */
50
+ POLICY_REVIEW: 4,
51
+ /** Trace or baseline schema version does not match the current CLI. */
52
+ SCHEMA_MIGRATION: 5,
53
+ /** Capture level is below the project-configured minimum requirement. */
54
+ CAPTURE_LEVEL_INSUFFICIENT: 6
55
+ };
56
+ // Annotate the CommonJS export names for ESM import in node:
57
+ 0 && (module.exports = {
58
+ EXIT_CODES,
59
+ SCHEMA_VERSIONS
60
+ });
package/dist/index.mjs ADDED
@@ -0,0 +1,34 @@
1
+ // src/index.ts
2
+ var SCHEMA_VERSIONS = {
3
+ trace: "tracegraph.trace.v1",
4
+ event: "tracegraph.event.v1",
5
+ baseline: "tracegraph.baseline.v1",
6
+ bundle: "tracegraph.bundle.v1",
7
+ report: "tracegraph.report.v1",
8
+ diff: "tracegraph.diff.v1",
9
+ suppression: "tracegraph.suppressions.v1",
10
+ findingApproval: "tracegraph.finding-approvals.v1",
11
+ scenario: "tracegraph.scenario.v1",
12
+ index: "tracegraph.index.v1",
13
+ coverage: "tracegraph.coverage.v1"
14
+ };
15
+ var EXIT_CODES = {
16
+ /** Wrapped command and compare both passed cleanly. */
17
+ SUCCESS: 0,
18
+ /** Wrapped command (npm test, etc.) exited with non-zero. */
19
+ COMMAND_FAILURE: 1,
20
+ /** Bad arguments, missing file, or internal CLI error. */
21
+ CLI_ERROR: 2,
22
+ /** Open findings at or above the severity threshold (--fail-on-critical). */
23
+ FINDINGS_THRESHOLD: 3,
24
+ /** Suppressions file was modified since the last approved baseline. */
25
+ POLICY_REVIEW: 4,
26
+ /** Trace or baseline schema version does not match the current CLI. */
27
+ SCHEMA_MIGRATION: 5,
28
+ /** Capture level is below the project-configured minimum requirement. */
29
+ CAPTURE_LEVEL_INSUFFICIENT: 6
30
+ };
31
+ export {
32
+ EXIT_CODES,
33
+ SCHEMA_VERSIONS
34
+ };
package/package.json ADDED
@@ -0,0 +1,25 @@
1
+ {
2
+ "name": "@tracegraph/shared-types",
3
+ "version": "0.1.0",
4
+ "description": "Canonical TypeScript types and schema version constants for TraceGraph",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.mjs",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.mjs",
12
+ "require": "./dist/index.js"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist"
17
+ ],
18
+ "publishConfig": {
19
+ "access": "public"
20
+ },
21
+ "scripts": {
22
+ "build": "tsup src/index.ts --format cjs,esm --dts",
23
+ "typecheck": "tsc --noEmit"
24
+ }
25
+ }