deepdebug-local-agent 0.3.1
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/.dockerignore +24 -0
- package/.idea/deepdebug-local-agent.iml +12 -0
- package/.idea/modules.xml +8 -0
- package/.idea/vcs.xml +6 -0
- package/Dockerfile +46 -0
- package/cloudbuild.yaml +42 -0
- package/index.js +42 -0
- package/mcp-server.js +533 -0
- package/package.json +22 -0
- package/src/ai-engine.js +861 -0
- package/src/analyzers/config-analyzer.js +446 -0
- package/src/analyzers/controller-analyzer.js +429 -0
- package/src/analyzers/dto-analyzer.js +455 -0
- package/src/detectors/build-tool-detector.js +0 -0
- package/src/detectors/framework-detector.js +91 -0
- package/src/detectors/language-detector.js +89 -0
- package/src/detectors/multi-project-detector.js +191 -0
- package/src/detectors/service-detector.js +244 -0
- package/src/detectors.js +30 -0
- package/src/exec-utils.js +215 -0
- package/src/fs-utils.js +34 -0
- package/src/git/base-git-provider.js +384 -0
- package/src/git/git-provider-registry.js +110 -0
- package/src/git/github-provider.js +502 -0
- package/src/mcp-http-server.js +313 -0
- package/src/patch/patch-engine.js +339 -0
- package/src/patch-manager.js +816 -0
- package/src/patch.js +607 -0
- package/src/patch_bkp.js +154 -0
- package/src/ports.js +69 -0
- package/src/routes/workspace.route.js +528 -0
- package/src/runtimes/base-runtime.js +290 -0
- package/src/runtimes/java/gradle-runtime.js +378 -0
- package/src/runtimes/java/java-integrations.js +339 -0
- package/src/runtimes/java/maven-runtime.js +418 -0
- package/src/runtimes/node/node-integrations.js +247 -0
- package/src/runtimes/node/npm-runtime.js +466 -0
- package/src/runtimes/node/yarn-runtime.js +354 -0
- package/src/runtimes/runtime-registry.js +256 -0
- package/src/server-local.js +576 -0
- package/src/server.js +4565 -0
- package/src/utils/environment-diagnostics.js +666 -0
- package/src/utils/exec-utils.js +264 -0
- package/src/utils/fs-utils.js +218 -0
- package/src/workspace/detect-port.js +176 -0
- package/src/workspace/file-reader.js +54 -0
- package/src/workspace/git-client.js +0 -0
- package/src/workspace/process-manager.js +619 -0
- package/src/workspace/scanner.js +72 -0
- package/src/workspace-manager.js +172 -0
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import { exists, listRecursive, readFile, stat } from "./fs-utils.js";
|
|
3
|
+
import { detectProject } from "./detectors.js";
|
|
4
|
+
import { detectPort } from "./ports.js";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* WorkspaceManager — Gere múltiplos workspaces simultâneos.
|
|
8
|
+
*
|
|
9
|
+
* Substitui a variável global WORKSPACE_ROOT.
|
|
10
|
+
* Cada workspace é identificado por um ID e tem o seu próprio root path.
|
|
11
|
+
*/
|
|
12
|
+
export class WorkspaceManager {
|
|
13
|
+
constructor() {
|
|
14
|
+
/** @type {Map<string, WorkspaceState>} */
|
|
15
|
+
this.workspaces = new Map();
|
|
16
|
+
|
|
17
|
+
/** Backward compat: workspace "default" para REST legacy */
|
|
18
|
+
this.defaultWorkspaceId = null;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Abre um workspace. Se já existe com mesmo ID, actualiza o root.
|
|
23
|
+
* @param {string} workspaceId - Identificador único
|
|
24
|
+
* @param {string} rootPath - Caminho absoluto
|
|
25
|
+
* @returns {Promise<WorkspaceState>}
|
|
26
|
+
*/
|
|
27
|
+
async open(workspaceId, rootPath) {
|
|
28
|
+
const abs = path.resolve(rootPath);
|
|
29
|
+
if (!(await exists(abs))) {
|
|
30
|
+
throw new Error(`Workspace path not found: ${abs}`);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const projectInfo = await detectProject(abs);
|
|
34
|
+
const port = await detectPort(abs);
|
|
35
|
+
|
|
36
|
+
const state = {
|
|
37
|
+
id: workspaceId,
|
|
38
|
+
root: abs,
|
|
39
|
+
projectInfo,
|
|
40
|
+
port,
|
|
41
|
+
openedAt: new Date().toISOString(),
|
|
42
|
+
lastAccessedAt: new Date().toISOString(),
|
|
43
|
+
status: "open"
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
this.workspaces.set(workspaceId, state);
|
|
47
|
+
|
|
48
|
+
// Se é o primeiro workspace, torna-se o default
|
|
49
|
+
if (!this.defaultWorkspaceId) {
|
|
50
|
+
this.defaultWorkspaceId = workspaceId;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
console.log(`📂 Workspace opened: ${workspaceId} → ${abs} (${projectInfo.language}/${projectInfo.buildTool})`);
|
|
54
|
+
return state;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Fecha um workspace.
|
|
59
|
+
*/
|
|
60
|
+
close(workspaceId) {
|
|
61
|
+
const ws = this.workspaces.get(workspaceId);
|
|
62
|
+
if (!ws) return false;
|
|
63
|
+
|
|
64
|
+
this.workspaces.delete(workspaceId);
|
|
65
|
+
|
|
66
|
+
if (this.defaultWorkspaceId === workspaceId) {
|
|
67
|
+
// Eleger novo default
|
|
68
|
+
const first = this.workspaces.keys().next().value;
|
|
69
|
+
this.defaultWorkspaceId = first || null;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
console.log(`📁 Workspace closed: ${workspaceId}`);
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Obtém estado de um workspace. Actualiza lastAccessedAt.
|
|
78
|
+
* @param {string} workspaceId
|
|
79
|
+
* @returns {WorkspaceState|null}
|
|
80
|
+
*/
|
|
81
|
+
get(workspaceId) {
|
|
82
|
+
const ws = this.workspaces.get(workspaceId);
|
|
83
|
+
if (ws) {
|
|
84
|
+
ws.lastAccessedAt = new Date().toISOString();
|
|
85
|
+
}
|
|
86
|
+
return ws || null;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Obtém o root path de um workspace. Throw se não existe.
|
|
91
|
+
* @param {string} workspaceId
|
|
92
|
+
* @returns {string}
|
|
93
|
+
*/
|
|
94
|
+
getRoot(workspaceId) {
|
|
95
|
+
const ws = this.get(workspaceId);
|
|
96
|
+
if (!ws) throw new Error(`Workspace not found: ${workspaceId}`);
|
|
97
|
+
return ws.root;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Resolve workspace ID — se null, usa o default.
|
|
102
|
+
* Backward compat para REST endpoints que não enviam workspaceId.
|
|
103
|
+
*/
|
|
104
|
+
resolveId(workspaceId) {
|
|
105
|
+
if (workspaceId) return workspaceId;
|
|
106
|
+
if (this.defaultWorkspaceId) return this.defaultWorkspaceId;
|
|
107
|
+
throw new Error("No workspace open. Call /workspace/open first.");
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Resolve root path — aceita workspaceId ou usa default.
|
|
112
|
+
*/
|
|
113
|
+
resolveRoot(workspaceId) {
|
|
114
|
+
const id = this.resolveId(workspaceId);
|
|
115
|
+
return this.getRoot(id);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Lista todos os workspaces abertos.
|
|
120
|
+
*/
|
|
121
|
+
list() {
|
|
122
|
+
return Array.from(this.workspaces.values());
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Verifica se workspace está aberto.
|
|
127
|
+
*/
|
|
128
|
+
isOpen(workspaceId) {
|
|
129
|
+
return this.workspaces.has(workspaceId);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Total de workspaces abertos.
|
|
134
|
+
*/
|
|
135
|
+
get count() {
|
|
136
|
+
return this.workspaces.size;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Backward compat: obtém WORKSPACE_ROOT (default workspace).
|
|
141
|
+
* Usado pelos endpoints REST legacy.
|
|
142
|
+
*/
|
|
143
|
+
get defaultRoot() {
|
|
144
|
+
if (!this.defaultWorkspaceId) return null;
|
|
145
|
+
const ws = this.workspaces.get(this.defaultWorkspaceId);
|
|
146
|
+
return ws ? ws.root : null;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Backward compat: define WORKSPACE_ROOT (default workspace).
|
|
151
|
+
* Chamado pelo POST /workspace/open legacy.
|
|
152
|
+
*/
|
|
153
|
+
async setDefault(rootPath) {
|
|
154
|
+
const id = `default-${Date.now()}`;
|
|
155
|
+
// Se já tem default, reutiliza o ID
|
|
156
|
+
const existingId = this.defaultWorkspaceId || id;
|
|
157
|
+
await this.open(existingId, rootPath);
|
|
158
|
+
this.defaultWorkspaceId = existingId;
|
|
159
|
+
return this.get(existingId);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* @typedef {Object} WorkspaceState
|
|
165
|
+
* @property {string} id
|
|
166
|
+
* @property {string} root
|
|
167
|
+
* @property {Object} projectInfo
|
|
168
|
+
* @property {number|null} port
|
|
169
|
+
* @property {string} openedAt
|
|
170
|
+
* @property {string} lastAccessedAt
|
|
171
|
+
* @property {string} status
|
|
172
|
+
*/
|