Skip to content

Commit d43db4d

Browse files
Remove semantic code intelligence from Python agent
1 parent b67ac36 commit d43db4d

3 files changed

Lines changed: 5 additions & 364 deletions

File tree

‎pkg/code/callgraph.go‎

Lines changed: 0 additions & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,8 @@ import (
55
"context"
66
"encoding/json"
77
"fmt"
8-
"os"
9-
"path/filepath"
10-
"strings"
118

129
basev0 "github.com/codefly-dev/core/generated/go/codefly/base/v0"
13-
codev0 "github.com/codefly-dev/core/generated/go/codefly/services/code/v0"
1410
runners "github.com/codefly-dev/core/runners/base"
1511
)
1612

@@ -176,133 +172,3 @@ print(json.dumps({'calls': calls, 'implements': implements, 'module': workdir}))
176172
result.Module = srcDir
177173
return result
178174
}
179-
180-
// handleFindReferences finds all usages of a symbol via grep + AST.
181-
func (c *Code) handleFindReferences(ctx context.Context, req *codev0.CodeRequest) (*codev0.CodeResponse, error) {
182-
c.EnsureInit()
183-
srcDir := c.SourceDir()
184-
185-
refs := req.GetFindReferences()
186-
if refs == nil {
187-
return &codev0.CodeResponse{
188-
Result: &codev0.CodeResponse_FindReferences{
189-
FindReferences: &codev0.FindReferencesResponse{},
190-
},
191-
}, nil
192-
}
193-
194-
symbolName, err := symbolAtPosition(srcDir, refs.File, refs.Line, refs.Column)
195-
if err != nil || symbolName == "" {
196-
return &codev0.CodeResponse{
197-
Result: &codev0.CodeResponse_FindReferences{
198-
FindReferences: &codev0.FindReferencesResponse{},
199-
},
200-
}, nil
201-
}
202-
203-
locations := c.grepForSymbol(ctx, srcDir, symbolName)
204-
205-
return &codev0.CodeResponse{
206-
Result: &codev0.CodeResponse_FindReferences{
207-
FindReferences: &codev0.FindReferencesResponse{
208-
Locations: locations,
209-
},
210-
},
211-
}, nil
212-
}
213-
214-
func symbolAtPosition(srcDir, file string, line, col int32) (string, error) {
215-
absPath := file
216-
if !filepath.IsAbs(file) {
217-
absPath = filepath.Join(srcDir, file)
218-
}
219-
data, err := os.ReadFile(absPath)
220-
if err != nil {
221-
return "", err
222-
}
223-
lines := strings.Split(string(data), "\n")
224-
if int(line) < 1 || int(line) > len(lines) {
225-
return "", fmt.Errorf("line %d out of range", line)
226-
}
227-
lineText := lines[line-1]
228-
if int(col) < 1 || int(col) > len(lineText) {
229-
col = 1
230-
}
231-
start := int(col) - 1
232-
end := start
233-
for start > 0 && isIdentChar(lineText[start-1]) {
234-
start--
235-
}
236-
for end < len(lineText) && isIdentChar(lineText[end]) {
237-
end++
238-
}
239-
if start >= end {
240-
return "", nil
241-
}
242-
return lineText[start:end], nil
243-
}
244-
245-
func isIdentChar(c byte) bool {
246-
return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '_'
247-
}
248-
249-
func (c *Code) grepForSymbol(ctx context.Context, srcDir, symbol string) []*codev0.Location {
250-
// Route grep through the plugin's active RunnerEnvironment so a
251-
// Docker-mode Python agent searches its own mounted tree. Pre-Init
252-
// uses ResolveStandaloneEnvironment which honors declared context.
253-
env := c.Service.ActiveEnv
254-
if env == nil {
255-
var rctx *basev0.RuntimeContext
256-
if c.Service.Base != nil && c.Service.Base.Runtime != nil {
257-
rctx = c.Service.Base.Runtime.RuntimeContext
258-
}
259-
env = runners.ResolveStandaloneEnvironment(ctx, srcDir, rctx)
260-
}
261-
proc, procErr := env.NewProcess("grep", "-rn", "--include=*.py", "-w", symbol, srcDir)
262-
if procErr != nil {
263-
return nil
264-
}
265-
var buf bytes.Buffer
266-
proc.WithOutput(&buf)
267-
_ = proc.Run(ctx) // grep returns non-zero on no match; that's fine
268-
out := buf.Bytes()
269-
270-
var locations []*codev0.Location
271-
for _, line := range strings.Split(string(out), "\n") {
272-
line = strings.TrimSpace(line)
273-
if line == "" {
274-
continue
275-
}
276-
parts := strings.SplitN(line, ":", 3)
277-
if len(parts) < 2 {
278-
continue
279-
}
280-
filePath := parts[0]
281-
relPath, _ := filepath.Rel(srcDir, filePath)
282-
if relPath == "" {
283-
relPath = filePath
284-
}
285-
286-
lineNum := int32(0)
287-
fmt.Sscanf(parts[1], "%d", &lineNum)
288-
289-
col := int32(1)
290-
if len(parts) >= 3 {
291-
idx := strings.Index(parts[2], symbol)
292-
if idx >= 0 {
293-
col = int32(idx + 1)
294-
}
295-
}
296-
297-
locations = append(locations, &codev0.Location{
298-
File: relPath,
299-
Line: lineNum,
300-
Column: col,
301-
})
302-
303-
if len(locations) >= 100 {
304-
break
305-
}
306-
}
307-
return locations
308-
}

