@principal-ai/subsystems-core 0.52.0 → 0.53.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (214) hide show
  1. package/README.md +30 -2
  2. package/dist/audit/boundary.d.ts +104 -0
  3. package/dist/audit/boundary.d.ts.map +1 -0
  4. package/dist/audit/boundary.js +363 -0
  5. package/dist/audit/boundary.js.map +1 -0
  6. package/dist/audit/c4.d.ts +41 -0
  7. package/dist/audit/c4.d.ts.map +1 -0
  8. package/dist/audit/c4.js +41 -0
  9. package/dist/audit/c4.js.map +1 -0
  10. package/dist/audit/engine.d.ts +135 -0
  11. package/dist/audit/engine.d.ts.map +1 -0
  12. package/dist/audit/engine.js +865 -0
  13. package/dist/audit/engine.js.map +1 -0
  14. package/dist/audit/fixes.d.ts +80 -0
  15. package/dist/audit/fixes.d.ts.map +1 -0
  16. package/dist/audit/fixes.js +162 -0
  17. package/dist/audit/fixes.js.map +1 -0
  18. package/dist/audit/graphify-provider.d.ts +51 -0
  19. package/dist/audit/graphify-provider.d.ts.map +1 -0
  20. package/dist/audit/graphify-provider.js +36 -0
  21. package/dist/audit/graphify-provider.js.map +1 -0
  22. package/dist/audit/hash.d.ts +25 -0
  23. package/dist/audit/hash.d.ts.map +1 -0
  24. package/dist/audit/hash.js +53 -0
  25. package/dist/audit/hash.js.map +1 -0
  26. package/dist/audit/index.d.ts +12 -0
  27. package/dist/audit/index.d.ts.map +1 -0
  28. package/dist/audit/index.js +40 -0
  29. package/dist/audit/index.js.map +1 -0
  30. package/dist/audit/local-graphify.d.ts +75 -0
  31. package/dist/audit/local-graphify.d.ts.map +1 -0
  32. package/dist/audit/local-graphify.js +283 -0
  33. package/dist/audit/local-graphify.js.map +1 -0
  34. package/dist/audit/paths.d.ts +16 -0
  35. package/dist/audit/paths.d.ts.map +1 -0
  36. package/dist/audit/paths.js +31 -0
  37. package/dist/audit/paths.js.map +1 -0
  38. package/dist/audit/pure.d.ts +18 -0
  39. package/dist/audit/pure.d.ts.map +1 -0
  40. package/dist/audit/pure.js +50 -0
  41. package/dist/audit/pure.js.map +1 -0
  42. package/dist/audit/report-logic.d.ts +17 -0
  43. package/dist/audit/report-logic.d.ts.map +1 -0
  44. package/dist/audit/report-logic.js +206 -0
  45. package/dist/audit/report-logic.js.map +1 -0
  46. package/dist/audit/report.d.ts +140 -0
  47. package/dist/audit/report.d.ts.map +1 -0
  48. package/dist/audit/report.js +3 -0
  49. package/dist/audit/report.js.map +1 -0
  50. package/dist/audit/trail.d.ts +29 -0
  51. package/dist/audit/trail.d.ts.map +1 -0
  52. package/dist/audit/trail.js +59 -0
  53. package/dist/audit/trail.js.map +1 -0
  54. package/dist/audit/verification.d.ts +98 -0
  55. package/dist/audit/verification.d.ts.map +1 -0
  56. package/dist/audit/verification.js +11 -0
  57. package/dist/audit/verification.js.map +1 -0
  58. package/dist/audit/verify/component.d.ts +68 -0
  59. package/dist/audit/verify/component.d.ts.map +1 -0
  60. package/dist/audit/verify/component.js +500 -0
  61. package/dist/audit/verify/component.js.map +1 -0
  62. package/dist/audit/verify/declarations.d.ts +58 -0
  63. package/dist/audit/verify/declarations.d.ts.map +1 -0
  64. package/dist/audit/verify/declarations.js +227 -0
  65. package/dist/audit/verify/declarations.js.map +1 -0
  66. package/dist/audit/verify/grammar.d.ts +12 -0
  67. package/dist/audit/verify/grammar.d.ts.map +1 -0
  68. package/dist/audit/verify/grammar.js +57 -0
  69. package/dist/audit/verify/grammar.js.map +1 -0
  70. package/dist/audit/verify/index.d.ts +12 -0
  71. package/dist/audit/verify/index.d.ts.map +1 -0
  72. package/dist/audit/verify/index.js +31 -0
  73. package/dist/audit/verify/index.js.map +1 -0
  74. package/dist/audit/verify/parser.d.ts +19 -0
  75. package/dist/audit/verify/parser.d.ts.map +1 -0
  76. package/dist/audit/verify/parser.js +122 -0
  77. package/dist/audit/verify/parser.js.map +1 -0
  78. package/dist/audit/verify/span.d.ts +49 -0
  79. package/dist/audit/verify/span.d.ts.map +1 -0
  80. package/dist/audit/verify/span.js +377 -0
  81. package/dist/audit/verify/span.js.map +1 -0
  82. package/dist/graphify/anchor.d.ts +45 -0
  83. package/dist/graphify/anchor.d.ts.map +1 -0
  84. package/dist/graphify/anchor.js +179 -0
  85. package/dist/graphify/anchor.js.map +1 -0
  86. package/dist/graphify/consolidated.d.ts +259 -0
  87. package/dist/graphify/consolidated.d.ts.map +1 -0
  88. package/dist/graphify/consolidated.js +12 -0
  89. package/dist/graphify/consolidated.js.map +1 -0
  90. package/dist/graphify/construct.d.ts +41 -0
  91. package/dist/graphify/construct.d.ts.map +1 -0
  92. package/dist/graphify/construct.js +106 -0
  93. package/dist/graphify/construct.js.map +1 -0
  94. package/dist/graphify/ids.d.ts +19 -0
  95. package/dist/graphify/ids.d.ts.map +1 -0
  96. package/dist/graphify/ids.js +53 -0
  97. package/dist/graphify/ids.js.map +1 -0
  98. package/dist/graphify/index.d.ts +16 -0
  99. package/dist/graphify/index.d.ts.map +1 -0
  100. package/dist/graphify/index.js +32 -0
  101. package/dist/graphify/index.js.map +1 -0
  102. package/dist/graphify/resolve.d.ts +48 -0
  103. package/dist/graphify/resolve.d.ts.map +1 -0
  104. package/dist/graphify/resolve.js +89 -0
  105. package/dist/graphify/resolve.js.map +1 -0
  106. package/dist/graphify/signature.d.ts +87 -0
  107. package/dist/graphify/signature.d.ts.map +1 -0
  108. package/dist/graphify/signature.js +282 -0
  109. package/dist/graphify/signature.js.map +1 -0
  110. package/dist/graphify/types.d.ts +141 -0
  111. package/dist/graphify/types.d.ts.map +1 -0
  112. package/dist/graphify/types.js +9 -0
  113. package/dist/graphify/types.js.map +1 -0
  114. package/dist/index.d.ts +4 -0
  115. package/dist/index.d.ts.map +1 -1
  116. package/dist/index.js +9 -1
  117. package/dist/index.js.map +1 -1
  118. package/dist/infra/c4.d.ts +59 -0
  119. package/dist/infra/c4.d.ts.map +1 -0
  120. package/dist/infra/c4.js +106 -0
  121. package/dist/infra/c4.js.map +1 -0
  122. package/dist/infra/index.d.ts +13 -0
  123. package/dist/infra/index.d.ts.map +1 -0
  124. package/dist/infra/index.js +22 -0
  125. package/dist/infra/index.js.map +1 -0
  126. package/dist/infra/jsonc.d.ts +10 -0
  127. package/dist/infra/jsonc.d.ts.map +1 -0
  128. package/dist/infra/jsonc.js +77 -0
  129. package/dist/infra/jsonc.js.map +1 -0
  130. package/dist/infra/terraform.d.ts +41 -0
  131. package/dist/infra/terraform.d.ts.map +1 -0
  132. package/dist/infra/terraform.js +208 -0
  133. package/dist/infra/terraform.js.map +1 -0
  134. package/dist/infra/types.d.ts +107 -0
  135. package/dist/infra/types.d.ts.map +1 -0
  136. package/dist/infra/types.js +47 -0
  137. package/dist/infra/types.js.map +1 -0
  138. package/dist/infra/wrangler.d.ts +32 -0
  139. package/dist/infra/wrangler.d.ts.map +1 -0
  140. package/dist/infra/wrangler.js +177 -0
  141. package/dist/infra/wrangler.js.map +1 -0
  142. package/dist/node.d.ts +3 -0
  143. package/dist/node.d.ts.map +1 -1
  144. package/dist/node.js +4 -1
  145. package/dist/node.js.map +1 -1
  146. package/dist/storage/topic-reference-links.d.ts +3 -3
  147. package/dist/storage/topic-reference-links.d.ts.map +1 -1
  148. package/dist/storage/topic-reference-links.js +23 -8
  149. package/dist/storage/topic-reference-links.js.map +1 -1
  150. package/dist/storage/topic-share.d.ts +69 -0
  151. package/dist/storage/topic-share.d.ts.map +1 -0
  152. package/dist/storage/topic-share.js +67 -0
  153. package/dist/storage/topic-share.js.map +1 -0
  154. package/dist/storage/topic-types.d.ts +5 -1
  155. package/dist/storage/topic-types.d.ts.map +1 -1
  156. package/dist/types/subsystem-model.d.ts +59 -0
  157. package/dist/types/subsystem-model.d.ts.map +1 -1
  158. package/dist/types/subsystem-model.js +50 -1
  159. package/dist/types/subsystem-model.js.map +1 -1
  160. package/dist/validation.d.ts.map +1 -1
  161. package/dist/validation.js +25 -2
  162. package/dist/validation.js.map +1 -1
  163. package/package.json +22 -2
  164. package/schemas/subsystem-model.schema.json +35 -19
  165. package/src/audit/boundary.ts +447 -0
  166. package/src/audit/c4.ts +70 -0
  167. package/src/audit/engine.ts +1099 -0
  168. package/src/audit/fixes.ts +192 -0
  169. package/src/audit/graphify-provider.test.ts +58 -0
  170. package/src/audit/graphify-provider.ts +77 -0
  171. package/src/audit/hash.ts +58 -0
  172. package/src/audit/index.ts +34 -0
  173. package/src/audit/local-graphify.test.ts +163 -0
  174. package/src/audit/local-graphify.ts +354 -0
  175. package/src/audit/paths.ts +25 -0
  176. package/src/audit/pure.ts +91 -0
  177. package/src/audit/report-logic.test.ts +145 -0
  178. package/src/audit/report-logic.ts +245 -0
  179. package/src/audit/report.ts +207 -0
  180. package/src/audit/trail.ts +77 -0
  181. package/src/audit/verification.ts +104 -0
  182. package/src/audit/verify/component.ts +760 -0
  183. package/src/audit/verify/declarations.ts +284 -0
  184. package/src/audit/verify/grammar.ts +57 -0
  185. package/src/audit/verify/index.ts +41 -0
  186. package/src/audit/verify/parser.ts +124 -0
  187. package/src/audit/verify/span.ts +478 -0
  188. package/src/graphify/anchor.ts +206 -0
  189. package/src/graphify/consolidated.ts +298 -0
  190. package/src/graphify/construct.ts +153 -0
  191. package/src/graphify/ids.ts +48 -0
  192. package/src/graphify/index.ts +16 -0
  193. package/src/graphify/resolve.ts +115 -0
  194. package/src/graphify/signature.ts +354 -0
  195. package/src/graphify/types.ts +164 -0
  196. package/src/index.ts +10 -0
  197. package/src/infra/c4.ts +146 -0
  198. package/src/infra/index.ts +21 -0
  199. package/src/infra/infra.test.ts +360 -0
  200. package/src/infra/jsonc.ts +70 -0
  201. package/src/infra/terraform.ts +251 -0
  202. package/src/infra/types.ts +136 -0
  203. package/src/infra/wrangler.ts +203 -0
  204. package/src/node.ts +3 -0
  205. package/src/storage/topic-reference-links.test.ts +7 -1
  206. package/src/storage/topic-reference-links.ts +24 -8
  207. package/src/storage/topic-share.test.ts +91 -0
  208. package/src/storage/topic-share.ts +118 -0
  209. package/src/storage/topic-types.ts +3 -1
  210. package/src/storage/topicStore.test.ts +1 -0
  211. package/src/types/subsystem-model.test.ts +52 -2
  212. package/src/types/subsystem-model.ts +104 -0
  213. package/src/validation.test.ts +71 -7
  214. package/src/validation.ts +27 -2
