devlensio 1.1.1 → 1.4.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 (64) hide show
  1. package/dist/graph/buildLookup.d.ts +30 -0
  2. package/dist/graph/buildLookup.js +36 -1
  3. package/dist/graph/edges/aliasChain.d.ts +7 -0
  4. package/dist/graph/edges/aliasChain.js +63 -0
  5. package/dist/graph/edges/aliasResolution.test.d.ts +1 -0
  6. package/dist/graph/edges/aliasResolution.test.js +351 -0
  7. package/dist/graph/edges/callEdges.js +178 -18
  8. package/dist/graph/edges/callEdges.test.js +119 -0
  9. package/dist/graph/edges/callOrder.test.d.ts +1 -0
  10. package/dist/graph/edges/callOrder.test.js +227 -0
  11. package/dist/graph/edges/importEdges.js +124 -0
  12. package/dist/graph/edges/propEdges.js +6 -1
  13. package/dist/index.d.ts +1 -0
  14. package/dist/index.js +1 -0
  15. package/dist/parser/callFlow.d.ts +15 -0
  16. package/dist/parser/callFlow.js +302 -0
  17. package/dist/parser/callOrder.test.d.ts +1 -0
  18. package/dist/parser/callOrder.test.js +407 -0
  19. package/dist/parser/declarationIds.d.ts +23 -0
  20. package/dist/parser/declarationIds.js +123 -0
  21. package/dist/parser/exportsMap.js +1 -90
  22. package/dist/parser/extractors/components.js +18 -28
  23. package/dist/parser/extractors/functions.d.ts +21 -1
  24. package/dist/parser/extractors/functions.js +92 -60
  25. package/dist/parser/extractors/moduleScope.d.ts +8 -0
  26. package/dist/parser/extractors/moduleScope.js +80 -0
  27. package/dist/parser/index.js +12 -0
  28. package/dist/parser/moduleScope.test.d.ts +1 -0
  29. package/dist/parser/moduleScope.test.js +176 -0
  30. package/dist/summarizer/index.js +53 -4
  31. package/dist/summarizer/prompts.js +111 -50
  32. package/dist/summarizer/prompts.test.d.ts +1 -0
  33. package/dist/summarizer/prompts.test.js +112 -0
  34. package/dist/types.d.ts +63 -0
  35. package/dist/version.d.ts +1 -0
  36. package/dist/version.js +2 -0
  37. package/extractors/go/bin/darwin-amd64/devlens_go_extractor +0 -0
  38. package/extractors/go/bin/darwin-arm64/devlens_go_extractor +0 -0
  39. package/extractors/go/bin/linux-amd64/devlens_go_extractor +0 -0
  40. package/extractors/go/bin/linux-arm64/devlens_go_extractor +0 -0
  41. package/extractors/go/bin/windows-amd64/devlens_go_extractor.exe +0 -0
  42. package/extractors/go/calls.go +131 -10
  43. package/extractors/go/nodes.go +29 -11
  44. package/extractors/go/parser.go +376 -41
  45. package/extractors/java/devlens_java_extractor.jar +0 -0
  46. package/extractors/java/src/devlens/extractor/Extractor.java +52 -12
  47. package/extractors/java/src/devlens/extractor/LookupMaps.java +2 -0
  48. package/extractors/java/src/devlens/extractor/Parser.java +420 -1
  49. package/extractors/java/src/devlens/extractor/edges/Calls.java +105 -5
  50. package/extractors/python/devlens_extractors_python/edges/calls.py +199 -36
  51. package/extractors/python/devlens_extractors_python/edges/imports.py +21 -1
  52. package/extractors/python/devlens_extractors_python/lookup.py +9 -0
  53. package/extractors/python/devlens_extractors_python/parser/__init__.py +11 -1
  54. package/extractors/python/devlens_extractors_python/parser/functions.py +199 -42
  55. package/extractors/rust/bin/darwin-amd64/devlens_rust_extractor +0 -0
  56. package/extractors/rust/bin/darwin-arm64/devlens_rust_extractor +0 -0
  57. package/extractors/rust/bin/linux-amd64/devlens_rust_extractor +0 -0
  58. package/extractors/rust/bin/linux-arm64/devlens_rust_extractor +0 -0
  59. package/extractors/rust/bin/windows-amd64/devlens_rust_extractor.exe +0 -0
  60. package/extractors/rust/src/calls.rs +114 -8
  61. package/extractors/rust/src/lookup.rs +66 -0
  62. package/extractors/rust/src/nodes.rs +29 -0
  63. package/extractors/rust/src/parser.rs +362 -27
  64. package/package.json +77 -73