‎pkg/code/code.go‎

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,8 @@ import (
1717
// It embeds PythonCodeServer from core, which provides:
1818
// - File ops: ReadFile, WriteFile, CreateFile, DeleteFile, MoveFile, ListFiles, Search
1919
// - Git ops: GitLog, GitDiff, GitShow, GitBlame
20-
// - Analysis: ListSymbols (AST), GetProjectInfo, ListDependencies
20+
// - Analysis: GetProjectInfo, ListDependencies
2121
// - Smart edit: ApplyEdit (fuzzy find/replace)
22-
//
23-
// Python-specific overrides added here:
24-
// - find_references: grep + AST-based symbol reference finding
25-
// - get_call_graph: served via Tooling gRPC (Tooling.GetCallGraph) —
26-
// the Execute Override path does NOT work for get_call_graph.
2722
type Code struct {
2823
*corecode.PythonCodeServer
2924
Service *pythonservice.Service
@@ -39,7 +34,6 @@ func New(svc *pythonservice.Service) *Code {
3934
Service: svc,
4035
PythonCodeServer: corecode.NewPythonCodeServer(".", nil),
4136
}
42-
c.registerOverrides()
4337
return c
4438
}
4539

@@ -61,30 +55,17 @@ func (c *Code) SourceDir() string {
6155
func (c *Code) EnsureInit() {
6256
if !c.initialized {
6357
c.PythonCodeServer = corecode.NewPythonCodeServer(c.SourceDir(), nil)
64-
c.registerOverrides()
6558
c.initialized = true
6659
}
6760
}
6861

69-
// registerOverrides wires Python-specific handlers on top of PythonCodeServer.
70-
// PythonCodeServer already provides: list_symbols (AST), get_project_info, list_dependencies.
71-
// Specializations may add their own via c.Override(...) after constructing.
72-
func (c *Code) registerOverrides() {
73-
c.Override("find_references", c.handleFindReferences)
74-
}
75-
7662
// ── Lazy-init RPC wrappers ───────────────────────────────
7763

7864
func (c *Code) GetProjectInfo(ctx context.Context, req *codev0.GetProjectInfoRequest) (*codev0.GetProjectInfoResponse, error) {
7965
c.EnsureInit()
8066
return c.PythonCodeServer.GetProjectInfo(ctx, req)
8167
}
8268

83-
func (c *Code) ListSymbols(ctx context.Context, req *codev0.ListSymbolsRequest) (*codev0.ListSymbolsResponse, error) {
84-
c.EnsureInit()
85-
return c.PythonCodeServer.ListSymbols(ctx, req)
86-
}
87-
8869
func (c *Code) ListDependencies(ctx context.Context, req *codev0.ListDependenciesRequest) (*codev0.ListDependenciesResponse, error) {
8970
c.EnsureInit()
9071
return c.PythonCodeServer.ListDependencies(ctx, req)

0 commit comments

Comments
 (0)