@@ -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,207 @@
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
+ /** Proposed components skipped — planned, with no source to check yet. */
143
+ proposedSkipped: number
144
+ /** Proposed trail steps skipped — the seam is not in the code yet. */
145
+ stepsProposed: number
146
+ missingFiles: number
147
+ missingSymbols: number
148
+ trailFailures: number
149
+ stepsUnconfirmed: number
150
+ stepsStale: number
151
+ stepsVerified: number
152
+ staleDeclarations: number
153
+ constructMismatches: number
154
+ signatureMismatches: number
155
+ weakAnchors: number
156
+ unresolved: number
157
+ ok: number
158
+ modulesClaimed: number
159
+ moduleFileOk: number
160
+ moduleFileMismatch: number
161
+ processNestsChecked: number
162
+ processNestOk: number
163
+ processNestDisagree: number
164
+ processRequired: number
165
+ processClaimed: number
166
+ processMissing: number
167
+ }
168
+ checks: SubsystemModelAuditCheck[]
169
+ boundaryChecks?: SubsystemModelAuditBoundaryCheck[]
170
+ findings: SubsystemModelAuditFinding[]
171
+ }
172
+
173
+ export type SubsystemVerificationLane =
174
+ | 'construct'
175
+ | 'static-topology'
176
+ | 'dynamic-topology'
177
+ | 'trail'
178
+
179
+ export type VerificationLaneStatus =
180
+ | 'verified'
181
+ | 'partial'
182
+ | 'issues'
183
+ | 'blocked'
184
+ | 'none'
185
+
186
+ export interface SubsystemModelVerificationLayer {
187
+ verified: number
188
+ open: number
189
+ blocked: number
190
+ na: number
191
+ coverage: number
192
+ blocking: number
193
+ }
194
+
195
+ export interface SubsystemModelVerification {
196
+ verified: number
197
+ open: number
198
+ blocked: number
199
+ na: number
200
+ coverage: number
201
+ blocking: number
202
+ byLayer: {
203
+ construct: SubsystemModelVerificationLayer
204
+ boundary: SubsystemModelVerificationLayer
205
+ topology: SubsystemModelVerificationLayer
206
+ }
207
+ }
@@ -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
+ }