causoryn 0.0.0-stage → 0.2.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 (197) hide show
  1. package/.claude-plugin/plugin.json +36 -0
  2. package/.codex-plugin/mcp.json +19 -0
  3. package/.codex-plugin/plugin.json +38 -0
  4. package/.zcode-plugin/plugin.json +42 -0
  5. package/LICENSE +21 -0
  6. package/README.md +171 -2
  7. package/THIRD-PARTY-NOTICES.md +443 -0
  8. package/dist/bundle-manifest.json +39 -0
  9. package/dist/cli.d.ts +3 -0
  10. package/dist/cli.js +253 -0
  11. package/dist/doctor.d.ts +13 -0
  12. package/dist/doctor.js +507 -0
  13. package/dist/index.d.ts +10 -0
  14. package/dist/index.js +10 -0
  15. package/dist/mcp-server.mjs +288477 -0
  16. package/dist/mcp-server.mjs.LEGAL.txt +17 -0
  17. package/dist/node_modules/better-sqlite3/LICENSE +21 -0
  18. package/dist/node_modules/better-sqlite3/lib/binding.js +62 -0
  19. package/dist/node_modules/better-sqlite3/lib/darwin-arm64.js +3 -0
  20. package/dist/node_modules/better-sqlite3/lib/darwin-x64.js +3 -0
  21. package/dist/node_modules/better-sqlite3/lib/database.js +109 -0
  22. package/dist/node_modules/better-sqlite3/lib/index.js +3 -0
  23. package/dist/node_modules/better-sqlite3/lib/linux-arm64.js +3 -0
  24. package/dist/node_modules/better-sqlite3/lib/linux-x64.js +3 -0
  25. package/dist/node_modules/better-sqlite3/lib/linuxmusl-arm64.js +4 -0
  26. package/dist/node_modules/better-sqlite3/lib/linuxmusl-x64.js +4 -0
  27. package/dist/node_modules/better-sqlite3/lib/methods/aggregate.js +43 -0
  28. package/dist/node_modules/better-sqlite3/lib/methods/backup.js +67 -0
  29. package/dist/node_modules/better-sqlite3/lib/methods/explain.js +9 -0
  30. package/dist/node_modules/better-sqlite3/lib/methods/function.js +31 -0
  31. package/dist/node_modules/better-sqlite3/lib/methods/inspect.js +7 -0
  32. package/dist/node_modules/better-sqlite3/lib/methods/pragma.js +12 -0
  33. package/dist/node_modules/better-sqlite3/lib/methods/serialize.js +16 -0
  34. package/dist/node_modules/better-sqlite3/lib/methods/table.js +195 -0
  35. package/dist/node_modules/better-sqlite3/lib/methods/transaction.js +78 -0
  36. package/dist/node_modules/better-sqlite3/lib/methods/wrappers.js +54 -0
  37. package/dist/node_modules/better-sqlite3/lib/sqlite-error.js +25 -0
  38. package/dist/node_modules/better-sqlite3/lib/util.js +12 -0
  39. package/dist/node_modules/better-sqlite3/lib/win32-arm64.js +3 -0
  40. package/dist/node_modules/better-sqlite3/lib/win32-x64.js +3 -0
  41. package/dist/node_modules/better-sqlite3/package.json +67 -0
  42. package/dist/node_modules/better-sqlite3/prebuilds/darwin-arm64.node +0 -0
  43. package/dist/node_modules/better-sqlite3/prebuilds/darwin-x64.node +0 -0
  44. package/dist/node_modules/better-sqlite3/prebuilds/linux-arm64.node +0 -0
  45. package/dist/node_modules/better-sqlite3/prebuilds/linux-x64.node +0 -0
  46. package/dist/node_modules/better-sqlite3/prebuilds/linuxmusl-arm64.node +0 -0
  47. package/dist/node_modules/better-sqlite3/prebuilds/linuxmusl-x64.node +0 -0
  48. package/dist/node_modules/better-sqlite3/prebuilds/win32-arm64.node +0 -0
  49. package/dist/node_modules/better-sqlite3/prebuilds/win32-x64.node +0 -0
  50. package/dist/runtime-stage.d.ts +8 -0
  51. package/dist/runtime-stage.js +159 -0
  52. package/dist/setup.d.ts +15 -0
  53. package/dist/setup.js +735 -0
  54. package/dist/toml-patch.d.ts +10 -0
  55. package/dist/toml-patch.js +587 -0
  56. package/dist/types.d.ts +144 -0
  57. package/dist/types.js +35 -0
  58. package/dist/typescript-lib/lib.d.ts +22 -0
  59. package/dist/typescript-lib/lib.decorators.d.ts +384 -0
  60. package/dist/typescript-lib/lib.decorators.legacy.d.ts +22 -0
  61. package/dist/typescript-lib/lib.dom.asynciterable.d.ts +41 -0
  62. package/dist/typescript-lib/lib.dom.d.ts +39429 -0
  63. package/dist/typescript-lib/lib.dom.iterable.d.ts +571 -0
  64. package/dist/typescript-lib/lib.es2015.collection.d.ts +147 -0
  65. package/dist/typescript-lib/lib.es2015.core.d.ts +597 -0
  66. package/dist/typescript-lib/lib.es2015.d.ts +28 -0
  67. package/dist/typescript-lib/lib.es2015.generator.d.ts +77 -0
  68. package/dist/typescript-lib/lib.es2015.iterable.d.ts +605 -0
  69. package/dist/typescript-lib/lib.es2015.promise.d.ts +81 -0
  70. package/dist/typescript-lib/lib.es2015.proxy.d.ts +128 -0
  71. package/dist/typescript-lib/lib.es2015.reflect.d.ts +144 -0
  72. package/dist/typescript-lib/lib.es2015.symbol.d.ts +46 -0
  73. package/dist/typescript-lib/lib.es2015.symbol.wellknown.d.ts +326 -0
  74. package/dist/typescript-lib/lib.es2016.array.include.d.ts +116 -0
  75. package/dist/typescript-lib/lib.es2016.d.ts +21 -0
  76. package/dist/typescript-lib/lib.es2016.full.d.ts +23 -0
  77. package/dist/typescript-lib/lib.es2016.intl.d.ts +31 -0
  78. package/dist/typescript-lib/lib.es2017.arraybuffer.d.ts +21 -0
  79. package/dist/typescript-lib/lib.es2017.d.ts +26 -0
  80. package/dist/typescript-lib/lib.es2017.date.d.ts +31 -0
  81. package/dist/typescript-lib/lib.es2017.full.d.ts +23 -0
  82. package/dist/typescript-lib/lib.es2017.intl.d.ts +44 -0
  83. package/dist/typescript-lib/lib.es2017.object.d.ts +49 -0
  84. package/dist/typescript-lib/lib.es2017.sharedmemory.d.ts +135 -0
  85. package/dist/typescript-lib/lib.es2017.string.d.ts +45 -0
  86. package/dist/typescript-lib/lib.es2017.typedarrays.d.ts +53 -0
  87. package/dist/typescript-lib/lib.es2018.asyncgenerator.d.ts +77 -0
  88. package/dist/typescript-lib/lib.es2018.asynciterable.d.ts +53 -0
  89. package/dist/typescript-lib/lib.es2018.d.ts +24 -0
  90. package/dist/typescript-lib/lib.es2018.full.d.ts +24 -0
  91. package/dist/typescript-lib/lib.es2018.intl.d.ts +83 -0
  92. package/dist/typescript-lib/lib.es2018.promise.d.ts +30 -0
  93. package/dist/typescript-lib/lib.es2018.regexp.d.ts +37 -0
  94. package/dist/typescript-lib/lib.es2019.array.d.ts +79 -0
  95. package/dist/typescript-lib/lib.es2019.d.ts +24 -0
  96. package/dist/typescript-lib/lib.es2019.full.d.ts +24 -0
  97. package/dist/typescript-lib/lib.es2019.intl.d.ts +23 -0
  98. package/dist/typescript-lib/lib.es2019.object.d.ts +33 -0
  99. package/dist/typescript-lib/lib.es2019.string.d.ts +37 -0
  100. package/dist/typescript-lib/lib.es2019.symbol.d.ts +24 -0
  101. package/dist/typescript-lib/lib.es2020.bigint.d.ts +765 -0
  102. package/dist/typescript-lib/lib.es2020.d.ts +27 -0
  103. package/dist/typescript-lib/lib.es2020.date.d.ts +42 -0
  104. package/dist/typescript-lib/lib.es2020.full.d.ts +24 -0
  105. package/dist/typescript-lib/lib.es2020.intl.d.ts +474 -0
  106. package/dist/typescript-lib/lib.es2020.number.d.ts +28 -0
  107. package/dist/typescript-lib/lib.es2020.promise.d.ts +47 -0
  108. package/dist/typescript-lib/lib.es2020.sharedmemory.d.ts +99 -0
  109. package/dist/typescript-lib/lib.es2020.string.d.ts +44 -0
  110. package/dist/typescript-lib/lib.es2020.symbol.wellknown.d.ts +41 -0
  111. package/dist/typescript-lib/lib.es2021.d.ts +23 -0
  112. package/dist/typescript-lib/lib.es2021.full.d.ts +24 -0
  113. package/dist/typescript-lib/lib.es2021.intl.d.ts +166 -0
  114. package/dist/typescript-lib/lib.es2021.promise.d.ts +48 -0
  115. package/dist/typescript-lib/lib.es2021.string.d.ts +33 -0
  116. package/dist/typescript-lib/lib.es2021.weakref.d.ts +78 -0
  117. package/dist/typescript-lib/lib.es2022.array.d.ts +121 -0
  118. package/dist/typescript-lib/lib.es2022.d.ts +25 -0
  119. package/dist/typescript-lib/lib.es2022.error.d.ts +75 -0
  120. package/dist/typescript-lib/lib.es2022.full.d.ts +24 -0
  121. package/dist/typescript-lib/lib.es2022.intl.d.ts +145 -0
  122. package/dist/typescript-lib/lib.es2022.object.d.ts +26 -0
  123. package/dist/typescript-lib/lib.es2022.regexp.d.ts +39 -0
  124. package/dist/typescript-lib/lib.es2022.string.d.ts +25 -0
  125. package/dist/typescript-lib/lib.es2023.array.d.ts +924 -0
  126. package/dist/typescript-lib/lib.es2023.collection.d.ts +21 -0
  127. package/dist/typescript-lib/lib.es2023.d.ts +22 -0
  128. package/dist/typescript-lib/lib.es2023.full.d.ts +24 -0
  129. package/dist/typescript-lib/lib.es2023.intl.d.ts +56 -0
  130. package/dist/typescript-lib/lib.es2024.arraybuffer.d.ts +65 -0
  131. package/dist/typescript-lib/lib.es2024.collection.d.ts +29 -0
  132. package/dist/typescript-lib/lib.es2024.d.ts +26 -0
  133. package/dist/typescript-lib/lib.es2024.full.d.ts +24 -0
  134. package/dist/typescript-lib/lib.es2024.object.d.ts +29 -0
  135. package/dist/typescript-lib/lib.es2024.promise.d.ts +35 -0
  136. package/dist/typescript-lib/lib.es2024.regexp.d.ts +25 -0
  137. package/dist/typescript-lib/lib.es2024.sharedmemory.d.ts +68 -0
  138. package/dist/typescript-lib/lib.es2024.string.d.ts +29 -0
  139. package/dist/typescript-lib/lib.es5.d.ts +4601 -0
  140. package/dist/typescript-lib/lib.es6.d.ts +23 -0
  141. package/dist/typescript-lib/lib.esnext.array.d.ts +35 -0
  142. package/dist/typescript-lib/lib.esnext.collection.d.ts +96 -0
  143. package/dist/typescript-lib/lib.esnext.d.ts +29 -0
  144. package/dist/typescript-lib/lib.esnext.decorators.d.ts +28 -0
  145. package/dist/typescript-lib/lib.esnext.disposable.d.ts +193 -0
  146. package/dist/typescript-lib/lib.esnext.error.d.ts +24 -0
  147. package/dist/typescript-lib/lib.esnext.float16.d.ts +445 -0
  148. package/dist/typescript-lib/lib.esnext.full.d.ts +24 -0
  149. package/dist/typescript-lib/lib.esnext.intl.d.ts +21 -0
  150. package/dist/typescript-lib/lib.esnext.iterator.d.ts +148 -0
  151. package/dist/typescript-lib/lib.esnext.promise.d.ts +34 -0
  152. package/dist/typescript-lib/lib.esnext.sharedmemory.d.ts +25 -0
  153. package/dist/typescript-lib/lib.scripthost.d.ts +322 -0
  154. package/dist/typescript-lib/lib.webworker.asynciterable.d.ts +41 -0
  155. package/dist/typescript-lib/lib.webworker.d.ts +13150 -0
  156. package/dist/typescript-lib/lib.webworker.importscripts.d.ts +23 -0
  157. package/dist/typescript-lib/lib.webworker.iterable.d.ts +340 -0
  158. package/licenses/Apache-2.0.txt +55 -0
  159. package/licenses/TypeScript-ThirdPartyNoticeText.txt +193 -0
  160. package/licenses/better-sqlite3-LICENSE.txt +21 -0
  161. package/mcp_config.json +16 -0
  162. package/native/go-worker/PROTOCOL.md +316 -0
  163. package/native/go-worker/cmd/worker/main.go +440 -0
  164. package/native/go-worker/go.mod +3 -0
  165. package/native/go-worker/internal/analyze/analyze.go +820 -0
  166. package/native/go-worker/internal/analyze/model.go +182 -0
  167. package/native/go-worker/internal/analyze/routes.go +181 -0
  168. package/native/python-worker/PROTOCOL.md +342 -0
  169. package/native/python-worker/worker.py +1190 -0
  170. package/native/roslyn-worker/Causoryn.RoslynWorker.csproj +40 -0
  171. package/native/roslyn-worker/Causoryn.RoslynWorker.deps.json +59 -0
  172. package/native/roslyn-worker/Causoryn.RoslynWorker.dll +0 -0
  173. package/native/roslyn-worker/Causoryn.RoslynWorker.runtimeconfig.json +13 -0
  174. package/native/roslyn-worker/Microsoft.CodeAnalysis.CSharp.dll +0 -0
  175. package/native/roslyn-worker/Microsoft.CodeAnalysis.dll +0 -0
  176. package/native/roslyn-worker/PROTOCOL.md +285 -0
  177. package/native/roslyn-worker/Program.cs +249 -0
  178. package/native/roslyn-worker/Protocol.cs +397 -0
  179. package/native/roslyn-worker/ReferenceResolver.cs +235 -0
  180. package/native/roslyn-worker/WorkerAnalyzer.cs +1669 -0
  181. package/native/roslyn-worker/packages.lock.json +30 -0
  182. package/native/rust-worker/Cargo.lock +107 -0
  183. package/native/rust-worker/Cargo.toml +23 -0
  184. package/native/rust-worker/PROTOCOL.md +294 -0
  185. package/native/rust-worker/src/analyzer.rs +1209 -0
  186. package/native/rust-worker/src/main.rs +127 -0
  187. package/native/rust-worker/src/protocol.rs +284 -0
  188. package/native/rust-worker/src/sha256.rs +136 -0
  189. package/package.json +71 -4
  190. package/plugin.json +17 -0
  191. package/scripts/causoryn.mjs +40 -0
  192. package/scripts/lib/node-version-guard.mjs +24 -0
  193. package/scripts/plugin-mcp-launcher.mjs +111 -0
  194. package/skills/causoryn/SKILL.md +53 -0
  195. package/skills/map-system/SKILL.md +69 -0
  196. package/skills/preflight-change/SKILL.md +38 -0
  197. package/skills/verify-change/SKILL.md +31 -0
