@tracegraph/graph-engine 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 +181 -0
- package/dist/index.d.mts +166 -0
- package/dist/index.d.ts +166 -0
- package/dist/index.js +937 -0
- package/dist/index.mjs +898 -0
- package/package.json +29 -0
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.
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import { TraceEvent, CaptureLevel, TraceSession, EventRole, SemanticSignature, TraceEntrypoint, JsonShape, CompactBaseline, BehaviorDiff, SignatureChange, Finding, Suppression, FindingApproval, EvaluatedFinding } from '@tracegraph/shared-types';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* T1.6 — Graph engine
|
|
5
|
+
*
|
|
6
|
+
* Converts a finalised TraceSession into a TraceGraph suitable for rendering.
|
|
7
|
+
*
|
|
8
|
+
* Design decisions (ARCHITECTURE.md §9):
|
|
9
|
+
* - Events from node_modules / vendor directories are collapsed into a single
|
|
10
|
+
* node per package, keeping the graph focused on application code.
|
|
11
|
+
* - Edges are derived from the parentEventId chain.
|
|
12
|
+
* - asyncGroupId members are marked as parallel_branch edges.
|
|
13
|
+
* - tracegraph_xdebug_marker events are stripped.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
type GraphNodeType = 'http_request' | 'http_response' | 'function_call' | 'method_call' | 'return' | 'db_query' | 'external_http_call' | 'auth_check' | 'authorization_check' | 'error' | 'log' | 'queue_event' | 'trace_start' | 'trace_end' | 'test_file' | 'test_suite' | 'test_run' | 'vendor' | 'other';
|
|
17
|
+
type GraphNode = {
|
|
18
|
+
/** Stable node ID (equals eventId, or 'vendor__<pkg>' for collapsed packages). */
|
|
19
|
+
id: string;
|
|
20
|
+
label: string;
|
|
21
|
+
displayName?: string;
|
|
22
|
+
type: GraphNodeType;
|
|
23
|
+
language: string;
|
|
24
|
+
framework?: string;
|
|
25
|
+
durationMs?: number;
|
|
26
|
+
file?: string;
|
|
27
|
+
line?: number;
|
|
28
|
+
/** Hex colour string for the node. */
|
|
29
|
+
color: string;
|
|
30
|
+
/** Visual size (1–10 scale). */
|
|
31
|
+
size: number;
|
|
32
|
+
/** The original TraceEvent that produced this node. */
|
|
33
|
+
data: TraceEvent;
|
|
34
|
+
};
|
|
35
|
+
type GraphEdgeType = 'parent' | 'parallel_branch';
|
|
36
|
+
type GraphEdge = {
|
|
37
|
+
id: string;
|
|
38
|
+
source: string;
|
|
39
|
+
target: string;
|
|
40
|
+
label?: string;
|
|
41
|
+
type: GraphEdgeType;
|
|
42
|
+
};
|
|
43
|
+
type TraceGraph = {
|
|
44
|
+
nodes: GraphNode[];
|
|
45
|
+
edges: GraphEdge[];
|
|
46
|
+
captureLevel: CaptureLevel;
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Converts a TraceSession into a graph structure with nodes and edges.
|
|
50
|
+
*
|
|
51
|
+
* @returns A TraceGraph suitable for passing to the webview renderer.
|
|
52
|
+
*/
|
|
53
|
+
declare function traceSessionToGraph(session: TraceSession): TraceGraph;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Classify an event into a semantic role.
|
|
57
|
+
* Auth events → "authorization"; validation-named functions → "validation";
|
|
58
|
+
* db_query → "db"; external_http_call → "external_call"; else → "business_logic".
|
|
59
|
+
*/
|
|
60
|
+
declare function classifyRole(event: TraceEvent): EventRole;
|
|
61
|
+
/**
|
|
62
|
+
* Extract a `SemanticSignature` from a `TraceEvent`.
|
|
63
|
+
* The signature is identity-stable across file moves and line changes.
|
|
64
|
+
*/
|
|
65
|
+
declare function eventToSignature(event: TraceEvent): SemanticSignature;
|
|
66
|
+
/**
|
|
67
|
+
* Produce a stable 16-char hex hash from a `SemanticSignature`.
|
|
68
|
+
*
|
|
69
|
+
* Fields included (in order): eventType, language, framework, className,
|
|
70
|
+
* methodName, functionName, routeMethod, routePathPattern, resourceType,
|
|
71
|
+
* resourceKey, resourceOperation, role.
|
|
72
|
+
*
|
|
73
|
+
* Fields NEVER included: file, line, column, packageName, eventId, traceId.
|
|
74
|
+
*/
|
|
75
|
+
declare function signatureToIdentityHash(sig: SemanticSignature): string;
|
|
76
|
+
|
|
77
|
+
type BaselineMeta = {
|
|
78
|
+
approvedBy: string;
|
|
79
|
+
reason: string;
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
* Convert a `TraceSession` into a `CompactBaseline`.
|
|
83
|
+
*
|
|
84
|
+
* @param session The finalised trace session to baseline.
|
|
85
|
+
* @param meta Who approved this baseline and why.
|
|
86
|
+
*/
|
|
87
|
+
declare function sessionToBaseline(session: TraceSession, meta: BaselineMeta): CompactBaseline;
|
|
88
|
+
/**
|
|
89
|
+
* Derive a stable `testId` from a trace entrypoint.
|
|
90
|
+
* Two sessions covering the same route/test get the same testId.
|
|
91
|
+
*/
|
|
92
|
+
declare function deriveTestId(entrypoint: TraceEntrypoint): string;
|
|
93
|
+
/**
|
|
94
|
+
* Recursively extract a `JsonShape` from a sanitised value.
|
|
95
|
+
* Arrays capture one representative element shape only.
|
|
96
|
+
*/
|
|
97
|
+
declare function extractShape(value: unknown, depth?: number, maxDepth?: number): JsonShape;
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* T2.4 — BehaviorDiff engine — Structure mode
|
|
101
|
+
*
|
|
102
|
+
* Compares a CompactBaseline against a candidate TraceSession to produce
|
|
103
|
+
* a BehaviorDiff describing:
|
|
104
|
+
* - Signatures present in baseline but absent in candidate (removedSignatures)
|
|
105
|
+
* - Signatures present in candidate but absent in baseline (addedSignatures)
|
|
106
|
+
* - Resource operation count changes
|
|
107
|
+
* - Response shape changes (added/removed fields, type changes)
|
|
108
|
+
*
|
|
109
|
+
* Volatile values in candidate event outputs are normalised before comparison
|
|
110
|
+
* so that changing IDs (INV-001 vs INV-523) do not produce false diffs.
|
|
111
|
+
*/
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Diff a `CompactBaseline` against a candidate `TraceSession`.
|
|
115
|
+
*
|
|
116
|
+
* The candidate's event outputs are normalised via `normaliseForDiff()` before
|
|
117
|
+
* shape comparison so that volatile values (UUIDs, IDs, timestamps) do not
|
|
118
|
+
* produce noise findings.
|
|
119
|
+
*/
|
|
120
|
+
declare function diffBaseline(baseline: CompactBaseline, candidate: TraceSession): BehaviorDiff;
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Convert a `BehaviorDiff` into a list of `Finding` objects.
|
|
124
|
+
*/
|
|
125
|
+
declare function diffToFindings(diff: BehaviorDiff): Finding[];
|
|
126
|
+
/**
|
|
127
|
+
* Compute a stable 16-hex-char fingerprint for a finding.
|
|
128
|
+
* Never includes file path, line, or column.
|
|
129
|
+
*/
|
|
130
|
+
declare function computeFingerprint(input: {
|
|
131
|
+
ruleId: string;
|
|
132
|
+
removed: SignatureChange;
|
|
133
|
+
}): string;
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* T2.6 — Approval and suppression evaluator
|
|
137
|
+
*
|
|
138
|
+
* For each Finding, determines its effective status:
|
|
139
|
+
* "approved" — a non-expired FindingApproval matches by fingerprint
|
|
140
|
+
* "suppressed" — a Suppression matches by ruleId + semanticTarget AND all
|
|
141
|
+
* requiresEvidence items exist in the candidate session
|
|
142
|
+
* "open" — no matching approval or suppression
|
|
143
|
+
*
|
|
144
|
+
* requiresEvidence self-invalidation:
|
|
145
|
+
* A suppression that requires `authorization_check:RolePolicy.update` is only
|
|
146
|
+
* effective when that event actually appears in the candidate trace. If the
|
|
147
|
+
* compensating function disappears, the suppression becomes invalid and the
|
|
148
|
+
* finding surfaces as "open" (Critical if the original finding was Critical).
|
|
149
|
+
*
|
|
150
|
+
*/
|
|
151
|
+
|
|
152
|
+
declare function evaluateFindings(findings: Finding[], session: TraceSession, suppressions: Suppression[], approvals: FindingApproval[]): EvaluatedFinding[];
|
|
153
|
+
|
|
154
|
+
declare const ANALYSE_RULES: {
|
|
155
|
+
readonly SENSITIVE_DATA_IN_RESPONSE: "security.sensitive_data.in_response";
|
|
156
|
+
readonly N_PLUS_ONE_QUERY: "reliability.n_plus_one_query";
|
|
157
|
+
readonly DUPLICATE_SIDE_EFFECTS: "reliability.duplicate_side_effects";
|
|
158
|
+
readonly MISSING_TRANSACTION: "reliability.missing_transaction";
|
|
159
|
+
};
|
|
160
|
+
/**
|
|
161
|
+
* Analyse a single `TraceSession` for intrinsic security and reliability
|
|
162
|
+
* findings (independent of any baseline comparison).
|
|
163
|
+
*/
|
|
164
|
+
declare function analyseTraceFindings(session: TraceSession): Finding[];
|
|
165
|
+
|
|
166
|
+
export { ANALYSE_RULES, type BaselineMeta, type GraphEdge, type GraphEdgeType, type GraphNode, type GraphNodeType, type TraceGraph, analyseTraceFindings, classifyRole, computeFingerprint, deriveTestId, diffBaseline, diffToFindings, evaluateFindings, eventToSignature, extractShape, sessionToBaseline, signatureToIdentityHash, traceSessionToGraph };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import { TraceEvent, CaptureLevel, TraceSession, EventRole, SemanticSignature, TraceEntrypoint, JsonShape, CompactBaseline, BehaviorDiff, SignatureChange, Finding, Suppression, FindingApproval, EvaluatedFinding } from '@tracegraph/shared-types';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* T1.6 — Graph engine
|
|
5
|
+
*
|
|
6
|
+
* Converts a finalised TraceSession into a TraceGraph suitable for rendering.
|
|
7
|
+
*
|
|
8
|
+
* Design decisions (ARCHITECTURE.md §9):
|
|
9
|
+
* - Events from node_modules / vendor directories are collapsed into a single
|
|
10
|
+
* node per package, keeping the graph focused on application code.
|
|
11
|
+
* - Edges are derived from the parentEventId chain.
|
|
12
|
+
* - asyncGroupId members are marked as parallel_branch edges.
|
|
13
|
+
* - tracegraph_xdebug_marker events are stripped.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
type GraphNodeType = 'http_request' | 'http_response' | 'function_call' | 'method_call' | 'return' | 'db_query' | 'external_http_call' | 'auth_check' | 'authorization_check' | 'error' | 'log' | 'queue_event' | 'trace_start' | 'trace_end' | 'test_file' | 'test_suite' | 'test_run' | 'vendor' | 'other';
|
|
17
|
+
type GraphNode = {
|
|
18
|
+
/** Stable node ID (equals eventId, or 'vendor__<pkg>' for collapsed packages). */
|
|
19
|
+
id: string;
|
|
20
|
+
label: string;
|
|
21
|
+
displayName?: string;
|
|
22
|
+
type: GraphNodeType;
|
|
23
|
+
language: string;
|
|
24
|
+
framework?: string;
|
|
25
|
+
durationMs?: number;
|
|
26
|
+
file?: string;
|
|
27
|
+
line?: number;
|
|
28
|
+
/** Hex colour string for the node. */
|
|
29
|
+
color: string;
|
|
30
|
+
/** Visual size (1–10 scale). */
|
|
31
|
+
size: number;
|
|
32
|
+
/** The original TraceEvent that produced this node. */
|
|
33
|
+
data: TraceEvent;
|
|
34
|
+
};
|
|
35
|
+
type GraphEdgeType = 'parent' | 'parallel_branch';
|
|
36
|
+
type GraphEdge = {
|
|
37
|
+
id: string;
|
|
38
|
+
source: string;
|
|
39
|
+
target: string;
|
|
40
|
+
label?: string;
|
|
41
|
+
type: GraphEdgeType;
|
|
42
|
+
};
|
|
43
|
+
type TraceGraph = {
|
|
44
|
+
nodes: GraphNode[];
|
|
45
|
+
edges: GraphEdge[];
|
|
46
|
+
captureLevel: CaptureLevel;
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Converts a TraceSession into a graph structure with nodes and edges.
|
|
50
|
+
*
|
|
51
|
+
* @returns A TraceGraph suitable for passing to the webview renderer.
|
|
52
|
+
*/
|
|
53
|
+
declare function traceSessionToGraph(session: TraceSession): TraceGraph;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Classify an event into a semantic role.
|
|
57
|
+
* Auth events → "authorization"; validation-named functions → "validation";
|
|
58
|
+
* db_query → "db"; external_http_call → "external_call"; else → "business_logic".
|
|
59
|
+
*/
|
|
60
|
+
declare function classifyRole(event: TraceEvent): EventRole;
|
|
61
|
+
/**
|
|
62
|
+
* Extract a `SemanticSignature` from a `TraceEvent`.
|
|
63
|
+
* The signature is identity-stable across file moves and line changes.
|
|
64
|
+
*/
|
|
65
|
+
declare function eventToSignature(event: TraceEvent): SemanticSignature;
|
|
66
|
+
/**
|
|
67
|
+
* Produce a stable 16-char hex hash from a `SemanticSignature`.
|
|
68
|
+
*
|
|
69
|
+
* Fields included (in order): eventType, language, framework, className,
|
|
70
|
+
* methodName, functionName, routeMethod, routePathPattern, resourceType,
|
|
71
|
+
* resourceKey, resourceOperation, role.
|
|
72
|
+
*
|
|
73
|
+
* Fields NEVER included: file, line, column, packageName, eventId, traceId.
|
|
74
|
+
*/
|
|
75
|
+
declare function signatureToIdentityHash(sig: SemanticSignature): string;
|
|
76
|
+
|
|
77
|
+
type BaselineMeta = {
|
|
78
|
+
approvedBy: string;
|
|
79
|
+
reason: string;
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
* Convert a `TraceSession` into a `CompactBaseline`.
|
|
83
|
+
*
|
|
84
|
+
* @param session The finalised trace session to baseline.
|
|
85
|
+
* @param meta Who approved this baseline and why.
|
|
86
|
+
*/
|
|
87
|
+
declare function sessionToBaseline(session: TraceSession, meta: BaselineMeta): CompactBaseline;
|
|
88
|
+
/**
|
|
89
|
+
* Derive a stable `testId` from a trace entrypoint.
|
|
90
|
+
* Two sessions covering the same route/test get the same testId.
|
|
91
|
+
*/
|
|
92
|
+
declare function deriveTestId(entrypoint: TraceEntrypoint): string;
|
|
93
|
+
/**
|
|
94
|
+
* Recursively extract a `JsonShape` from a sanitised value.
|
|
95
|
+
* Arrays capture one representative element shape only.
|
|
96
|
+
*/
|
|
97
|
+
declare function extractShape(value: unknown, depth?: number, maxDepth?: number): JsonShape;
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* T2.4 — BehaviorDiff engine — Structure mode
|
|
101
|
+
*
|
|
102
|
+
* Compares a CompactBaseline against a candidate TraceSession to produce
|
|
103
|
+
* a BehaviorDiff describing:
|
|
104
|
+
* - Signatures present in baseline but absent in candidate (removedSignatures)
|
|
105
|
+
* - Signatures present in candidate but absent in baseline (addedSignatures)
|
|
106
|
+
* - Resource operation count changes
|
|
107
|
+
* - Response shape changes (added/removed fields, type changes)
|
|
108
|
+
*
|
|
109
|
+
* Volatile values in candidate event outputs are normalised before comparison
|
|
110
|
+
* so that changing IDs (INV-001 vs INV-523) do not produce false diffs.
|
|
111
|
+
*/
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Diff a `CompactBaseline` against a candidate `TraceSession`.
|
|
115
|
+
*
|
|
116
|
+
* The candidate's event outputs are normalised via `normaliseForDiff()` before
|
|
117
|
+
* shape comparison so that volatile values (UUIDs, IDs, timestamps) do not
|
|
118
|
+
* produce noise findings.
|
|
119
|
+
*/
|
|
120
|
+
declare function diffBaseline(baseline: CompactBaseline, candidate: TraceSession): BehaviorDiff;
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Convert a `BehaviorDiff` into a list of `Finding` objects.
|
|
124
|
+
*/
|
|
125
|
+
declare function diffToFindings(diff: BehaviorDiff): Finding[];
|
|
126
|
+
/**
|
|
127
|
+
* Compute a stable 16-hex-char fingerprint for a finding.
|
|
128
|
+
* Never includes file path, line, or column.
|
|
129
|
+
*/
|
|
130
|
+
declare function computeFingerprint(input: {
|
|
131
|
+
ruleId: string;
|
|
132
|
+
removed: SignatureChange;
|
|
133
|
+
}): string;
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* T2.6 — Approval and suppression evaluator
|
|
137
|
+
*
|
|
138
|
+
* For each Finding, determines its effective status:
|
|
139
|
+
* "approved" — a non-expired FindingApproval matches by fingerprint
|
|
140
|
+
* "suppressed" — a Suppression matches by ruleId + semanticTarget AND all
|
|
141
|
+
* requiresEvidence items exist in the candidate session
|
|
142
|
+
* "open" — no matching approval or suppression
|
|
143
|
+
*
|
|
144
|
+
* requiresEvidence self-invalidation:
|
|
145
|
+
* A suppression that requires `authorization_check:RolePolicy.update` is only
|
|
146
|
+
* effective when that event actually appears in the candidate trace. If the
|
|
147
|
+
* compensating function disappears, the suppression becomes invalid and the
|
|
148
|
+
* finding surfaces as "open" (Critical if the original finding was Critical).
|
|
149
|
+
*
|
|
150
|
+
*/
|
|
151
|
+
|
|
152
|
+
declare function evaluateFindings(findings: Finding[], session: TraceSession, suppressions: Suppression[], approvals: FindingApproval[]): EvaluatedFinding[];
|
|
153
|
+
|
|
154
|
+
declare const ANALYSE_RULES: {
|
|
155
|
+
readonly SENSITIVE_DATA_IN_RESPONSE: "security.sensitive_data.in_response";
|
|
156
|
+
readonly N_PLUS_ONE_QUERY: "reliability.n_plus_one_query";
|
|
157
|
+
readonly DUPLICATE_SIDE_EFFECTS: "reliability.duplicate_side_effects";
|
|
158
|
+
readonly MISSING_TRANSACTION: "reliability.missing_transaction";
|
|
159
|
+
};
|
|
160
|
+
/**
|
|
161
|
+
* Analyse a single `TraceSession` for intrinsic security and reliability
|
|
162
|
+
* findings (independent of any baseline comparison).
|
|
163
|
+
*/
|
|
164
|
+
declare function analyseTraceFindings(session: TraceSession): Finding[];
|
|
165
|
+
|
|
166
|
+
export { ANALYSE_RULES, type BaselineMeta, type GraphEdge, type GraphEdgeType, type GraphNode, type GraphNodeType, type TraceGraph, analyseTraceFindings, classifyRole, computeFingerprint, deriveTestId, diffBaseline, diffToFindings, evaluateFindings, eventToSignature, extractShape, sessionToBaseline, signatureToIdentityHash, traceSessionToGraph };
|