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.
- package/.claude-plugin/plugin.json +36 -0
- package/.codex-plugin/mcp.json +19 -0
- package/.codex-plugin/plugin.json +38 -0
- package/.zcode-plugin/plugin.json +42 -0
- package/LICENSE +21 -0
- package/README.md +171 -2
- package/THIRD-PARTY-NOTICES.md +443 -0
- package/dist/bundle-manifest.json +39 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.js +253 -0
- package/dist/doctor.d.ts +13 -0
- package/dist/doctor.js +507 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +10 -0
- package/dist/mcp-server.mjs +288477 -0
- package/dist/mcp-server.mjs.LEGAL.txt +17 -0
- package/dist/node_modules/better-sqlite3/LICENSE +21 -0
- package/dist/node_modules/better-sqlite3/lib/binding.js +62 -0
- package/dist/node_modules/better-sqlite3/lib/darwin-arm64.js +3 -0
- package/dist/node_modules/better-sqlite3/lib/darwin-x64.js +3 -0
- package/dist/node_modules/better-sqlite3/lib/database.js +109 -0
- package/dist/node_modules/better-sqlite3/lib/index.js +3 -0
- package/dist/node_modules/better-sqlite3/lib/linux-arm64.js +3 -0
- package/dist/node_modules/better-sqlite3/lib/linux-x64.js +3 -0
- package/dist/node_modules/better-sqlite3/lib/linuxmusl-arm64.js +4 -0
- package/dist/node_modules/better-sqlite3/lib/linuxmusl-x64.js +4 -0
- package/dist/node_modules/better-sqlite3/lib/methods/aggregate.js +43 -0
- package/dist/node_modules/better-sqlite3/lib/methods/backup.js +67 -0
- package/dist/node_modules/better-sqlite3/lib/methods/explain.js +9 -0
- package/dist/node_modules/better-sqlite3/lib/methods/function.js +31 -0
- package/dist/node_modules/better-sqlite3/lib/methods/inspect.js +7 -0
- package/dist/node_modules/better-sqlite3/lib/methods/pragma.js +12 -0
- package/dist/node_modules/better-sqlite3/lib/methods/serialize.js +16 -0
- package/dist/node_modules/better-sqlite3/lib/methods/table.js +195 -0
- package/dist/node_modules/better-sqlite3/lib/methods/transaction.js +78 -0
- package/dist/node_modules/better-sqlite3/lib/methods/wrappers.js +54 -0
- package/dist/node_modules/better-sqlite3/lib/sqlite-error.js +25 -0
- package/dist/node_modules/better-sqlite3/lib/util.js +12 -0
- package/dist/node_modules/better-sqlite3/lib/win32-arm64.js +3 -0
- package/dist/node_modules/better-sqlite3/lib/win32-x64.js +3 -0
- package/dist/node_modules/better-sqlite3/package.json +67 -0
- package/dist/node_modules/better-sqlite3/prebuilds/darwin-arm64.node +0 -0
- package/dist/node_modules/better-sqlite3/prebuilds/darwin-x64.node +0 -0
- package/dist/node_modules/better-sqlite3/prebuilds/linux-arm64.node +0 -0
- package/dist/node_modules/better-sqlite3/prebuilds/linux-x64.node +0 -0
- package/dist/node_modules/better-sqlite3/prebuilds/linuxmusl-arm64.node +0 -0
- package/dist/node_modules/better-sqlite3/prebuilds/linuxmusl-x64.node +0 -0
- package/dist/node_modules/better-sqlite3/prebuilds/win32-arm64.node +0 -0
- package/dist/node_modules/better-sqlite3/prebuilds/win32-x64.node +0 -0
- package/dist/runtime-stage.d.ts +8 -0
- package/dist/runtime-stage.js +159 -0
- package/dist/setup.d.ts +15 -0
- package/dist/setup.js +735 -0
- package/dist/toml-patch.d.ts +10 -0
- package/dist/toml-patch.js +587 -0
- package/dist/types.d.ts +144 -0
- package/dist/types.js +35 -0
- package/dist/typescript-lib/lib.d.ts +22 -0
- package/dist/typescript-lib/lib.decorators.d.ts +384 -0
- package/dist/typescript-lib/lib.decorators.legacy.d.ts +22 -0
- package/dist/typescript-lib/lib.dom.asynciterable.d.ts +41 -0
- package/dist/typescript-lib/lib.dom.d.ts +39429 -0
- package/dist/typescript-lib/lib.dom.iterable.d.ts +571 -0
- package/dist/typescript-lib/lib.es2015.collection.d.ts +147 -0
- package/dist/typescript-lib/lib.es2015.core.d.ts +597 -0
- package/dist/typescript-lib/lib.es2015.d.ts +28 -0
- package/dist/typescript-lib/lib.es2015.generator.d.ts +77 -0
- package/dist/typescript-lib/lib.es2015.iterable.d.ts +605 -0
- package/dist/typescript-lib/lib.es2015.promise.d.ts +81 -0
- package/dist/typescript-lib/lib.es2015.proxy.d.ts +128 -0
- package/dist/typescript-lib/lib.es2015.reflect.d.ts +144 -0
- package/dist/typescript-lib/lib.es2015.symbol.d.ts +46 -0
- package/dist/typescript-lib/lib.es2015.symbol.wellknown.d.ts +326 -0
- package/dist/typescript-lib/lib.es2016.array.include.d.ts +116 -0
- package/dist/typescript-lib/lib.es2016.d.ts +21 -0
- package/dist/typescript-lib/lib.es2016.full.d.ts +23 -0
- package/dist/typescript-lib/lib.es2016.intl.d.ts +31 -0
- package/dist/typescript-lib/lib.es2017.arraybuffer.d.ts +21 -0
- package/dist/typescript-lib/lib.es2017.d.ts +26 -0
- package/dist/typescript-lib/lib.es2017.date.d.ts +31 -0
- package/dist/typescript-lib/lib.es2017.full.d.ts +23 -0
- package/dist/typescript-lib/lib.es2017.intl.d.ts +44 -0
- package/dist/typescript-lib/lib.es2017.object.d.ts +49 -0
- package/dist/typescript-lib/lib.es2017.sharedmemory.d.ts +135 -0
- package/dist/typescript-lib/lib.es2017.string.d.ts +45 -0
- package/dist/typescript-lib/lib.es2017.typedarrays.d.ts +53 -0
- package/dist/typescript-lib/lib.es2018.asyncgenerator.d.ts +77 -0
- package/dist/typescript-lib/lib.es2018.asynciterable.d.ts +53 -0
- package/dist/typescript-lib/lib.es2018.d.ts +24 -0
- package/dist/typescript-lib/lib.es2018.full.d.ts +24 -0
- package/dist/typescript-lib/lib.es2018.intl.d.ts +83 -0
- package/dist/typescript-lib/lib.es2018.promise.d.ts +30 -0
- package/dist/typescript-lib/lib.es2018.regexp.d.ts +37 -0
- package/dist/typescript-lib/lib.es2019.array.d.ts +79 -0
- package/dist/typescript-lib/lib.es2019.d.ts +24 -0
- package/dist/typescript-lib/lib.es2019.full.d.ts +24 -0
- package/dist/typescript-lib/lib.es2019.intl.d.ts +23 -0
- package/dist/typescript-lib/lib.es2019.object.d.ts +33 -0
- package/dist/typescript-lib/lib.es2019.string.d.ts +37 -0
- package/dist/typescript-lib/lib.es2019.symbol.d.ts +24 -0
- package/dist/typescript-lib/lib.es2020.bigint.d.ts +765 -0
- package/dist/typescript-lib/lib.es2020.d.ts +27 -0
- package/dist/typescript-lib/lib.es2020.date.d.ts +42 -0
- package/dist/typescript-lib/lib.es2020.full.d.ts +24 -0
- package/dist/typescript-lib/lib.es2020.intl.d.ts +474 -0
- package/dist/typescript-lib/lib.es2020.number.d.ts +28 -0
- package/dist/typescript-lib/lib.es2020.promise.d.ts +47 -0
- package/dist/typescript-lib/lib.es2020.sharedmemory.d.ts +99 -0
- package/dist/typescript-lib/lib.es2020.string.d.ts +44 -0
- package/dist/typescript-lib/lib.es2020.symbol.wellknown.d.ts +41 -0
- package/dist/typescript-lib/lib.es2021.d.ts +23 -0
- package/dist/typescript-lib/lib.es2021.full.d.ts +24 -0
- package/dist/typescript-lib/lib.es2021.intl.d.ts +166 -0
- package/dist/typescript-lib/lib.es2021.promise.d.ts +48 -0
- package/dist/typescript-lib/lib.es2021.string.d.ts +33 -0
- package/dist/typescript-lib/lib.es2021.weakref.d.ts +78 -0
- package/dist/typescript-lib/lib.es2022.array.d.ts +121 -0
- package/dist/typescript-lib/lib.es2022.d.ts +25 -0
- package/dist/typescript-lib/lib.es2022.error.d.ts +75 -0
- package/dist/typescript-lib/lib.es2022.full.d.ts +24 -0
- package/dist/typescript-lib/lib.es2022.intl.d.ts +145 -0
- package/dist/typescript-lib/lib.es2022.object.d.ts +26 -0
- package/dist/typescript-lib/lib.es2022.regexp.d.ts +39 -0
- package/dist/typescript-lib/lib.es2022.string.d.ts +25 -0
- package/dist/typescript-lib/lib.es2023.array.d.ts +924 -0
- package/dist/typescript-lib/lib.es2023.collection.d.ts +21 -0
- package/dist/typescript-lib/lib.es2023.d.ts +22 -0
- package/dist/typescript-lib/lib.es2023.full.d.ts +24 -0
- package/dist/typescript-lib/lib.es2023.intl.d.ts +56 -0
- package/dist/typescript-lib/lib.es2024.arraybuffer.d.ts +65 -0
- package/dist/typescript-lib/lib.es2024.collection.d.ts +29 -0
- package/dist/typescript-lib/lib.es2024.d.ts +26 -0
- package/dist/typescript-lib/lib.es2024.full.d.ts +24 -0
- package/dist/typescript-lib/lib.es2024.object.d.ts +29 -0
- package/dist/typescript-lib/lib.es2024.promise.d.ts +35 -0
- package/dist/typescript-lib/lib.es2024.regexp.d.ts +25 -0
- package/dist/typescript-lib/lib.es2024.sharedmemory.d.ts +68 -0
- package/dist/typescript-lib/lib.es2024.string.d.ts +29 -0
- package/dist/typescript-lib/lib.es5.d.ts +4601 -0
- package/dist/typescript-lib/lib.es6.d.ts +23 -0
- package/dist/typescript-lib/lib.esnext.array.d.ts +35 -0
- package/dist/typescript-lib/lib.esnext.collection.d.ts +96 -0
- package/dist/typescript-lib/lib.esnext.d.ts +29 -0
- package/dist/typescript-lib/lib.esnext.decorators.d.ts +28 -0
- package/dist/typescript-lib/lib.esnext.disposable.d.ts +193 -0
- package/dist/typescript-lib/lib.esnext.error.d.ts +24 -0
- package/dist/typescript-lib/lib.esnext.float16.d.ts +445 -0
- package/dist/typescript-lib/lib.esnext.full.d.ts +24 -0
- package/dist/typescript-lib/lib.esnext.intl.d.ts +21 -0
- package/dist/typescript-lib/lib.esnext.iterator.d.ts +148 -0
- package/dist/typescript-lib/lib.esnext.promise.d.ts +34 -0
- package/dist/typescript-lib/lib.esnext.sharedmemory.d.ts +25 -0
- package/dist/typescript-lib/lib.scripthost.d.ts +322 -0
- package/dist/typescript-lib/lib.webworker.asynciterable.d.ts +41 -0
- package/dist/typescript-lib/lib.webworker.d.ts +13150 -0
- package/dist/typescript-lib/lib.webworker.importscripts.d.ts +23 -0
- package/dist/typescript-lib/lib.webworker.iterable.d.ts +340 -0
- package/licenses/Apache-2.0.txt +55 -0
- package/licenses/TypeScript-ThirdPartyNoticeText.txt +193 -0
- package/licenses/better-sqlite3-LICENSE.txt +21 -0
- package/mcp_config.json +16 -0
- package/native/go-worker/PROTOCOL.md +316 -0
- package/native/go-worker/cmd/worker/main.go +440 -0
- package/native/go-worker/go.mod +3 -0
- package/native/go-worker/internal/analyze/analyze.go +820 -0
- package/native/go-worker/internal/analyze/model.go +182 -0
- package/native/go-worker/internal/analyze/routes.go +181 -0
- package/native/python-worker/PROTOCOL.md +342 -0
- package/native/python-worker/worker.py +1190 -0
- package/native/roslyn-worker/Causoryn.RoslynWorker.csproj +40 -0
- package/native/roslyn-worker/Causoryn.RoslynWorker.deps.json +59 -0
- package/native/roslyn-worker/Causoryn.RoslynWorker.dll +0 -0
- package/native/roslyn-worker/Causoryn.RoslynWorker.runtimeconfig.json +13 -0
- package/native/roslyn-worker/Microsoft.CodeAnalysis.CSharp.dll +0 -0
- package/native/roslyn-worker/Microsoft.CodeAnalysis.dll +0 -0
- package/native/roslyn-worker/PROTOCOL.md +285 -0
- package/native/roslyn-worker/Program.cs +249 -0
- package/native/roslyn-worker/Protocol.cs +397 -0
- package/native/roslyn-worker/ReferenceResolver.cs +235 -0
- package/native/roslyn-worker/WorkerAnalyzer.cs +1669 -0
- package/native/roslyn-worker/packages.lock.json +30 -0
- package/native/rust-worker/Cargo.lock +107 -0
- package/native/rust-worker/Cargo.toml +23 -0
- package/native/rust-worker/PROTOCOL.md +294 -0
- package/native/rust-worker/src/analyzer.rs +1209 -0
- package/native/rust-worker/src/main.rs +127 -0
- package/native/rust-worker/src/protocol.rs +284 -0
- package/native/rust-worker/src/sha256.rs +136 -0
- package/package.json +71 -4
- package/plugin.json +17 -0
- package/scripts/causoryn.mjs +40 -0
- package/scripts/lib/node-version-guard.mjs +24 -0
- package/scripts/plugin-mcp-launcher.mjs +111 -0
- package/skills/causoryn/SKILL.md +53 -0
- package/skills/map-system/SKILL.md +69 -0
- package/skills/preflight-change/SKILL.md +38 -0
- package/skills/verify-change/SKILL.md +31 -0
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
// Package analyze — go/parser + go/ast ile satır-bazlı JSON protokolünün
|
|
2
|
+
// graph çıkarımı (M1-Go dilimi; TŞ v2.1 §7 Go satırı, §8 node/edge sözleşmesi).
|
|
3
|
+
//
|
|
4
|
+
// model.go: protokol ve graph tipleri (packages/domain SnapshotNodeInput /
|
|
5
|
+
// SnapshotEdgeInput / SnapshotEvidenceInput GİRDİ sözleşmesiyle alan-adı
|
|
6
|
+
// düzeyinde hizalı — worker KİMLİK ÜRETMEZ; canonical ID merkezi normalizer
|
|
7
|
+
// kalır). Analyzer sabitleri, resolution tablosu ve kanonik sıralama
|
|
8
|
+
// yardımcıları da burada yaşar.
|
|
9
|
+
package analyze
|
|
10
|
+
|
|
11
|
+
import (
|
|
12
|
+
"encoding/json"
|
|
13
|
+
"sort"
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
// Analyzer kimliği — Evidence.analyzerId karşılığı; TS adapter sabitiyle
|
|
17
|
+
// (adapters/go GO_ADAPTER_ID) aynı olmalıdır.
|
|
18
|
+
const AnalyzerID = "go-worker"
|
|
19
|
+
|
|
20
|
+
// AnalyzerVersion — csproj <Version> karşılığı; Evidence.analyzerVersion'a
|
|
21
|
+
// yazılır ve yanıttaki worker.analyzerVersion ile senkrondur.
|
|
22
|
+
const AnalyzerVersion = "0.1.0"
|
|
23
|
+
|
|
24
|
+
// Protokol sürümü (PROTOCOL.md v1).
|
|
25
|
+
const ProtocolVersion = "1"
|
|
26
|
+
|
|
27
|
+
// Kaynak sınırları (TŞ §9 resource budget; K-010: yalnızca boyut limitleri).
|
|
28
|
+
const (
|
|
29
|
+
// MaxRequestLineChars — tek istek satırı üst sınırı (char). Aşım: satırın
|
|
30
|
+
// kalanı DISCARD edilir; id:null + LIMIT_EXCEEDED yanıtı yazılır.
|
|
31
|
+
MaxRequestLineChars = 64_000_000
|
|
32
|
+
// MaxFileCount — istek başına dosya sayısı üst sınırı.
|
|
33
|
+
MaxFileCount = 5_000
|
|
34
|
+
// MaxFileContentBytes — tek dosya içeriği üst sınırı (UTF-8 bayt).
|
|
35
|
+
MaxFileContentBytes = 2_000_000
|
|
36
|
+
// MaxResponseNodes — yanıt node bütçesi; istek maxNodes ile altına
|
|
37
|
+
// çekilebilir (1..MaxResponseNodes; dışı INVALID_ARGUMENT).
|
|
38
|
+
MaxResponseNodes = 250_000
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
// MaxAstDepth — dosya başına AST gezinme derinliği sınırı. Bu sınırı aşan
|
|
42
|
+
// gövde çağrı çıkarımına DAHİL EDİLMEZ; dosya başına bir kez GO_AST_DEPTH
|
|
43
|
+
// tanısı + uyarı verilir ve analiz partial olur (Roslyn worker'daki 1000
|
|
44
|
+
// derinlik savunmasının Go karşılığı).
|
|
45
|
+
const MaxAstDepth = 1000
|
|
46
|
+
|
|
47
|
+
// RouteDetectionCapability — CapabilitiesOut.routeDetection sabiti; TS
|
|
48
|
+
// adapter testleri bu dizgiyi birebir doğrular.
|
|
49
|
+
const RouteDetectionCapability = "go-http-handlefunc-and-gin-echo-chi-registration-pattern"
|
|
50
|
+
|
|
51
|
+
// UnsupportedConstructs — bu dilimde modellenmeyen kurulumların AÇIK beyanı
|
|
52
|
+
// (sessiz eksiklik yok; Roslyn worker unsupportedConstructs disiplini):
|
|
53
|
+
// - semantic-type-resolution: go/types semantik model YOK; package adı ve
|
|
54
|
+
// benzersiz metot adı kuralı heuristic'tir (belgelenmiştir).
|
|
55
|
+
// - inline-anonymous-route-handlers: func literal handler'da Endpoint
|
|
56
|
+
// korunur, ROUTES_TO üretilmez + uyarı verilir (Roslyn paraleli).
|
|
57
|
+
// - builtin-function-calls: len/make/append... çağrıları CALLS üretmez.
|
|
58
|
+
// - closure-call-attribution: func literal içindeki çağrılar kapsayan
|
|
59
|
+
// adlı fonksiyona Yazılır (AST yaklaşımı, belgelenmiştir).
|
|
60
|
+
var UnsupportedConstructs = []string{
|
|
61
|
+
"semantic-type-resolution",
|
|
62
|
+
"inline-anonymous-route-handlers",
|
|
63
|
+
"builtin-function-calls",
|
|
64
|
+
"closure-call-attribution",
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// goBuiltins — CALLS üretmeyen Go öntanımlı fonksiyonları (go/types olmadan
|
|
68
|
+
// bunların çağrı oldukları AST'ten bellidir ama sembol çözümlemesi anlamsızdır).
|
|
69
|
+
var goBuiltins = map[string]bool{
|
|
70
|
+
"append": true, "cap": true, "clear": true, "close": true,
|
|
71
|
+
"complex": true, "copy": true, "delete": true, "imag": true,
|
|
72
|
+
"len": true, "make": true, "max": true, "min": true, "new": true,
|
|
73
|
+
"panic": true, "print": true, "println": true, "real": true,
|
|
74
|
+
"recover": true,
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// Node/NodeRef/Evidence/Span/Ambiguity — domain SnapshotNodeInput /
|
|
78
|
+
// NodeRef / SnapshotEvidenceInput / SourceSpan karşılıkları (ID'siz).
|
|
79
|
+
//
|
|
80
|
+
// Determinizm: encoding/json map anahtarlarını sıralı yazar; struct alan
|
|
81
|
+
// sırası sabittir; aynı girdi → birebir aynı yanıt satırı (PROTOCOL.md §6).
|
|
82
|
+
|
|
83
|
+
type Span struct {
|
|
84
|
+
RelativePath string `json:"relativePath"`
|
|
85
|
+
StartLine int `json:"startLine"`
|
|
86
|
+
EndLine int `json:"endLine"`
|
|
87
|
+
SourceHash string `json:"sourceHash"`
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
type Evidence struct {
|
|
91
|
+
Kind string `json:"kind"`
|
|
92
|
+
Span *Span `json:"span,omitempty"`
|
|
93
|
+
AnalyzerID string `json:"analyzerId"`
|
|
94
|
+
AnalyzerVersion string `json:"analyzerVersion"`
|
|
95
|
+
Rationale string `json:"rationale"`
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
type NodeRef struct {
|
|
99
|
+
Kind string `json:"kind"`
|
|
100
|
+
QualifiedName string `json:"qualifiedName"`
|
|
101
|
+
RelativePath string `json:"relativePath,omitempty"`
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
type Node struct {
|
|
105
|
+
Kind string `json:"kind"`
|
|
106
|
+
QualifiedName string `json:"qualifiedName"`
|
|
107
|
+
Language string `json:"language"`
|
|
108
|
+
RelativePath string `json:"relativePath,omitempty"`
|
|
109
|
+
Attributes map[string]any `json:"attributes"`
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
type Ambiguity struct {
|
|
113
|
+
Candidates []string `json:"candidates"`
|
|
114
|
+
Reason string `json:"reason"`
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
type Edge struct {
|
|
118
|
+
Kind string `json:"kind"`
|
|
119
|
+
From NodeRef `json:"from"`
|
|
120
|
+
To NodeRef `json:"to"`
|
|
121
|
+
Resolution string `json:"resolution"`
|
|
122
|
+
Evidence []Evidence `json:"evidence"`
|
|
123
|
+
Ambiguity *Ambiguity `json:"ambiguity,omitempty"`
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
type Diagnostic struct {
|
|
127
|
+
RelativePath string `json:"relativePath"`
|
|
128
|
+
Code string `json:"code"`
|
|
129
|
+
Message string `json:"message"`
|
|
130
|
+
Line int `json:"line"`
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// Resolution değerleri (TŞ §8).
|
|
134
|
+
const (
|
|
135
|
+
ResolutionVerified = "verified"
|
|
136
|
+
ResolutionHeuristic = "heuristic"
|
|
137
|
+
ResolutionUnresolved = "unresolved"
|
|
138
|
+
)
|
|
139
|
+
|
|
140
|
+
// Edge kind sabitleri (worker yalnızca bu üçünü üretir).
|
|
141
|
+
const (
|
|
142
|
+
EdgeContains = "CONTAINS"
|
|
143
|
+
EdgeCalls = "CALLS"
|
|
144
|
+
EdgeRoutesTo = "ROUTES_TO"
|
|
145
|
+
)
|
|
146
|
+
|
|
147
|
+
// Evidence kind sabitleri. route-registration, Go route kayıt çağrı kalıbı
|
|
148
|
+
// için dürüst addır (C#'taki route-attribute öznitelik kanıtının Go
|
|
149
|
+
// karşılığı değildir); Evidence.kind domain şemasında bilinçli olarak
|
|
150
|
+
// serbest string'dir (packages/domain graph-schema.ts notu).
|
|
151
|
+
const (
|
|
152
|
+
EvidenceKindAstSpan = "ast-span"
|
|
153
|
+
EvidenceKindRouteReg = "route-registration"
|
|
154
|
+
)
|
|
155
|
+
|
|
156
|
+
// nodeKey — kenar uçlarını node kümesine bağlamak ve kenar dedupe için
|
|
157
|
+
// kanonik kimlik (kind + qualifiedName + relativePath).
|
|
158
|
+
func nodeKey(ref NodeRef) string {
|
|
159
|
+
return ref.Kind + "\x00" + ref.QualifiedName + "\x00" + ref.RelativePath
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
func edgeKey(e Edge) string {
|
|
163
|
+
return e.Kind + "\x00" + nodeKey(e.From) + "\x00" + nodeKey(e.To)
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
func evidenceKey(ev Evidence) string {
|
|
167
|
+
bytes, err := json.Marshal(ev)
|
|
168
|
+
if err != nil {
|
|
169
|
+
// struct alanları yalnızca string/int → marshal hata vermez.
|
|
170
|
+
return ""
|
|
171
|
+
}
|
|
172
|
+
return string(bytes)
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
func sortStrings(values []string) {
|
|
176
|
+
sort.Strings(values)
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// round4 — coverageRatio 4 ondalık (Roslyn worker kuralı).
|
|
180
|
+
func round4(ratio float64) float64 {
|
|
181
|
+
return float64(int64(ratio*10000+0.5)) / 10000
|
|
182
|
+
}
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
// routes.go — L3 route kayıt tespiti (M1-Go).
|
|
2
|
+
//
|
|
3
|
+
// Kalıp katmanı (documented heuristic): http.HandleFunc/Handle ve
|
|
4
|
+
// gin/echo/chi benzeri kayıt metot adları (get/post/put/delete/patch/
|
|
5
|
+
// head/options — büyük/küçük harf duyarsız; chi Get gibi). Yanıltıcı
|
|
6
|
+
// pozitifleri kırmak için iki koruma şarttır:
|
|
7
|
+
// 1. ilk argüman string literal VE "/" önekli path,
|
|
8
|
+
// 2. en az iki argüman (path + handler; tek-argümanlı map delete vb. elenir).
|
|
9
|
+
//
|
|
10
|
+
// Tanınan kayıt çağrıları CALLS ÜRETMEZ — semantikleri Endpoint +
|
|
11
|
+
// ROUTES_TO ile tam temsil edilir (PROTOCOL.md). Handle/HandleFunc HTTP
|
|
12
|
+
// fiili taşımadığından Endpoint metodu "*" olur.
|
|
13
|
+
//
|
|
14
|
+
// Handler çözümü: named func (aynı package) → verified; selector →
|
|
15
|
+
// resolution tablosu (heuristic/unresolved); func literal → inline anonim
|
|
16
|
+
// handler: Endpoint KORUNUR, kenar ÜRETİLMEZ + uyarı (Roslyn worker
|
|
17
|
+
// unsupportedConstructs paraleli).
|
|
18
|
+
package analyze
|
|
19
|
+
|
|
20
|
+
import (
|
|
21
|
+
"fmt"
|
|
22
|
+
"go/ast"
|
|
23
|
+
"go/token"
|
|
24
|
+
"strconv"
|
|
25
|
+
"strings"
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
type routeMatch struct {
|
|
29
|
+
verb string
|
|
30
|
+
path string
|
|
31
|
+
handler ast.Expr // Args[1]
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// analysisContext — tek Analyze koşumunun paylaşılan indeksleri ve
|
|
35
|
+
// çıktı toplayıcıları (parametre listesi patlamasın).
|
|
36
|
+
type analysisContext struct {
|
|
37
|
+
fset *token.FileSet
|
|
38
|
+
pkgFuncs map[string]map[string]*funcInfo
|
|
39
|
+
uniquePkg func(string) bool
|
|
40
|
+
methodsByName map[string][]*funcInfo
|
|
41
|
+
ifaceMethods map[string][]string
|
|
42
|
+
addNode func(Node) NodeRef
|
|
43
|
+
addEdge func(Edge)
|
|
44
|
+
warnings *[]string
|
|
45
|
+
declSpan func(*fileCtx, token.Pos, token.Pos) *Span
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// matchRoute — kayıt çağrısı kalıbını tanır; eşleşmezse nil.
|
|
49
|
+
func matchRoute(call *ast.CallExpr) *routeMatch {
|
|
50
|
+
sel, ok := call.Fun.(*ast.SelectorExpr)
|
|
51
|
+
if !ok {
|
|
52
|
+
return nil
|
|
53
|
+
}
|
|
54
|
+
if _, ok := sel.X.(*ast.Ident); !ok {
|
|
55
|
+
return nil
|
|
56
|
+
}
|
|
57
|
+
verb := ""
|
|
58
|
+
switch strings.ToLower(sel.Sel.Name) {
|
|
59
|
+
case "handle", "handlefunc":
|
|
60
|
+
verb = "*"
|
|
61
|
+
case "get":
|
|
62
|
+
verb = "GET"
|
|
63
|
+
case "post":
|
|
64
|
+
verb = "POST"
|
|
65
|
+
case "put":
|
|
66
|
+
verb = "PUT"
|
|
67
|
+
case "delete":
|
|
68
|
+
verb = "DELETE"
|
|
69
|
+
case "patch":
|
|
70
|
+
verb = "PATCH"
|
|
71
|
+
case "head":
|
|
72
|
+
verb = "HEAD"
|
|
73
|
+
case "options":
|
|
74
|
+
verb = "OPTIONS"
|
|
75
|
+
default:
|
|
76
|
+
return nil
|
|
77
|
+
}
|
|
78
|
+
if len(call.Args) < 2 {
|
|
79
|
+
return nil
|
|
80
|
+
}
|
|
81
|
+
lit, ok := call.Args[0].(*ast.BasicLit)
|
|
82
|
+
if !ok || lit.Kind != token.STRING {
|
|
83
|
+
return nil
|
|
84
|
+
}
|
|
85
|
+
path, uerr := strconv.Unquote(lit.Value)
|
|
86
|
+
if uerr != nil || !strings.HasPrefix(path, "/") {
|
|
87
|
+
return nil
|
|
88
|
+
}
|
|
89
|
+
return &routeMatch{verb: verb, path: path, handler: call.Args[1]}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// handleRoute — Endpoint node + (inline değilse) ROUTES_TO kenarı üretir.
|
|
93
|
+
func handleRoute(ctx *analysisContext, fi *funcInfo, match *routeMatch, call *ast.CallExpr) {
|
|
94
|
+
line := ctx.declSpan(fi.file, call.Pos(), call.End()).StartLine
|
|
95
|
+
endpointRef := ctx.addNode(Node{
|
|
96
|
+
Kind: "Endpoint",
|
|
97
|
+
QualifiedName: match.verb + " " + match.path,
|
|
98
|
+
Language: "go",
|
|
99
|
+
RelativePath: fi.file.relativePath,
|
|
100
|
+
Attributes: map[string]any{"method": match.verb, "path": match.path},
|
|
101
|
+
})
|
|
102
|
+
|
|
103
|
+
if _, isLit := match.handler.(*ast.FuncLit); isLit {
|
|
104
|
+
*ctx.warnings = append(*ctx.warnings, fmt.Sprintf(
|
|
105
|
+
"%s: inline anonim route handler '%s %s' (%s:%d) — Endpoint korunur, ROUTES_TO üretilmez",
|
|
106
|
+
AnalyzerID, match.verb, match.path, fi.file.relativePath, line,
|
|
107
|
+
))
|
|
108
|
+
return
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
target := classifyHandler(ctx, fi, match.handler)
|
|
112
|
+
if target == nil {
|
|
113
|
+
*ctx.warnings = append(*ctx.warnings, fmt.Sprintf(
|
|
114
|
+
"%s: '%s %s' route handler'ı çözümlenemedi (%s:%d)",
|
|
115
|
+
AnalyzerID, match.verb, match.path, fi.file.relativePath, line,
|
|
116
|
+
))
|
|
117
|
+
return
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
resolutionText := map[string]string{
|
|
121
|
+
ResolutionVerified: "verified",
|
|
122
|
+
ResolutionHeuristic: "heuristic",
|
|
123
|
+
ResolutionUnresolved: "unresolved",
|
|
124
|
+
}[target.resolution]
|
|
125
|
+
|
|
126
|
+
ctx.addEdge(Edge{
|
|
127
|
+
Kind: EdgeRoutesTo,
|
|
128
|
+
From: endpointRef,
|
|
129
|
+
To: target.ref,
|
|
130
|
+
Resolution: target.resolution,
|
|
131
|
+
Evidence: []Evidence{{
|
|
132
|
+
Kind: EvidenceKindRouteReg,
|
|
133
|
+
Span: ctx.declSpan(fi.file, call.Pos(), call.End()),
|
|
134
|
+
AnalyzerID: AnalyzerID,
|
|
135
|
+
AnalyzerVersion: AnalyzerVersion,
|
|
136
|
+
Rationale: fmt.Sprintf(
|
|
137
|
+
"ROUTES_TO: '%s %s' route kayıt çağrısı (http.HandleFunc / gin-echo-chi kalıbı) %s handler'ına çözümlendi (%s).",
|
|
138
|
+
match.verb, match.path, target.ref.QualifiedName, resolutionText,
|
|
139
|
+
),
|
|
140
|
+
}},
|
|
141
|
+
Ambiguity: target.ambiguity,
|
|
142
|
+
})
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// classifyHandler — route handler ifadesi için resolution tablosu
|
|
146
|
+
// (classifyExpr ile aynı tablo; rationale ROUTES_TO gerekçesidir).
|
|
147
|
+
func classifyHandler(ctx *analysisContext, fi *funcInfo, expr ast.Expr) *callTarget {
|
|
148
|
+
switch h := expr.(type) {
|
|
149
|
+
case *ast.Ident:
|
|
150
|
+
if samePkg, ok := ctx.pkgFuncs[fi.pkg][h.Name]; ok && samePkg.recv == "" {
|
|
151
|
+
return &callTarget{
|
|
152
|
+
ref: NodeRef{Kind: "Function", QualifiedName: samePkg.qname, RelativePath: samePkg.file.relativePath},
|
|
153
|
+
resolution: ResolutionVerified,
|
|
154
|
+
rationale: fmt.Sprintf(
|
|
155
|
+
"ROUTES_TO: %s aynı package içindeki tanımlı handler fonksiyonudur (go/ast, verified).",
|
|
156
|
+
samePkg.qname,
|
|
157
|
+
),
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
return &callTarget{
|
|
161
|
+
ref: NodeRef{Kind: "UnknownExternal", QualifiedName: h.Name},
|
|
162
|
+
resolution: ResolutionUnresolved,
|
|
163
|
+
rationale: fmt.Sprintf(
|
|
164
|
+
"ROUTES_TO: '%s' handler adı hiçbir tanımlı sembolle eşleşmedi (unresolved).",
|
|
165
|
+
h.Name,
|
|
166
|
+
),
|
|
167
|
+
}
|
|
168
|
+
default:
|
|
169
|
+
text := exprText(ctx.fset, fi.file.content, expr)
|
|
170
|
+
target := classifyExpr(fi, expr, ctx.fset, ctx.pkgFuncs, ctx.uniquePkg, ctx.methodsByName, ctx.ifaceMethods)
|
|
171
|
+
if target == nil {
|
|
172
|
+
return nil
|
|
173
|
+
}
|
|
174
|
+
// classifyExpr gerekçesi CALLS odaklıdır; UnknownExternal metnini
|
|
175
|
+
// handler bağlamında da koruyarak döndürür.
|
|
176
|
+
if target.resolution == ResolutionUnresolved && text != "" {
|
|
177
|
+
target.ref = NodeRef{Kind: "UnknownExternal", QualifiedName: text}
|
|
178
|
+
}
|
|
179
|
+
return target
|
|
180
|
+
}
|
|
181
|
+
}
|