@@ -8,7 +8,8 @@
8
8
  // same-package func; alias.member → symbol maps → local method/func or
9
9
  // [mod] lazy member (python's proven chain rule).
10
10
  //
11
- // metadata.calls (sorted unique strings) + metadata.resolvedCalls written on
11
+ // metadata.calls (sorted unique strings) + metadata.callSites (one record per
12
+ // occurrence) + metadata.resolvedCalls (first occurrence per target) written on
12
13
  // every caller node (contract compliance + LLM context).
13
14
 
14
15
  package main
@@ -21,10 +22,68 @@ import (
21
22
  "strings"
22
23
  )
23
24
 
25
+ // resolvedCall — one metadata.resolvedCalls entry, shaped exactly like ResolvedCall
26
+ // in src/types.ts: name is the DECLARATION name the edge points at, firstOrder is
27
+ // the first position that reached it, orders carries the repeat positions.
24
28
  type resolvedCall struct {
25
- Target string `json:"target"`
26
- Method string `json:"method,omitempty"`
27
- Class string `json:"class,omitempty"`
29
+ Name string `json:"name"`
30
+ NodeID string `json:"nodeId"`
31
+ FirstOrder int `json:"firstOrder,omitempty"`
32
+ Line int `json:"line,omitempty"`
33
+ Defer string `json:"defer,omitempty"`
34
+ DeferDetail string `json:"deferDetail,omitempty"`
35
+ Conc bool `json:"conc,omitempty"`
36
+ Repeat bool `json:"repeat,omitempty"`
37
+ Maybe bool `json:"maybe,omitempty"`
38
+ Orders []int `json:"orders,omitempty"`
39
+ }
40
+
41
+ // declaredName — the name of the node the edge points at, falling back to the
42
+ // call-site text when the target is not in the registry (third-party ids).
43
+ func declaredName(l *LookupMaps, target, fallback string) string {
44
+ if n, ok := l.NodeByID[target]; ok {
45
+ if s, ok := n["name"].(string); ok && s != "" {
46
+ return s
47
+ }
48
+ }
49
+ return fallback
50
+ }
51
+
52
+ func newResolvedCall(c CallSite, target, name string) resolvedCall {
53
+ return resolvedCall{
54
+ Name: name, NodeID: target,
55
+ FirstOrder: c.Order, Line: c.Line,
56
+ Defer: c.Defer, DeferDetail: c.DeferDetail,
57
+ Conc: c.Conc, Repeat: c.Repeat, Maybe: c.Maybe,
58
+ }
59
+ }
60
+
61
+ func sortedUniqueInts(in []int) []int {
62
+ seen := map[int]bool{}
63
+ out := make([]int, 0, len(in))
64
+ for _, v := range in {
65
+ if v > 0 && !seen[v] {
66
+ seen[v] = true
67
+ out = append(out, v)
68
+ }
69
+ }
70
+ sort.Ints(out)
71
+ return out
72
+ }
73
+
74
+ // attachRepeatOrders — fill orders[] only when a target was reached more than
75
+ // once, so a renderer never needs the edge mirror for repeated calls.
76
+ func attachRepeatOrders(details []resolvedCall, index map[string]int, orders map[string][]int) {
77
+ for target, list := range orders {
78
+ idx, ok := index[target]
79
+ if !ok {
80
+ continue
81
+ }
82
+ unique := sortedUniqueInts(list)
83
+ if len(unique) > 1 {
84
+ details[idx].Orders = unique
85
+ }
86
+ }
28
87
  }
29
88
 
30
89
  // detectCalls — CALLS edges for every non-test function/method body.
@@ -40,16 +99,26 @@ func detectCalls(pr *parsedRepo, ti *TypeInfo, l *LookupMaps, opts *Options) []m
40
99
  callerID := nodeIDForFunc(pf.RelPath, fn)