@@ -0,0 +1,820 @@
1
+ // analyze.go — go/parser + go/ast ile graph çıkarımı (M1-Go).
2
+ //
3
+ // Çıkarım disiplini (PROTOCOL.md resolution tablosu — dürüstlük sözleşmesi):
4
+ // - Aynı package içindeki tanımlı fonksiyona bare-ident çağrı → verified
5
+ // (go/ast declaration eşleşmesi; kaynak-içi sembol).
6
+ // - Package-qualified çağrı (pkg.Func; pkg analiz setindeki package) →
7
+ // heuristic + ambiguity (go/types semantik çözümleme YOK — ad kuralı).
8
+ // - Import local adı eşleşen / analiz seti dışı package çağrısı →
9
+ // heuristic + UnknownExternal (çağrı metni hedef olarak temsil edilir).
10
+ // - Benzersiz metot adı → heuristic; birden çok aday → unresolved +
11
+ // aday listesi; arayüz metodu adı → heuristic + UnknownExternal.
12
+ // - Hiç eşleşmeyen ifade → unresolved + UnknownExternal (çağrı metni);
13
+ // uydurma hedef ÜRETİLMEZ.
14
+ //
15
+ // Determinizm: dosyalar relativePath sıralı işlenir; node/edge/evidence
16
+ // kanonik anahtarla sıralanır; saat okunmaz; map yineleme sırası çıktıya
17
+ // sırtlanmaz (tüm çıktı kümeleri sıralanır).
18
+ package analyze
19
+
20
+ import (
21
+ "fmt"
22
+ "go/ast"
23
+ "go/parser"
24
+ "go/scanner"
25
+ "go/token"
26
+ "sort"
27
+ "strconv"
28
+ "strings"
29
+ )
30
+
31
+ // SourceFile — worker'a gelen tek kaynak dosya (hash'i main hesaplar).
32
+ type SourceFile struct {
33
+ RelativePath string
34
+ Content string
35
+ SourceHash string
36
+ }
37
+
38
+ // Analyze sonucu — main bu alanları doğrudan Response'a kopyalar.
39
+ type Result struct {
40
+ State string // "ready" | "partial"
41
+ CoverageRatio float64
42
+ Warnings []string
43
+ Diagnostics []Diagnostic
44
+ Nodes []Node
45
+ Edges []Edge
46
+ Evidence []Evidence // kept edge kanıtlarının dedupe edilmiş listesi
47
+ }
48
+
49
+ type fileCtx struct {
50
+ relativePath string
51
+ content string
52
+ hash string
53
+ pkgName string
54
+ imports map[string]bool // import local adları ("_"/"." hariç)
55
+ f *ast.File
56
+ depthFlagged bool
57
+ }
58
+
59
+ type funcInfo struct {
60
+ file *fileCtx
61
+ decl *ast.FuncDecl
62
+ pkg string
63
+ name string
64
+ recv string // "" → top-level func; değilse alıcı tip adı
65
+ qname string
66
+ }
67
+
68
+ type typeInfo struct {
69
+ file *fileCtx
70
+ spec *ast.TypeSpec
71
+ pkg string
72
+ name string
73
+ qname string
74
+ kind string // Class | Interface | Type
75
+ }
76
+
77
+ // depthProbe — ast.Walk ile gövde başına maksimum derinlik ölçümü.
78
+ // Visit(nil) çağrıları Walk'ın exit sinyalidir; asla nil döndürmeyiz,
79
+ // böylece derinlik sayacı dengede kalır.
80
+ type depthProbe struct {
81
+ max int
82
+ depth int
83
+ }
84
+
85
+ func (p *depthProbe) Visit(n ast.Node) ast.Visitor {
86
+ if n == nil {
87
+ p.depth--
88
+ return nil
89
+ }
90
+ p.depth++
91
+ if p.depth > p.max {
92
+ p.max = p.depth
93
+ }
94
+ return p
95
+ }
96
+
97
+ // callTarget — tek çağrı ifadesinin çözümleme kararı.
98
+ type callTarget struct {
99
+ ref NodeRef
100
+ resolution string
101
+ ambiguity *Ambiguity
102
+ rationale string
103
+ // nil (skip): builtin vb. — kenar üretilmez.
104
+ }
105
+
106
+ func receiverTypeName(fd *ast.FuncDecl) string {
107
+ if fd.Recv == nil || len(fd.Recv.List) == 0 {
108
+ return ""
109
+ }
110
+ t := fd.Recv.List[0].Type
111
+ for {
112
+ switch v := t.(type) {
113
+ case *ast.StarExpr:
114
+ t = v.X
115
+ case *ast.IndexExpr:
116
+ t = v.X
117
+ case *ast.IndexListExpr:
118
+ t = v.X
119
+ case *ast.ParenExpr:
120
+ t = v.X
121
+ case *ast.Ident:
122
+ return v.Name
123
+ default:
124
+ return ""
125
+ }
126
+ }
127
+ }
128
+
129
+ // Analyze — verilen dosyalar (relativePath sıralı) üzerinden graph üretir.
130
+ // maxNodes ≤ 0 → MaxResponseNodes uygulanır.
131
+ func Analyze(files []SourceFile, maxNodes int) Result {
132
+ if len(files) > 1 {
133
+ // Savunma katmanı: main zaten sıralar; determinizm için burada da.
134
+ for i := 1; i < len(files); i++ {
135
+ for j := i; j > 0 && files[j].RelativePath < files[j-1].RelativePath; j-- {
136
+ files[j], files[j-1] = files[j-1], files[j]
137
+ }
138
+ }
139
+ }
140
+ budget := maxNodes
141
+ if budget <= 0 || budget > MaxResponseNodes {
142
+ budget = MaxResponseNodes
143
+ }
144
+
145
+ fset := token.NewFileSet()
146
+ var warnings []string
147
+ var diagnostics []Diagnostic
148
+
149
+ var fileCtxs []*fileCtx
150
+ var funcs []*funcInfo
151
+ var types []*typeInfo
152
+ pkgCount := map[string]int{}
153
+
154
+ // 1) Parse + declaration toplama (dosya sıralı, belge sıralı).
155
+ for _, sf := range files {
156
+ ctx := &fileCtx{
157
+ relativePath: sf.RelativePath,
158
+ content: sf.Content,
159
+ hash: sf.SourceHash,
160
+ imports: map[string]bool{},
161
+ }
162
+ fileCtxs = append(fileCtxs, ctx)
163
+ parsed, err := parser.ParseFile(fset, sf.RelativePath, sf.Content, parser.SkipObjectResolution)
164
+ if err != nil {
165
+ if list, ok := err.(scanner.ErrorList); ok {
166
+ for _, e := range list {
167
+ line := 0
168
+ if e.Pos.IsValid() {
169
+ line = e.Pos.Line
170
+ }
171
+ diagnostics = append(diagnostics, Diagnostic{
172
+ RelativePath: sf.RelativePath,
173
+ Code: "GOPARSE",
174
+ Message: e.Msg,
175
+ Line: line,
176
+ })
177
+ }
178
+ } else {
179
+ diagnostics = append(diagnostics, Diagnostic{
180
+ RelativePath: sf.RelativePath,
181
+ Code: "GOPARSE",
182
+ Message: err.Error(),
183
+ Line: 0,
184
+ })
185
+ }
186
+ }
187
+ if parsed == nil {
188
+ continue
189
+ }
190
+ ctx.f = parsed
191
+ ctx.pkgName = parsed.Name.Name
192
+ pkgCount[parsed.Name.Name]++
193
+ for _, imp := range parsed.Imports {
194
+ pathValue, uerr := strconv.Unquote(imp.Path.Value)
195
+ if uerr != nil {
196
+ continue
197
+ }
198
+ local := ""
199
+ if imp.Name != nil {
200
+ local = imp.Name.Name
201
+ }
202
+ if local == "" {
203
+ local = pathValue
204
+ if idx := strings.LastIndex(local, "/"); idx >= 0 {
205
+ local = local[idx+1:]
206
+ }
207
+ }
208
+ if local != "_" && local != "." && local != "" {
209
+ ctx.imports[local] = true
210
+ }
211
+ }
212
+ for _, decl := range parsed.Decls {
213
+ switch d := decl.(type) {
214
+ case *ast.FuncDecl:
215
+ recv := receiverTypeName(d)
216
+ fi := &funcInfo{file: ctx, decl: d, pkg: ctx.pkgName, name: d.Name.Name, recv: recv}
217
+ if recv != "" {
218
+ fi.qname = ctx.pkgName + "." + recv + "." + d.Name.Name
219
+ } else {
220
+ fi.qname = ctx.pkgName + "." + d.Name.Name
221
+ }
222
+ funcs = append(funcs, fi)
223
+ case *ast.GenDecl:
224
+ if d.Tok != token.TYPE {
225
+ continue
226
+ }
227
+ for _, spec := range d.Specs {
228
+ ts, ok := spec.(*ast.TypeSpec)
229
+ if !ok {
230
+ continue
231
+ }
232
+ ti := &typeInfo{file: ctx, spec: ts, pkg: ctx.pkgName, name: ts.Name.Name, qname: ctx.pkgName + "." + ts.Name.Name}
233
+ switch ts.Type.(type) {
234
+ case *ast.StructType:
235
+ ti.kind = "Class"
236
+ case *ast.InterfaceType:
237
+ ti.kind = "Interface"
238
+ default:
239
+ ti.kind = "Type"
240
+ }
241
+ types = append(types, ti)
242
+ }
243
+ }
244
+ }
245
+ }
246
+
247
+ // 2) İndeksler.
248
+ pkgFuncs := map[string]map[string]*funcInfo{} // package → top-level func adı
249
+ methodsByName := map[string][]*funcInfo{} // metot adı → adaylar (belge sıralı)
250
+ ifaceMethods := map[string][]string{} // arayüz metodu adı → arayüz qname'leri
251
+ typeIndex := map[string]*typeInfo{} // pkg\x00name → typeInfo
252
+ for _, ti := range types {
253
+ typeIndex[ti.pkg+"\x00"+ti.name] = ti
254
+ if ti.kind != "Interface" {
255
+ continue
256
+ }
257
+ it, ok := ti.spec.Type.(*ast.InterfaceType)
258
+ if !ok {
259
+ continue
260
+ }
261
+ for _, field := range it.Methods.List {
262
+ for _, nm := range field.Names {
263
+ ifaceMethods[nm.Name] = append(ifaceMethods[nm.Name], ti.qname)
264
+ }
265
+ }
266
+ }
267
+ for _, fi := range funcs {
268
+ if fi.recv == "" {
269
+ m := pkgFuncs[fi.pkg]
270
+ if m == nil {
271
+ m = map[string]*funcInfo{}
272
+ pkgFuncs[fi.pkg] = m
273
+ }
274
+ m[fi.name] = fi
275
+ } else {
276
+ methodsByName[fi.name] = append(methodsByName[fi.name], fi)
277
+ }
278
+ }
279
+ uniquePkg := func(name string) bool { return pkgCount[name] == 1 }
280
+
281
+ // 3) Node kümeleri.
282
+ nodeSet := map[string]Node{}
283
+ addNode := func(n Node) NodeRef {
284
+ ref := NodeRef{Kind: n.Kind, QualifiedName: n.QualifiedName, RelativePath: n.RelativePath}
285
+ key := nodeKey(ref)
286
+ if _, exists := nodeSet[key]; !exists {
287
+ nodeSet[key] = n
288
+ }
289
+ return ref
290
+ }
291
+ fileRef := func(ctx *fileCtx) NodeRef {
292
+ return addNode(Node{
293
+ Kind: "File",
294
+ QualifiedName: ctx.relativePath,
295
+ Language: "go",
296
+ RelativePath: ctx.relativePath,
297
+ Attributes: map[string]any{"sourceHash": ctx.hash},
298
+ })
299
+ }
300
+ ensureNodeRef := func(ref NodeRef) {
301
+ key := nodeKey(ref)
302
+ if _, exists := nodeSet[key]; !exists {
303
+ addNode(Node{Kind: ref.Kind, QualifiedName: ref.QualifiedName, Language: "go", RelativePath: ref.RelativePath, Attributes: map[string]any{}})
304
+ }
305
+ }
306
+ funcRef := func(fi *funcInfo) NodeRef {
307
+ kind := "Function"
308
+ if fi.recv != "" {
309
+ kind = "Method"
310
+ }
311
+ return addNode(Node{Kind: kind, QualifiedName: fi.qname, Language: "go", RelativePath: fi.file.relativePath, Attributes: map[string]any{}})
312
+ }
313
+ typeRef := func(ti *typeInfo) NodeRef {
314
+ return addNode(Node{Kind: ti.kind, QualifiedName: ti.qname, Language: "go", RelativePath: ti.file.relativePath, Attributes: map[string]any{}})
315
+ }
316
+
317
+ declSpan := func(ctx *fileCtx, from, to token.Pos) *Span {
318
+ start := fset.Position(from)
319
+ end := fset.Position(to)
320
+ return &Span{
321
+ RelativePath: ctx.relativePath,
322
+ StartLine: start.Line,
323
+ EndLine: end.Line,
324
+ SourceHash: ctx.hash,
325
+ }
326
+ }
327
+
328
+ // 4) Kenar toplayıcı (dedupe + evidence birleştirme).
329
+ edgeSet := map[string]int{}
330
+ var edges []Edge
331
+ addEdge := func(e Edge) {
332
+ ensureNodeRef(e.From)
333
+ ensureNodeRef(e.To)
334
+ key := edgeKey(e)
335
+ if idx, ok := edgeSet[key]; ok {
336
+ merged := edges[idx].Evidence
337
+ for _, ev := range e.Evidence {
338
+ merged = appendEvidenceUnique(merged, ev)
339
+ }
340
+ edges[idx].Evidence = merged
341
+ return
342
+ }
343
+ edgeSet[key] = len(edges)
344
+ edges = append(edges, e)
345
+ }
346
+
347
+ // 5) CONTAINS — File → üst-düzey bildirimler; Class/Interface/Type → metotları.
348
+ for _, fi := range funcs {
349
+ ref := funcRef(fi)
350
+ addEdge(Edge{
351
+ Kind: EdgeContains,
352
+ From: fileRef(fi.file),
353
+ To: ref,
354
+ Resolution: ResolutionVerified,
355
+ Evidence: []Evidence{{
356
+ Kind: EvidenceKindAstSpan,
357
+ Span: declSpan(fi.file, fi.decl.Pos(), fi.decl.End()),
358
+ AnalyzerID: AnalyzerID,
359
+ AnalyzerVersion: AnalyzerVersion,
360
+ Rationale: fmt.Sprintf(
361
+ "CONTAINS: %s '%s' bildirimini kapsar (go/ast declaration aralığı).",
362
+ fi.file.relativePath, fi.qname,
363
+ ),
364
+ }},
365
+ })
366
+ if fi.recv != "" {
367
+ if ti, ok := typeIndex[fi.pkg+"\x00"+fi.recv]; ok {
368
+ addEdge(Edge{
369
+ Kind: EdgeContains,
370
+ From: typeRef(ti),
371
+ To: ref,
372
+ Resolution: ResolutionVerified,
373
+ Evidence: []Evidence{{
374
+ Kind: EvidenceKindAstSpan,
375
+ Span: declSpan(fi.file, fi.decl.Pos(), fi.decl.End()),
376
+ AnalyzerID: AnalyzerID,
377
+ AnalyzerVersion: AnalyzerVersion,
378
+ Rationale: fmt.Sprintf(
379
+ "CONTAINS: %s '%s' metodunu kapsar (go/ast alıcı eşleşmesi).",
380
+ ti.qname, fi.qname,
381
+ ),
382
+ }},
383
+ })
384
+ }
385
+ }
386
+ }
387
+ for _, ti := range types {
388
+ addEdge(Edge{
389
+ Kind: EdgeContains,
390
+ From: fileRef(ti.file),
391
+ To: typeRef(ti),
392
+ Resolution: ResolutionVerified,
393
+ Evidence: []Evidence{{
394
+ Kind: EvidenceKindAstSpan,
395
+ Span: declSpan(ti.file, ti.spec.Pos(), ti.spec.End()),
396
+ AnalyzerID: AnalyzerID,
397
+ AnalyzerVersion: AnalyzerVersion,
398
+ Rationale: fmt.Sprintf(
399
+ "CONTAINS: %s '%s' bildirimini kapsar (go/ast type spec aralığı).",
400
+ ti.file.relativePath, ti.qname,
401
+ ),
402
+ }},
403
+ })
404
+ }
405
+
406
+ // 6) CALLS + ROUTES_TO — gövde gezinmesi (derinlik ölçümlü).
407
+ flagDepth := func(fctx *fileCtx) {
408
+ if fctx.depthFlagged {
409
+ return
410
+ }
411
+ fctx.depthFlagged = true
412
+ diagnostic := Diagnostic{
413
+ RelativePath: fctx.relativePath,
414
+ Code: "GO_AST_DEPTH",
415
+ Message: fmt.Sprintf("AST gezinme derinliği %d aşıldı; derin gövdeler çağrı çıkarımına dahil edilmedi", MaxAstDepth),
416
+ Line: 0,
417
+ }
418
+ diagnostics = append(diagnostics, diagnostic)
419
+ warnings = append(warnings, fmt.Sprintf("%s: AST derinlik sınırı aşan gövdeler atlandı (%s)", AnalyzerID, fctx.relativePath))
420
+ }
421
+ actx := &analysisContext{
422
+ fset: fset,
423
+ pkgFuncs: pkgFuncs,
424
+ uniquePkg: uniquePkg,
425
+ methodsByName: methodsByName,
426
+ ifaceMethods: ifaceMethods,
427
+ addNode: addNode,
428
+ addEdge: addEdge,
429
+ warnings: &warnings,
430
+ declSpan: declSpan,
431
+ }
432
+ for _, fi := range funcs {
433
+ if fi.decl.Body == nil {
434
+ continue
435
+ }
436
+ probe := &depthProbe{}
437
+ ast.Walk(probe, fi.decl.Body)
438
+ if probe.max > MaxAstDepth {
439
+ flagDepth(fi.file)
440
+ continue
441
+ }
442
+ calls := collectCallExprs(fi.decl.Body)
443
+ for _, call := range calls {
444
+ if match := matchRoute(call); match != nil {
445
+ handleRoute(actx, fi, match, call)
446
+ continue
447
+ }
448
+ resolveAndAddCallEdge(actx, fi, call)
449
+ }
450
+ }
451
+
452
+ // 7) Kanonik sıralama + node bütçesi + evidence birleşimi.
453
+ nodes := make([]Node, 0, len(nodeSet))
454
+ for _, n := range nodeSet {
455
+ nodes = append(nodes, n)
456
+ }
457
+ sortNodes(nodes)
458
+ if len(nodes) > budget {
459
+ kept := make(map[string]bool, budget)
460
+ for _, n := range nodes[:budget] {
461
+ kept[nodeKey(NodeRef{Kind: n.Kind, QualifiedName: n.QualifiedName, RelativePath: n.RelativePath})] = true
462
+ }
463
+ droppedEdges := 0
464
+ trimmed := edges[:0]
465
+ for _, e := range edges {
466
+ if kept[nodeKey(e.From)] && kept[nodeKey(e.To)] {
467
+ trimmed = append(trimmed, e)
468
+ } else {
469
+ droppedEdges++
470
+ }
471
+ }
472
+ edges = trimmed
473
+ diagnostics = append(diagnostics, Diagnostic{
474
+ RelativePath: "",
475
+ Code: "RESPONSE_TRUNCATED",
476
+ Message: fmt.Sprintf(
477
+ "yanıt node bütçesi (%d) aşıldı; %d node yayınlandı, uçları yayınlanmayan %d kenar düştü (dangling yok)",
478
+ budget, budget, droppedEdges,
479
+ ),
480
+ Line: 0,
481
+ })
482
+ nodes = nodes[:budget]
483
+ }
484
+ sortEdges(edges)
485
+
486
+ evidenceSet := map[string]bool{}
487
+ var evidence []Evidence
488
+ for _, e := range edges {
489
+ for _, ev := range e.Evidence {
490
+ key := evidenceKey(ev)
491
+ if !evidenceSet[key] {
492
+ evidenceSet[key] = true
493
+ evidence = append(evidence, ev)
494
+ }
495
+ }
496
+ }
497
+ sortEvidence(evidence)
498
+
499
+ verified := 0
500
+ for _, e := range edges {
501
+ if e.Resolution == ResolutionVerified {
502
+ verified++
503
+ }
504
+ }
505
+ coverage := 1.0
506
+ if len(edges) > 0 {
507
+ coverage = round4(float64(verified) / float64(len(edges)))
508
+ }
509
+
510
+ state := "ready"
511
+ if len(diagnostics) > 0 || len(warnings) > 0 {
512
+ state = "partial"
513
+ }
514
+ if warnings == nil {
515
+ warnings = []string{}
516
+ }
517
+ if diagnostics == nil {
518
+ diagnostics = []Diagnostic{}
519
+ }
520
+
521
+ return Result{
522
+ State: state,
523
+ CoverageRatio: coverage,
524
+ Warnings: warnings,
525
+ Diagnostics: diagnostics,
526
+ Nodes: nodes,
527
+ Edges: edges,
528
+ Evidence: evidence,
529
+ }
530
+ }
531
+
532
+ // --------------------------------------------------------------------
533
+ // Çağrı çözümleme (resolution tablosu)
534
+ // --------------------------------------------------------------------
535
+
536
+ func resolveAndAddCallEdge(actx *analysisContext, fi *funcInfo, call *ast.CallExpr) {
537
+ if id, ok := call.Fun.(*ast.Ident); ok && goBuiltins[id.Name] {
538
+ return
539
+ }
540
+ target := classifyExpr(fi, call.Fun, actx.fset, actx.pkgFuncs, actx.uniquePkg, actx.methodsByName, actx.ifaceMethods)
541
+ if target == nil {
542
+ return
543
+ }
544
+ span := actx.declSpan(fi.file, call.Pos(), call.End())
545
+ evidence := []Evidence{{
546
+ Kind: EvidenceKindAstSpan,
547
+ Span: span,
548
+ AnalyzerID: AnalyzerID,
549
+ AnalyzerVersion: AnalyzerVersion,
550
+ Rationale: target.rationale,
551
+ }}
552
+ actx.addEdge(Edge{
553
+ Kind: EdgeCalls,
554
+ From: NodeRef{Kind: funcKind(fi), QualifiedName: fi.qname, RelativePath: fi.file.relativePath},
555
+ To: target.ref,
556
+ Resolution: target.resolution,
557
+ Evidence: evidence,
558
+ Ambiguity: target.ambiguity,
559
+ })
560
+ }
561
+
562
+ func funcKind(fi *funcInfo) string {
563
+ if fi.recv != "" {
564
+ return "Method"
565
+ }
566
+ return "Function"
567
+ }
568
+
569
+ // classifyExpr — Fun ifadesini resolution tablosuna göre çözer; nil → skip.
570
+ func classifyExpr(
571
+ fi *funcInfo,
572
+ expr ast.Expr,
573
+ fset *token.FileSet,
574
+ pkgFuncs map[string]map[string]*funcInfo,
575
+ uniquePkg func(string) bool,
576
+ methodsByName map[string][]*funcInfo,
577
+ ifaceMethods map[string][]string,
578
+ ) *callTarget {
579
+ switch fun := expr.(type) {
580
+ case *ast.Ident:
581
+ if goBuiltins[fun.Name] {
582
+ return nil
583
+ }
584
+ if samePkg, ok := pkgFuncs[fi.pkg][fun.Name]; ok && samePkg.recv == "" {
585
+ return &callTarget{
586
+ ref: NodeRef{Kind: "Function", QualifiedName: samePkg.qname, RelativePath: samePkg.file.relativePath},
587
+ resolution: ResolutionVerified,
588
+ rationale: fmt.Sprintf(
589
+ "CALLS: %s → %s; aynı package içindeki tanımlı fonksiyon go/ast ile çözümlendi (verified).",
590
+ fi.qname, samePkg.qname,
591
+ ),
592
+ }
593
+ }
594
+ return &callTarget{
595
+ ref: NodeRef{Kind: "UnknownExternal", QualifiedName: fun.Name},
596
+ resolution: ResolutionUnresolved,
597
+ rationale: fmt.Sprintf(
598
+ "CALLS: '%s' hiçbir tanımlı sembolle eşleşmedi; uydurma hedef üretilmedi (unresolved).",
599
+ fun.Name,
600
+ ),
601
+ }
602
+ case *ast.SelectorExpr:
603
+ selName := fun.Sel.Name
604
+ text := exprText(fset, fi.file.content, expr)
605
+ // Zincirli ifadelerde (s.repo.FindAll) sol-temel ident'e inilir:
606
+ // package/import kontrolü TEMELE, metot adı kuralı dış Sel'e bakar.
607
+ // Böylece struct alanı üzerinden erişilen bağımlılık metotları
608
+ // (field.Method) benzersiz-ad kuralıyla çözümlenebilir.
609
+ var x *ast.Ident
610
+ base := ast.Expr(fun.X)
611
+ for base != nil {
612
+ switch v := base.(type) {
613
+ case *ast.Ident:
614
+ x = v
615
+ base = nil
616
+ case *ast.SelectorExpr:
617
+ base = v.X
618
+ case *ast.ParenExpr:
619
+ base = v.X
620
+ case *ast.CallExpr:
621
+ base = v.Fun
622
+ default:
623
+ base = nil
624
+ }
625
+ }
626
+ if x != nil {
627
+ // (a) Analiz setindeki package (unique clause adı) + declared func.
628
+ if uniquePkg(x.Name) {
629
+ if callee, ok := pkgFuncs[x.Name][selName]; ok && callee.recv == "" {
630
+ return &callTarget{
631
+ ref: NodeRef{Kind: "Function", QualifiedName: callee.qname, RelativePath: callee.file.relativePath},
632
+ resolution: ResolutionHeuristic,
633
+ ambiguity: &Ambiguity{
634
+ Candidates: []string{callee.qname},
635
+ Reason: fmt.Sprintf(
636
+ "package-qualified çağrı ad kuralıyla analiz setindeki %s package'ına eşlendi; go/types semantik çözümleme yok (heuristic).",
637
+ x.Name,
638
+ ),
639
+ },
640
+ rationale: fmt.Sprintf(
641
+ "CALLS: %s → %s; package-qualified çağrı ad kuralıyla analiz setindeki %s package'ına eşlendi (heuristic — go/types yok).",
642
+ fi.qname, callee.qname, x.Name,
643
+ ),
644
+ }
645
+ }
646
+ // (b) Setteki package ama bildirim yok → çözümsüz (uydurma yok).
647
+ return &callTarget{
648
+ ref: NodeRef{Kind: "UnknownExternal", QualifiedName: text},
649
+ resolution: ResolutionUnresolved,
650
+ rationale: fmt.Sprintf(
651
+ "CALLS: '%s' analiz setindeki %s package'ında tanımlı değil; uydurma hedef üretilmedi (unresolved).",
652
+ text, x.Name,
653
+ ),
654
+ }
655
+ }
656
+ // (c) Import local adı (analiz seti dışı package) → heuristic.
657
+ if fi.file.imports[x.Name] {
658
+ return &callTarget{
659
+ ref: NodeRef{Kind: "UnknownExternal", QualifiedName: text},
660
+ resolution: ResolutionHeuristic,
661
+ ambiguity: &Ambiguity{
662
+ Candidates: []string{text},
663
+ Reason: fmt.Sprintf(
664
+ "analiz seti dışı package çağrısı ('%s'); çağrı metni UnknownExternal üzerinde temsil edilir (heuristic).",
665
+ x.Name,
666
+ ),
667
+ },
668
+ rationale: fmt.Sprintf(
669
+ "CALLS: %s → %s; analiz seti dışı package çağrısı, çağrı metni UnknownExternal üzerinde temsil edilir (heuristic).",
670
+ fi.qname, text,
671
+ ),
672
+ }
673
+ }
674
+ // (d) Yerel değişken/parametre alıcısı → metot adı kuralı.
675
+ if candidates := methodsByName[selName]; len(candidates) == 1 {
676
+ only := candidates[0]
677
+ return &callTarget{
678
+ ref: NodeRef{Kind: "Method", QualifiedName: only.qname, RelativePath: only.file.relativePath},
679
+ resolution: ResolutionHeuristic,
680
+ ambiguity: &Ambiguity{
681
+ Candidates: []string{only.qname},
682
+ Reason: "benzersiz metot adı kuralı; alıcı tipi go/types olmadan doğrulanamaz (heuristic).",
683
+ },
684
+ rationale: fmt.Sprintf(
685
+ "CALLS: %s → %s; benzersiz metot adı kuralı (heuristic — alıcı tipi go/types olmadan doğrulanamaz).",
686
+ fi.qname, only.qname,
687
+ ),
688
+ }
689
+ } else if len(candidates) > 1 {
690
+ names := make([]string, 0, len(candidates))
691
+ for _, candidate := range candidates {
692
+ names = append(names, candidate.qname)
693
+ }
694
+ sortStrings(names)
695
+ return &callTarget{
696
+ ref: NodeRef{Kind: "UnknownExternal", QualifiedName: text},
697
+ resolution: ResolutionUnresolved,
698
+ ambiguity: &Ambiguity{
699
+ Candidates: names,
700
+ Reason: "metot adı analiz setinde birden fazla tipte bulundu; belirsizlik çözülemedi (unresolved).",
701
+ },
702
+ rationale: fmt.Sprintf(
703
+ "CALLS: '%s' birden fazla aday metotla eşleşti (%d aday); uydurma hedef üretilmedi (unresolved).",
704
+ text, len(names),
705
+ ),
706
+ }
707
+ }
708
+ // (e) Arayüz metodu adı → heuristic + UnknownExternal.
709
+ if ifaceNames := ifaceMethods[selName]; len(ifaceNames) > 0 {
710
+ sorted := append([]string(nil), ifaceNames...)
711
+ sortStrings(sorted)
712
+ candidates := make([]string, 0, len(sorted))
713
+ for _, ifaceQname := range sorted {
714
+ candidates = append(candidates, ifaceQname+"."+selName)
715
+ }
716
+ return &callTarget{
717
+ ref: NodeRef{Kind: "UnknownExternal", QualifiedName: text},
718
+ resolution: ResolutionHeuristic,
719
+ ambiguity: &Ambiguity{
720
+ Candidates: candidates,
721
+ Reason: "arayüz metodu adı analiz setinde bulundu; somut gerçekleme go/types olmadan çözülemez (heuristic).",
722
+ },
723
+ rationale: fmt.Sprintf(
724
+ "CALLS: %s → %s; arayüz metodu adı analiz setinde bulundu, somut gerçekleme çözülemez (heuristic).",
725
+ fi.qname, text,
726
+ ),
727
+ }
728
+ }
729
+ // (f) Hiç eşleşme yok.
730
+ return &callTarget{
731
+ ref: NodeRef{Kind: "UnknownExternal", QualifiedName: text},
732
+ resolution: ResolutionUnresolved,
733
+ rationale: fmt.Sprintf(
734
+ "CALLS: '%s' hiçbir tanımlı sembolle eşleşmedi; uydurma hedef üretilmedi (unresolved).",
735
+ text,
736
+ ),
737
+ }
738
+ }
739
+ // X ident değil (zincirli çağrı vb.).
740
+ return &callTarget{
741
+ ref: NodeRef{Kind: "UnknownExternal", QualifiedName: text},
742
+ resolution: ResolutionUnresolved,
743
+ rationale: fmt.Sprintf(
744
+ "CALLS: '%s' zincirli ifade çözümlenemedi; uydurma hedef üretilmedi (unresolved).",
745
+ text,
746
+ ),
747
+ }
748
+ default:
749
+ // FuncLit çağrısı, generic instantiation vb.
750
+ text := exprText(fset, fi.file.content, expr)
751
+ return &callTarget{
752
+ ref: NodeRef{Kind: "UnknownExternal", QualifiedName: text},
753
+ resolution: ResolutionUnresolved,
754
+ rationale: fmt.Sprintf(
755
+ "CALLS: '%s' bu dilimde çözümlenmeyen ifade kalıbı; uydurma hedef üretilmedi (unresolved).",
756
+ text,
757
+ ),
758
+ }
759
+ }
760
+ }
761
+
762
+ func exprText(fset *token.FileSet, content string, e ast.Expr) string {
763
+ start := fset.Position(e.Pos())
764
+ end := fset.Position(e.End())
765
+ if !start.IsValid() || !end.IsValid() || end.Offset < start.Offset || end.Offset > len(content) {
766
+ return ""
767
+ }
768
+ return content[start.Offset:end.Offset]
769
+ }
770
+
771
+ func collectCallExprs(body *ast.BlockStmt) []*ast.CallExpr {
772
+ var calls []*ast.CallExpr
773
+ ast.Inspect(body, func(n ast.Node) bool {
774
+ if call, ok := n.(*ast.CallExpr); ok {
775
+ calls = append(calls, call)
776
+ }
777
+ return true
778
+ })
779
+ return calls
780
+ }
781
+
782
+ // --------------------------------------------------------------------
783
+ // Kanonik sıralama + evidence yardımcıları
784
+ // --------------------------------------------------------------------
785
+
786
+ func nodeSortKey(n Node) string {
787
+ return n.Kind + "\x00" + n.QualifiedName + "\x00" + n.RelativePath
788
+ }
789
+
790
+ func sortNodes(nodes []Node) {
791
+ sort.Slice(nodes, func(i, j int) bool {
792
+ return nodeSortKey(nodes[i]) < nodeSortKey(nodes[j])
793
+ })
794
+ }
795
+
796
+ func edgeSortKey(e Edge) string {
797
+ return e.Kind + "\x00" + nodeKey(e.From) + "\x00" + nodeKey(e.To)
798
+ }
799
+
800
+ func sortEdges(edges []Edge) {
801
+ sort.Slice(edges, func(i, j int) bool {
802
+ return edgeSortKey(edges[i]) < edgeSortKey(edges[j])
803
+ })
804
+ }
805
+
806
+ func sortEvidence(evidence []Evidence) {
807
+ sort.Slice(evidence, func(i, j int) bool {
808
+ return evidenceKey(evidence[i]) < evidenceKey(evidence[j])
809
+ })
810
+ }
811
+
812
+ func appendEvidenceUnique(base []Evidence, ev Evidence) []Evidence {
813
+ key := evidenceKey(ev)
814
+ for _, existing := range base {
815
+ if evidenceKey(existing) == key {
816
+ return base
817
+ }
818
+ }
819
+ return append(base, ev)
820
+ }