@principal-ai/subsystems-core 0.51.3 → 0.51.5
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/README.md +21 -0
- package/dist/audit/boundary.d.ts +104 -0
- package/dist/audit/boundary.d.ts.map +1 -0
- package/dist/audit/boundary.js +363 -0
- package/dist/audit/boundary.js.map +1 -0
- package/dist/audit/c4.d.ts +41 -0
- package/dist/audit/c4.d.ts.map +1 -0
- package/dist/audit/c4.js +41 -0
- package/dist/audit/c4.js.map +1 -0
- package/dist/audit/engine.d.ts +135 -0
- package/dist/audit/engine.d.ts.map +1 -0
- package/dist/audit/engine.js +828 -0
- package/dist/audit/engine.js.map +1 -0
- package/dist/audit/fixes.d.ts +80 -0
- package/dist/audit/fixes.d.ts.map +1 -0
- package/dist/audit/fixes.js +162 -0
- package/dist/audit/fixes.js.map +1 -0
- package/dist/audit/graphify-provider.d.ts +51 -0
- package/dist/audit/graphify-provider.d.ts.map +1 -0
- package/dist/audit/graphify-provider.js +36 -0
- package/dist/audit/graphify-provider.js.map +1 -0
- package/dist/audit/hash.d.ts +25 -0
- package/dist/audit/hash.d.ts.map +1 -0
- package/dist/audit/hash.js +53 -0
- package/dist/audit/hash.js.map +1 -0
- package/dist/audit/index.d.ts +12 -0
- package/dist/audit/index.d.ts.map +1 -0
- package/dist/audit/index.js +40 -0
- package/dist/audit/index.js.map +1 -0
- package/dist/audit/local-graphify.d.ts +75 -0
- package/dist/audit/local-graphify.d.ts.map +1 -0
- package/dist/audit/local-graphify.js +283 -0
- package/dist/audit/local-graphify.js.map +1 -0
- package/dist/audit/paths.d.ts +16 -0
- package/dist/audit/paths.d.ts.map +1 -0
- package/dist/audit/paths.js +31 -0
- package/dist/audit/paths.js.map +1 -0
- package/dist/audit/pure.d.ts +18 -0
- package/dist/audit/pure.d.ts.map +1 -0
- package/dist/audit/pure.js +50 -0
- package/dist/audit/pure.js.map +1 -0
- package/dist/audit/report-logic.d.ts +17 -0
- package/dist/audit/report-logic.d.ts.map +1 -0
- package/dist/audit/report-logic.js +206 -0
- package/dist/audit/report-logic.js.map +1 -0
- package/dist/audit/report.d.ts +136 -0
- package/dist/audit/report.d.ts.map +1 -0
- package/dist/audit/report.js +3 -0
- package/dist/audit/report.js.map +1 -0
- package/dist/audit/trail.d.ts +29 -0
- package/dist/audit/trail.d.ts.map +1 -0
- package/dist/audit/trail.js +59 -0
- package/dist/audit/trail.js.map +1 -0
- package/dist/audit/verification.d.ts +98 -0
- package/dist/audit/verification.d.ts.map +1 -0
- package/dist/audit/verification.js +11 -0
- package/dist/audit/verification.js.map +1 -0
- package/dist/audit/verify/component.d.ts +68 -0
- package/dist/audit/verify/component.d.ts.map +1 -0
- package/dist/audit/verify/component.js +500 -0
- package/dist/audit/verify/component.js.map +1 -0
- package/dist/audit/verify/declarations.d.ts +58 -0
- package/dist/audit/verify/declarations.d.ts.map +1 -0
- package/dist/audit/verify/declarations.js +227 -0
- package/dist/audit/verify/declarations.js.map +1 -0
- package/dist/audit/verify/grammar.d.ts +12 -0
- package/dist/audit/verify/grammar.d.ts.map +1 -0
- package/dist/audit/verify/grammar.js +57 -0
- package/dist/audit/verify/grammar.js.map +1 -0
- package/dist/audit/verify/index.d.ts +12 -0
- package/dist/audit/verify/index.d.ts.map +1 -0
- package/dist/audit/verify/index.js +31 -0
- package/dist/audit/verify/index.js.map +1 -0
- package/dist/audit/verify/parser.d.ts +19 -0
- package/dist/audit/verify/parser.d.ts.map +1 -0
- package/dist/audit/verify/parser.js +122 -0
- package/dist/audit/verify/parser.js.map +1 -0
- package/dist/audit/verify/span.d.ts +49 -0
- package/dist/audit/verify/span.d.ts.map +1 -0
- package/dist/audit/verify/span.js +377 -0
- package/dist/audit/verify/span.js.map +1 -0
- package/dist/graphify/anchor.d.ts +45 -0
- package/dist/graphify/anchor.d.ts.map +1 -0
- package/dist/graphify/anchor.js +179 -0
- package/dist/graphify/anchor.js.map +1 -0
- package/dist/graphify/consolidated.d.ts +259 -0
- package/dist/graphify/consolidated.d.ts.map +1 -0
- package/dist/graphify/consolidated.js +12 -0
- package/dist/graphify/consolidated.js.map +1 -0
- package/dist/graphify/construct.d.ts +41 -0
- package/dist/graphify/construct.d.ts.map +1 -0
- package/dist/graphify/construct.js +106 -0
- package/dist/graphify/construct.js.map +1 -0
- package/dist/graphify/ids.d.ts +19 -0
- package/dist/graphify/ids.d.ts.map +1 -0
- package/dist/graphify/ids.js +53 -0
- package/dist/graphify/ids.js.map +1 -0
- package/dist/graphify/index.d.ts +16 -0
- package/dist/graphify/index.d.ts.map +1 -0
- package/dist/graphify/index.js +32 -0
- package/dist/graphify/index.js.map +1 -0
- package/dist/graphify/resolve.d.ts +48 -0
- package/dist/graphify/resolve.d.ts.map +1 -0
- package/dist/graphify/resolve.js +89 -0
- package/dist/graphify/resolve.js.map +1 -0
- package/dist/graphify/signature.d.ts +87 -0
- package/dist/graphify/signature.d.ts.map +1 -0
- package/dist/graphify/signature.js +282 -0
- package/dist/graphify/signature.js.map +1 -0
- package/dist/graphify/types.d.ts +141 -0
- package/dist/graphify/types.d.ts.map +1 -0
- package/dist/graphify/types.js +9 -0
- package/dist/graphify/types.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/node.d.ts +1 -0
- package/dist/node.d.ts.map +1 -1
- package/dist/node.js +1 -0
- package/dist/node.js.map +1 -1
- package/package.json +22 -2
- package/src/audit/boundary.ts +447 -0
- package/src/audit/c4.ts +70 -0
- package/src/audit/engine.ts +1058 -0
- package/src/audit/fixes.ts +192 -0
- package/src/audit/graphify-provider.test.ts +58 -0
- package/src/audit/graphify-provider.ts +77 -0
- package/src/audit/hash.ts +58 -0
- package/src/audit/index.ts +34 -0
- package/src/audit/local-graphify.test.ts +163 -0
- package/src/audit/local-graphify.ts +354 -0
- package/src/audit/paths.ts +25 -0
- package/src/audit/pure.ts +91 -0
- package/src/audit/report-logic.test.ts +145 -0
- package/src/audit/report-logic.ts +245 -0
- package/src/audit/report.ts +203 -0
- package/src/audit/trail.ts +77 -0
- package/src/audit/verification.ts +104 -0
- package/src/audit/verify/component.ts +760 -0
- package/src/audit/verify/declarations.ts +284 -0
- package/src/audit/verify/grammar.ts +57 -0
- package/src/audit/verify/index.ts +41 -0
- package/src/audit/verify/parser.ts +124 -0
- package/src/audit/verify/span.ts +478 -0
- package/src/graphify/anchor.ts +206 -0
- package/src/graphify/consolidated.ts +298 -0
- package/src/graphify/construct.ts +153 -0
- package/src/graphify/ids.ts +48 -0
- package/src/graphify/index.ts +16 -0
- package/src/graphify/resolve.ts +115 -0
- package/src/graphify/signature.ts +354 -0
- package/src/graphify/types.ts +164 -0
- package/src/index.ts +4 -0
- package/src/node.ts +1 -0
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
SubsystemModelAuditFixGroup,
|
|
3
|
+
SubsystemModelAuditReport,
|
|
4
|
+
SubsystemModelAuditCheck,
|
|
5
|
+
SubsystemModelAuditBoundaryCheck,
|
|
6
|
+
SubsystemModelVerification,
|
|
7
|
+
SubsystemModelVerificationLayer,
|
|
8
|
+
SubsystemVerificationLane,
|
|
9
|
+
VerificationLaneStatus,
|
|
10
|
+
} from './report'
|
|
11
|
+
|
|
12
|
+
export type SubsystemModelAuditVerdict =
|
|
13
|
+
| 'fully_verified'
|
|
14
|
+
| 'partially_verified'
|
|
15
|
+
| 'issues'
|
|
16
|
+
|
|
17
|
+
export function auditFixGroups(
|
|
18
|
+
report: SubsystemModelAuditReport,
|
|
19
|
+
): SubsystemModelAuditFixGroup[] {
|
|
20
|
+
const byFix = new Map<string, number>()
|
|
21
|
+
for (const finding of report.findings) {
|
|
22
|
+
if (!finding.fix) continue
|
|
23
|
+
byFix.set(finding.fix.id, (byFix.get(finding.fix.id) ?? 0) + 1)
|
|
24
|
+
}
|
|
25
|
+
return [...byFix.entries()].map(([fixId, count]) => ({
|
|
26
|
+
fixId: fixId as SubsystemModelAuditFixGroup['fixId'],
|
|
27
|
+
count,
|
|
28
|
+
}))
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function auditIssueCount(report: SubsystemModelAuditReport): number {
|
|
32
|
+
const fromFindings = report.findings.filter(
|
|
33
|
+
(finding) => finding.severity === 'error',
|
|
34
|
+
).length
|
|
35
|
+
if (fromFindings > 0) return fromFindings
|
|
36
|
+
return report.checks.filter((check) => check.verdict === 'issue').length
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function auditHasIssues(report: SubsystemModelAuditReport): boolean {
|
|
40
|
+
if (report.needsUpdate) return true
|
|
41
|
+
if (report.checks.some((check) => check.verdict === 'issue')) return true
|
|
42
|
+
return report.findings.some((finding) => finding.severity === 'error')
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** Gaps that are not failures — some checks confirmed, some still need follow-up. */
|
|
46
|
+
export function auditHasPartialGaps(report: SubsystemModelAuditReport): boolean {
|
|
47
|
+
if (report.findings.some((finding) => finding.severity === 'info')) return true
|
|
48
|
+
for (const check of report.checks) {
|
|
49
|
+
if (check.verdict === 'issue') continue
|
|
50
|
+
if (check.constructInferred === 'unknown' && check.constructMatch !== true) return true
|
|
51
|
+
if (check.signature === 'skipped') return true
|
|
52
|
+
}
|
|
53
|
+
return report.boundaryChecks?.some((check) => check.verdict === 'gap') ?? false
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function classifyAuditReport(
|
|
57
|
+
report: SubsystemModelAuditReport,
|
|
58
|
+
): SubsystemModelAuditVerdict {
|
|
59
|
+
if (auditHasIssues(report)) return 'issues'
|
|
60
|
+
if (auditHasPartialGaps(report)) return 'partially_verified'
|
|
61
|
+
return 'fully_verified'
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** Fully verified construct claim: exact graph anchor, source, kind, signature, and span. */
|
|
65
|
+
export function isVerifiedConstructCheck(
|
|
66
|
+
check: SubsystemModelAuditCheck,
|
|
67
|
+
): boolean {
|
|
68
|
+
return (
|
|
69
|
+
check.verdict === 'ok' &&
|
|
70
|
+
check.graphify === 'confirmed' &&
|
|
71
|
+
check.fileExists === true &&
|
|
72
|
+
check.constructMatch === true &&
|
|
73
|
+
check.signature !== 'mismatch' &&
|
|
74
|
+
check.signature !== 'skipped' &&
|
|
75
|
+
check.declarationFreshness !== 'stale' &&
|
|
76
|
+
check.declarationFreshness !== 'missing'
|
|
77
|
+
)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
interface VerificationTally {
|
|
81
|
+
verified: number
|
|
82
|
+
open: number
|
|
83
|
+
blocked: number
|
|
84
|
+
na: number
|
|
85
|
+
blocking: number
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function emptyTally(): VerificationTally {
|
|
89
|
+
return { verified: 0, open: 0, blocked: 0, na: 0, blocking: 0 }
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function finalizeLayer(tally: VerificationTally): SubsystemModelVerificationLayer {
|
|
93
|
+
const adjudicable = tally.verified + tally.open
|
|
94
|
+
const coverage =
|
|
95
|
+
adjudicable > 0
|
|
96
|
+
? tally.verified / adjudicable
|
|
97
|
+
: tally.blocked > 0
|
|
98
|
+
? 0
|
|
99
|
+
: 1
|
|
100
|
+
return {
|
|
101
|
+
verified: tally.verified,
|
|
102
|
+
open: tally.open,
|
|
103
|
+
blocked: tally.blocked,
|
|
104
|
+
na: tally.na,
|
|
105
|
+
coverage,
|
|
106
|
+
blocking: tally.blocking,
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function mergeTallies(...tallies: VerificationTally[]): VerificationTally {
|
|
111
|
+
const merged = emptyTally()
|
|
112
|
+
for (const tally of tallies) {
|
|
113
|
+
merged.verified += tally.verified
|
|
114
|
+
merged.open += tally.open
|
|
115
|
+
merged.blocked += tally.blocked
|
|
116
|
+
merged.na += tally.na
|
|
117
|
+
merged.blocking += tally.blocking
|
|
118
|
+
}
|
|
119
|
+
return merged
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function classifyConstructCheck(
|
|
123
|
+
check: SubsystemModelAuditCheck,
|
|
124
|
+
tally: VerificationTally,
|
|
125
|
+
): void {
|
|
126
|
+
if (check.graphify === 'skipped') {
|
|
127
|
+
tally.na++
|
|
128
|
+
return
|
|
129
|
+
}
|
|
130
|
+
if (check.verdict === 'issue' || check.fileExists === false) {
|
|
131
|
+
tally.open++
|
|
132
|
+
tally.blocking++
|
|
133
|
+
return
|
|
134
|
+
}
|
|
135
|
+
if (check.fileExists === null || check.graphify === 'unavailable') {
|
|
136
|
+
tally.blocked++
|
|
137
|
+
return
|
|
138
|
+
}
|
|
139
|
+
if (isVerifiedConstructCheck(check)) {
|
|
140
|
+
tally.verified++
|
|
141
|
+
return
|
|
142
|
+
}
|
|
143
|
+
tally.open++
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function classifyBoundaryCheck(
|
|
147
|
+
check: SubsystemModelAuditBoundaryCheck,
|
|
148
|
+
tally: VerificationTally,
|
|
149
|
+
): void {
|
|
150
|
+
if (check.kind === 'skipped' || check.verdict === 'skipped') {
|
|
151
|
+
tally.na++
|
|
152
|
+
return
|
|
153
|
+
}
|
|
154
|
+
if (check.verdict === 'issue') {
|
|
155
|
+
tally.open++
|
|
156
|
+
tally.blocking++
|
|
157
|
+
return
|
|
158
|
+
}
|
|
159
|
+
if (check.verdict === 'ok') {
|
|
160
|
+
tally.verified++
|
|
161
|
+
return
|
|
162
|
+
}
|
|
163
|
+
tally.open++
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/** Derive the claim-based verification ledger from an audit report. */
|
|
167
|
+
export function summarizeVerification(
|
|
168
|
+
report: SubsystemModelAuditReport,
|
|
169
|
+
): SubsystemModelVerification {
|
|
170
|
+
const construct = emptyTally()
|
|
171
|
+
const boundary = emptyTally()
|
|
172
|
+
const topology = emptyTally()
|
|
173
|
+
|
|
174
|
+
for (const check of report.checks) classifyConstructCheck(check, construct)
|
|
175
|
+
for (const check of report.boundaryChecks ?? [])
|
|
176
|
+
classifyBoundaryCheck(check, boundary)
|
|
177
|
+
|
|
178
|
+
const total = finalizeLayer(mergeTallies(construct, boundary, topology))
|
|
179
|
+
return {
|
|
180
|
+
...total,
|
|
181
|
+
byLayer: {
|
|
182
|
+
construct: finalizeLayer(construct),
|
|
183
|
+
boundary: finalizeLayer(boundary),
|
|
184
|
+
topology: finalizeLayer(topology),
|
|
185
|
+
},
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
function laneStatus(tally: VerificationTally): VerificationLaneStatus {
|
|
190
|
+
if (tally.blocking > 0) return 'issues'
|
|
191
|
+
if (tally.open > 0) return 'partial'
|
|
192
|
+
if (tally.verified > 0) return 'verified'
|
|
193
|
+
if (tally.blocked > 0) return 'blocked'
|
|
194
|
+
return 'none'
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/** Coarse verification status mapped onto the four model layers. */
|
|
198
|
+
export function summarizeLanes(
|
|
199
|
+
report: SubsystemModelAuditReport,
|
|
200
|
+
opts: { hasTrails: boolean },
|
|
201
|
+
): Record<SubsystemVerificationLane, VerificationLaneStatus> {
|
|
202
|
+
const construct = emptyTally()
|
|
203
|
+
for (const check of report.checks) classifyConstructCheck(check, construct)
|
|
204
|
+
|
|
205
|
+
const staticTopology = emptyTally()
|
|
206
|
+
const dynamicTopology = emptyTally()
|
|
207
|
+
for (const check of report.boundaryChecks ?? []) {
|
|
208
|
+
if (check.kind === 'module_file') classifyBoundaryCheck(check, staticTopology)
|
|
209
|
+
if (
|
|
210
|
+
check.kind === 'process_nest' ||
|
|
211
|
+
check.kind === 'process_claim' ||
|
|
212
|
+
check.kind === 'process_container'
|
|
213
|
+
) {
|
|
214
|
+
classifyBoundaryCheck(check, dynamicTopology)
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
const hasStepIssues = (report.summary.stepsStale ?? 0) > 0
|
|
219
|
+
const hasUnconfirmedSteps = (report.summary.stepsUnconfirmed ?? 0) > 0
|
|
220
|
+
const hasVerifiedSteps = (report.summary.stepsVerified ?? 0) > 0
|
|
221
|
+
const hasAnyStepInfo = hasStepIssues || hasUnconfirmedSteps || hasVerifiedSteps
|
|
222
|
+
const trail: VerificationLaneStatus = !opts.hasTrails
|
|
223
|
+
? 'none'
|
|
224
|
+
: report.summary.trailFailures > 0 || hasStepIssues
|
|
225
|
+
? 'issues'
|
|
226
|
+
: hasUnconfirmedSteps
|
|
227
|
+
? 'partial'
|
|
228
|
+
: hasVerifiedSteps
|
|
229
|
+
? 'verified'
|
|
230
|
+
: hasAnyStepInfo
|
|
231
|
+
? 'partial'
|
|
232
|
+
: 'verified'
|
|
233
|
+
|
|
234
|
+
const constructStatus: VerificationLaneStatus =
|
|
235
|
+
report.summary.components > 0 && laneStatus(construct) === 'none'
|
|
236
|
+
? 'partial'
|
|
237
|
+
: laneStatus(construct)
|
|
238
|
+
|
|
239
|
+
return {
|
|
240
|
+
construct: constructStatus,
|
|
241
|
+
'static-topology': laneStatus(staticTopology),
|
|
242
|
+
'dynamic-topology': laneStatus(dynamicTopology),
|
|
243
|
+
trail,
|
|
244
|
+
}
|
|
245
|
+
}
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import type { SubsystemSourceSpan } from '../types/subsystem-model'
|
|
2
|
+
|
|
3
|
+
export type AuditSpanFreshness =
|
|
4
|
+
| 'full'
|
|
5
|
+
| 'stale'
|
|
6
|
+
| 'missing'
|
|
7
|
+
| 'unanchored'
|
|
8
|
+
| 'unchecked'
|
|
9
|
+
|
|
10
|
+
export type SubsystemModelAuditFindingKind =
|
|
11
|
+
| 'missing_file'
|
|
12
|
+
| 'component_unconnected'
|
|
13
|
+
| 'symbol_ambiguous'
|
|
14
|
+
| 'symbol_unmatched'
|
|
15
|
+
| 'trail'
|
|
16
|
+
| 'construct_span_stale'
|
|
17
|
+
| 'construct_span_unconfirmed'
|
|
18
|
+
| 'construct_span_capturable'
|
|
19
|
+
| 'construct_mismatch'
|
|
20
|
+
| 'construct_unconfirmed'
|
|
21
|
+
| 'store_type_undeclared'
|
|
22
|
+
| 'store_type_stale'
|
|
23
|
+
| 'signature_mismatch'
|
|
24
|
+
| 'signature_unconfirmed'
|
|
25
|
+
| 'step_span_unconfirmed'
|
|
26
|
+
| 'step_span_stale'
|
|
27
|
+
| 'step_site_outside_from'
|
|
28
|
+
| 'step_site_unconfirmed'
|
|
29
|
+
| 'step_site_mismatch'
|
|
30
|
+
| 'step_site_stale'
|
|
31
|
+
| 'step_target_mismatch'
|
|
32
|
+
| 'step_target_stale'
|
|
33
|
+
| 'repo_unresolved'
|
|
34
|
+
| 'graphify_unavailable'
|
|
35
|
+
| 'third_party_path'
|
|
36
|
+
| 'boundary_module_file_mismatch'
|
|
37
|
+
| 'boundary_process_nest_disagree'
|
|
38
|
+
| 'boundary_process_missing'
|
|
39
|
+
| 'boundary_process_unassigned'
|
|
40
|
+
| 'boundary_process_proposed'
|
|
41
|
+
| 'boundary_process_rejected'
|
|
42
|
+
| 'boundary_process_unbacked'
|
|
43
|
+
|
|
44
|
+
export type SubsystemModelAuditSeverity = 'error' | 'info'
|
|
45
|
+
|
|
46
|
+
export type SubsystemModelAuditFix =
|
|
47
|
+
| {
|
|
48
|
+
id: 'adopt_graphify_signature'
|
|
49
|
+
label: string
|
|
50
|
+
parameterTypes: string[]
|
|
51
|
+
returnTypes: string[]
|
|
52
|
+
}
|
|
53
|
+
| {
|
|
54
|
+
id: 'adopt_graphify_file'
|
|
55
|
+
label: string
|
|
56
|
+
file: string
|
|
57
|
+
previousFile?: string
|
|
58
|
+
}
|
|
59
|
+
| {
|
|
60
|
+
id: 'adopt_graphify_declaration_ref'
|
|
61
|
+
label: string
|
|
62
|
+
declarationSpan: SubsystemSourceSpan
|
|
63
|
+
previousStartLine?: number
|
|
64
|
+
}
|
|
65
|
+
| {
|
|
66
|
+
id: 'adopt_tree_sitter_span'
|
|
67
|
+
label: string
|
|
68
|
+
declarationSpan: SubsystemSourceSpan
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export interface SubsystemModelAuditFixGroup {
|
|
72
|
+
fixId: SubsystemModelAuditFix['id']
|
|
73
|
+
count: number
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export interface SubsystemModelAuditFinding {
|
|
77
|
+
kind: SubsystemModelAuditFindingKind
|
|
78
|
+
severity: SubsystemModelAuditSeverity
|
|
79
|
+
componentAlias?: string
|
|
80
|
+
componentName?: string
|
|
81
|
+
moduleKey?: string
|
|
82
|
+
processKey?: string
|
|
83
|
+
purl?: string
|
|
84
|
+
trailId?: string
|
|
85
|
+
step?: number
|
|
86
|
+
message: string
|
|
87
|
+
fix?: SubsystemModelAuditFix
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export interface SubsystemModelAuditCheck {
|
|
91
|
+
componentAlias: string
|
|
92
|
+
componentName?: string
|
|
93
|
+
construct?: string
|
|
94
|
+
symbol?: string
|
|
95
|
+
file?: string
|
|
96
|
+
fileExists: boolean | null
|
|
97
|
+
symbolDeclared: boolean | null
|
|
98
|
+
declarationFreshness?: AuditSpanFreshness | 'n/a'
|
|
99
|
+
constructMatch?: boolean | null
|
|
100
|
+
constructClaimed?: string
|
|
101
|
+
constructInferred?: string
|
|
102
|
+
constructEvidence?: string[]
|
|
103
|
+
signature?: 'match' | 'mismatch' | 'skipped' | 'augmented' | 'n/a'
|
|
104
|
+
storeType?: 'declared' | 'undeclared' | 'stale' | 'n/a'
|
|
105
|
+
anchor?: 'exact' | 'file-only' | 'ambiguous' | 'missing' | 'n/a'
|
|
106
|
+
graphify: 'confirmed' | 'weak' | 'unavailable' | 'skipped'
|
|
107
|
+
verdict: 'ok' | 'issue' | 'skipped'
|
|
108
|
+
note?: string
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export interface SubsystemModelAuditBoundaryCheck {
|
|
112
|
+
componentAlias: string
|
|
113
|
+
componentName?: string
|
|
114
|
+
kind:
|
|
115
|
+
| 'module_file'
|
|
116
|
+
| 'process_nest'
|
|
117
|
+
| 'process_claim'
|
|
118
|
+
| 'process_container'
|
|
119
|
+
| 'skipped'
|
|
120
|
+
module?: string
|
|
121
|
+
file?: string
|
|
122
|
+
process?: string
|
|
123
|
+
verdict: 'ok' | 'issue' | 'gap' | 'skipped'
|
|
124
|
+
note?: string
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export interface SubsystemModelAuditReport {
|
|
128
|
+
graphId: string
|
|
129
|
+
title: string
|
|
130
|
+
checkedAt: string
|
|
131
|
+
needsUpdate: boolean
|
|
132
|
+
summary: {
|
|
133
|
+
components: number
|
|
134
|
+
filesVerified: number
|
|
135
|
+
symbolsVerified: number
|
|
136
|
+
declarationsFresh: number
|
|
137
|
+
constructsMatched: number
|
|
138
|
+
signaturesMatched: number
|
|
139
|
+
anchorsExact: number
|
|
140
|
+
graphifyConfirmed: number
|
|
141
|
+
externalsSkipped: number
|
|
142
|
+
missingFiles: number
|
|
143
|
+
missingSymbols: number
|
|
144
|
+
trailFailures: number
|
|
145
|
+
stepsUnconfirmed: number
|
|
146
|
+
stepsStale: number
|
|
147
|
+
stepsVerified: number
|
|
148
|
+
staleDeclarations: number
|
|
149
|
+
constructMismatches: number
|
|
150
|
+
signatureMismatches: number
|
|
151
|
+
weakAnchors: number
|
|
152
|
+
unresolved: number
|
|
153
|
+
ok: number
|
|
154
|
+
modulesClaimed: number
|
|
155
|
+
moduleFileOk: number
|
|
156
|
+
moduleFileMismatch: number
|
|
157
|
+
processNestsChecked: number
|
|
158
|
+
processNestOk: number
|
|
159
|
+
processNestDisagree: number
|
|
160
|
+
processRequired: number
|
|
161
|
+
processClaimed: number
|
|
162
|
+
processMissing: number
|
|
163
|
+
}
|
|
164
|
+
checks: SubsystemModelAuditCheck[]
|
|
165
|
+
boundaryChecks?: SubsystemModelAuditBoundaryCheck[]
|
|
166
|
+
findings: SubsystemModelAuditFinding[]
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
export type SubsystemVerificationLane =
|
|
170
|
+
| 'construct'
|
|
171
|
+
| 'static-topology'
|
|
172
|
+
| 'dynamic-topology'
|
|
173
|
+
| 'trail'
|
|
174
|
+
|
|
175
|
+
export type VerificationLaneStatus =
|
|
176
|
+
| 'verified'
|
|
177
|
+
| 'partial'
|
|
178
|
+
| 'issues'
|
|
179
|
+
| 'blocked'
|
|
180
|
+
| 'none'
|
|
181
|
+
|
|
182
|
+
export interface SubsystemModelVerificationLayer {
|
|
183
|
+
verified: number
|
|
184
|
+
open: number
|
|
185
|
+
blocked: number
|
|
186
|
+
na: number
|
|
187
|
+
coverage: number
|
|
188
|
+
blocking: number
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
export interface SubsystemModelVerification {
|
|
192
|
+
verified: number
|
|
193
|
+
open: number
|
|
194
|
+
blocked: number
|
|
195
|
+
na: number
|
|
196
|
+
coverage: number
|
|
197
|
+
blocking: number
|
|
198
|
+
byLayer: {
|
|
199
|
+
construct: SubsystemModelVerificationLayer
|
|
200
|
+
boundary: SubsystemModelVerificationLayer
|
|
201
|
+
topology: SubsystemModelVerificationLayer
|
|
202
|
+
}
|
|
203
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Trail rules shared by the audit engine and the UI.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import type {
|
|
6
|
+
SubsystemComponent,
|
|
7
|
+
SubsystemTrail,
|
|
8
|
+
SubsystemTrailStep,
|
|
9
|
+
} from '../types/subsystem-model'
|
|
10
|
+
import type { SubsystemModelAuditFinding } from './report'
|
|
11
|
+
|
|
12
|
+
type StepSite = Pick<
|
|
13
|
+
SubsystemTrailStep,
|
|
14
|
+
'mechanism' | 'file' | 'span' | 'site'
|
|
15
|
+
>
|
|
16
|
+
type FromComponent = Pick<SubsystemComponent, 'file' | 'declarationSpan'>
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* True when a `calls` step's site is not housed by its `from` component.
|
|
20
|
+
*
|
|
21
|
+
* - Different file → outside (the component cannot contain the site).
|
|
22
|
+
* - Same file but the stored site span falls outside the component's
|
|
23
|
+
* declaration span → outside (a sibling construct, not a nested one).
|
|
24
|
+
* - Unknown component span / site span → not enough evidence to call it
|
|
25
|
+
* outside; stay permissive so missing spans stay a separate finding.
|
|
26
|
+
*
|
|
27
|
+
* Always false for non-`calls` mechanisms: `uses`, `feeds`, `writes`, … are
|
|
28
|
+
* allowed to point at evidence in another construct.
|
|
29
|
+
*/
|
|
30
|
+
export function callsSiteOutsideFrom(
|
|
31
|
+
step: StepSite,
|
|
32
|
+
from: FromComponent | undefined,
|
|
33
|
+
): boolean {
|
|
34
|
+
if (step.mechanism !== 'calls' || !from) return false
|
|
35
|
+
|
|
36
|
+
const fromFile = from.file?.trim()
|
|
37
|
+
if (fromFile && fromFile !== step.file) return true
|
|
38
|
+
|
|
39
|
+
const fromSpan = from.declarationSpan
|
|
40
|
+
const siteSpan = step.site?.span ?? step.span
|
|
41
|
+
if (fromSpan && siteSpan) {
|
|
42
|
+
return !(
|
|
43
|
+
fromSpan.startLine <= siteSpan.startLine &&
|
|
44
|
+
siteSpan.endLine <= fromSpan.endLine
|
|
45
|
+
)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return false
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Components with no trail edges.
|
|
53
|
+
*
|
|
54
|
+
* A standalone node may be intentional, but is worth a second look in a
|
|
55
|
+
* subsystem graph whose purpose is to explain relationships.
|
|
56
|
+
*/
|
|
57
|
+
export function unconnectedComponentFindings(
|
|
58
|
+
components: readonly SubsystemComponent[],
|
|
59
|
+
trails: readonly SubsystemTrail[],
|
|
60
|
+
): SubsystemModelAuditFinding[] {
|
|
61
|
+
const connected = new Set<string>()
|
|
62
|
+
for (const trail of trails) {
|
|
63
|
+
for (const step of trail.steps ?? []) {
|
|
64
|
+
connected.add(step.from)
|
|
65
|
+
connected.add(step.to)
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return components
|
|
69
|
+
.filter((component) => !connected.has(component.alias))
|
|
70
|
+
.map((component) => ({
|
|
71
|
+
kind: 'component_unconnected' as const,
|
|
72
|
+
severity: 'info' as const,
|
|
73
|
+
componentAlias: component.alias,
|
|
74
|
+
componentName: component.name,
|
|
75
|
+
message: `Component ${JSON.stringify(component.name)} has no trail edges. Add a trail if it participates in this subsystem, or remove it if it is out of scope.`,
|
|
76
|
+
}))
|
|
77
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Structural shape of one component-verification result as the audit engine
|
|
3
|
+
* consumes it.
|
|
4
|
+
*
|
|
5
|
+
* The concrete verifier lives in the host (filesystem, Graphify, tree-sitter).
|
|
6
|
+
* The engine only reads these fields, so the host result is assignable without
|
|
7
|
+
* the engine depending on host code.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type { SubsystemSourceSpan } from '../types/subsystem-model'
|
|
11
|
+
import type { AuditSpanFreshness } from './report'
|
|
12
|
+
|
|
13
|
+
export interface AuditFileCheck {
|
|
14
|
+
exists: boolean
|
|
15
|
+
symbolDeclared?: boolean | null
|
|
16
|
+
repoRoot?: string
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface AuditFileSuggestion {
|
|
20
|
+
file: string
|
|
21
|
+
nodeId?: string
|
|
22
|
+
label?: string
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface AuditAnchorCandidate {
|
|
26
|
+
nodeId: string
|
|
27
|
+
label: string
|
|
28
|
+
source_file?: string
|
|
29
|
+
source_location?: string
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface AuditAnchorCheck {
|
|
33
|
+
resolution: 'exact' | 'file-only' | 'ambiguous' | 'missing'
|
|
34
|
+
nodeId?: string
|
|
35
|
+
label?: string
|
|
36
|
+
source_file?: string
|
|
37
|
+
source_location?: string
|
|
38
|
+
candidates?: AuditAnchorCandidate[]
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface AuditConstructCheck {
|
|
42
|
+
claimed: string
|
|
43
|
+
inferred: 'class' | 'function' | 'method' | 'type' | 'module' | 'unknown'
|
|
44
|
+
/** true = match, false = known mismatch, null = unconfirmed. */
|
|
45
|
+
match: boolean | null
|
|
46
|
+
evidence?: string[]
|
|
47
|
+
/** Agent-confirmed construct that cleared a gap. */
|
|
48
|
+
augmented?: string
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export interface AuditSignatureTypes {
|
|
52
|
+
parameterTypes: string[]
|
|
53
|
+
returnTypes: string[]
|
|
54
|
+
inlineParameters?: number
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export interface AuditSignatureCheck {
|
|
58
|
+
match: boolean
|
|
59
|
+
skipped: boolean
|
|
60
|
+
reason?: string
|
|
61
|
+
skipCode?: string
|
|
62
|
+
claimed: AuditSignatureTypes
|
|
63
|
+
inferred: AuditSignatureTypes
|
|
64
|
+
/** Agent-extracted, human-confirmed signature. */
|
|
65
|
+
augmented?: {
|
|
66
|
+
parameters: Array<{ type: string; optional?: boolean }>
|
|
67
|
+
returnType?: string
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export interface AuditDeclarationCheck {
|
|
72
|
+
freshness: AuditSpanFreshness
|
|
73
|
+
span?: SubsystemSourceSpan
|
|
74
|
+
liveContentHash?: string
|
|
75
|
+
/** Content-preserving re-pin candidate. */
|
|
76
|
+
repin?: SubsystemSourceSpan
|
|
77
|
+
derivation?: {
|
|
78
|
+
class: 'deterministic' | 'trivial' | 'ambiguous' | 'unknown' | 'skipped'
|
|
79
|
+
endLine?: number
|
|
80
|
+
span?: SubsystemSourceSpan
|
|
81
|
+
failedGates?: string[]
|
|
82
|
+
evidence?: string[]
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export interface AuditComponentVerification {
|
|
87
|
+
ok: boolean
|
|
88
|
+
error?: string
|
|
89
|
+
code?: string
|
|
90
|
+
componentAlias?: string
|
|
91
|
+
file?: AuditFileCheck
|
|
92
|
+
fileSuggest?: AuditFileSuggestion
|
|
93
|
+
fileCandidates?: AuditFileSuggestion[]
|
|
94
|
+
cache?: {
|
|
95
|
+
status: 'ready' | 'missing' | 'unavailable'
|
|
96
|
+
purl: string
|
|
97
|
+
repoRoot?: string
|
|
98
|
+
}
|
|
99
|
+
anchor?: AuditAnchorCheck
|
|
100
|
+
construct?: AuditConstructCheck
|
|
101
|
+
signature?: AuditSignatureCheck
|
|
102
|
+
declaration?: AuditDeclarationCheck
|
|
103
|
+
storeTypeUndeclared?: boolean
|
|
104
|
+
}
|