41
100
  callStrings := make([]string, 0, len(fn.Calls))
42
101
  var details []resolvedCall
102
+ resolvedIndex := map[string]int{}
103
+ ordersByTarget := map[string][]int{}
43
104
  for _, c := range fn.Calls {
44
105
  callStrings = append(callStrings, c.Str)
45
- target, method, class, e := resolveCall(c, fn, pf, info, l)
106
+ target, _, _, e := resolveCall(c, fn, pf, info, l)
46
107
  if e != nil {
47
108
  edges = append(edges, e)
48
109
  }
49
- if target != "" {
50
- details = append(details, resolvedCall{Target: target, Method: method, Class: class})
110
+ if target == "" {
111
+ continue
112
+ }
113
+ if c.Order > 0 {
114
+ ordersByTarget[target] = append(ordersByTarget[target], c.Order)
115
+ }
116
+ if _, seen := resolvedIndex[target]; !seen {
117
+ resolvedIndex[target] = len(details)
118
+ details = append(details, newResolvedCall(c, target, declaredName(l, target, c.Str)))
51
119
  }
52
120
  }
121
+ attachRepeatOrders(details, resolvedIndex, ordersByTarget)
53
122
  // metadata enrichment on the (already created) caller node
54
123
  if n, ok := l.NodeByID[callerID]; ok {
55
124
  m := n["metadata"].(map[string]any)
@@ -60,6 +129,51 @@ func detectCalls(pr *parsedRepo, ti *TypeInfo, l *LookupMaps, opts *Options) []m
60
129
  }
61
130
  }
62
131
  }
132
+ // ── Module scope: package-level VAR initializers ──
133
+ // These run at init time and belong to the FILE node. Resolution uses the
134
+ // exact same ladder + registry (l.tp) as function callers, so the
135
+ // third-party gate applies identically.
136
+ for _, pf := range pr.files {
137
+ if pf.IsTest || len(pf.FileCalls) == 0 {
138
+ continue
139
+ }
140
+ callerID := "file::" + pf.RelPath
141
+ info := ti.Infos[pf.RelPath]
142
+ callStrings := make([]string, 0, len(pf.FileCalls))
143
+ var details []resolvedCall
144
+ resolvedIndex := map[string]int{}
145
+ ordersByTarget := map[string][]int{}
146
+
147
+ for _, c := range pf.FileCalls {
148
+ callStrings = append(callStrings, c.Str)
149
+ target, _, _, e := resolveCallFor(c, pf.PkgPath, callerID, nil, pf, info, l)
150
+ if e != nil {
151
+ e["metadata"].(map[string]any)["scope"] = "module"
152
+ edges = append(edges, e)
153
+ }
154
+ if target == "" {
155
+ continue
156
+ }
157
+ if c.Order > 0 {
158
+ ordersByTarget[target] = append(ordersByTarget[target], c.Order)
159
+ }
160
+ if _, seen := resolvedIndex[target]; !seen {
161
+ resolvedIndex[target] = len(details)
162
+ details = append(details, newResolvedCall(c, target, declaredName(l, target, c.Str)))
163
+ }
164
+ }
165
+ attachRepeatOrders(details, resolvedIndex, ordersByTarget)
166
+
167
+ if n, ok := l.NodeByID[callerID]; ok {
168
+ m := n["metadata"].(map[string]any)
169
+ m["calls"] = sortedUnique(callStrings)
170
+ m["callSites"] = callSitesMeta(pf.FileCalls)
171
+ if len(details) > 0 {
172
+ m["resolvedCalls"] = details
173
+ }
174
+ }
175
+ }
176
+
63
177
  return edges
64
178
  }
65
179
 
@@ -73,11 +187,18 @@ func nodeIDForFunc(rel string, fn *ParsedFunc) string {
73
187
 
74
188
  // resolveCall → (target node id, method, class, edge) — edge nil when
75
189
  // unresolvable (documented: builtins/locals/dynamic stay metadata-only).
190
+ // resolveCall — function/method caller wrapper. Keeps the ParsedFunc-based
191
+ // call sites untouched while the shared ladder works on a caller identity.
76
192
  func resolveCall(c CallSite, fn *ParsedFunc, pf *ParsedFile, info *types.Info,
77
193
  l *LookupMaps) (string, string, string, map[string]any) {
194
+ return resolveCallFor(c, fn.PkgPath, nodeIDForFunc(pf.RelPath, fn), fn, pf, info, l)
195
+ }
78
196
 
79
- pkgPath := fn.PkgPath
80
- callerID := nodeIDForFunc(pf.RelPath, fn)
197
+ // resolveCallFor — the resolution ladder for any caller identity (FUNCTION,
198
+ // METHOD, or FILE for module-scope VAR initializers).
199
+ func resolveCallFor(c CallSite, pkgPath, callerID string, fn *ParsedFunc,
200
+ pf *ParsedFile, info *types.Info,
201
+ l *LookupMaps) (string, string, string, map[string]any) {
81
202
 
82
203
  // ── 1. type-info resolution (exact) ──
83
204
  if info != nil {
@@ -117,7 +238,7 @@ func resolveCall(c CallSite, fn *ParsedFunc, pf *ParsedFile, info *types.Info,
117
238
  // ── 1.5 receiver-type-from-declaration (params / typed vars) ──
118
239
  // Handlers receive framework types by signature: func(c *gin.Context) —
119
240
  // the checker can't resolve external types, but the DECLARED type can.
120
- if c.IsSel {
241
+ if c.IsSel && fn != nil {
121
242
  if impPath, typeName, local := receiverDeclaredType(c, fn, pf, l); typeName != "" {
122
243
  if local {
123
244
  if id, ok := l.MethodNodeByPkgTypeName[impPath+"::"+typeName+"."+c.Sel]; ok {
@@ -5,8 +5,6 @@
5
5
  package main
6
6
 
7
7
  import (
8
- "strconv"
9
- "strings"
10
8
  "unicode"
11
9
  "unicode/utf8"
12
10
  )
@@ -129,26 +127,46 @@ func nodeTypeForFunc(fn *ParsedFunc) string {
129
127
  return NodeFunction
130
128
  }
131
129
 
132
- // callSitesMeta — structured call-site records from the parse-time facts:
133
- // {name, argCount, argTypes, hasSpread?}. One record per (name, arity,
134
- // argTypes) triple; order follows the AST walk (deterministic).
130
+ // callSitesMeta — structured call-site records from the parse-time facts,
131
+ // ONE RECORD PER OCCURRENCE in source order (docs/CALL_ORDER.md §3.1), so
132
+ // `order` is the owner node's lexical call sequence. De-duplication lives in
133
+ // metadata.calls only (name-only, sorted) — never here.
135
134
  func callSitesMeta(calls []CallSite) []map[string]any {
136
135
  sites := make([]map[string]any, 0, len(calls))
137
- seen := map[string]bool{}
138
136
  for _, c := range calls {
139
- key := c.Str + "/" + strconv.Itoa(c.ArgCount) + "/" + strings.Join(c.ArgTypes, ",")
140
- if seen[key] {
141
- continue
142
- }
143
- seen[key] = true
144
137
  site := map[string]any{
145
138
  "name": c.Str,
146
139
  "argCount": c.ArgCount,
147
140
  "argTypes": c.ArgTypes,
141
+ "order": c.Order,
142
+ "line": c.Line,
143
+ "col": c.Col,
144
+ "scope": c.Scope,
148
145
  }
149
146
  if c.HasSpread {
150
147
  site["hasSpread"] = true
151
148
  }
149
+ if c.Nested > 0 {
150
+ site["nested"] = c.Nested
151
+ }
152
+ if c.Defer != "" {
153
+ site["defer"] = c.Defer
154
+ }
155
+ if c.DeferDetail != "" {
156
+ site["deferDetail"] = c.DeferDetail
157
+ }
158
+ if c.Conc {
159
+ site["conc"] = true
160
+ }
161
+ if c.Repeat {
162
+ site["repeat"] = true
163
+ }
164
+ if c.Maybe {
165
+ site["maybe"] = true
166
+ }
167
+ if c.EarlyExit {
168
+ site["earlyExit"] = true
169
+ }
152
170
  sites = append(sites, site)
153
171
  }
154
172
  return sites