kodingo-cli 1.0.7 → 1.0.9
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.
|
@@ -145,41 +145,130 @@ class GitListenerAdapter {
|
|
|
145
145
|
this.lastProcessedCommit = latestCommit.hash;
|
|
146
146
|
}
|
|
147
147
|
/**
|
|
148
|
-
|
|
149
|
-
*
|
|
148
|
+
/**
|
|
149
|
+
* Extract touched function/class/method names from changed files.
|
|
150
|
+
* Supports: JS, TS, JSX, TSX (AST), PHP, Python, Go, Rust, Java, Kotlin, Ruby, C/C++ (regex).
|
|
150
151
|
*/
|
|
151
152
|
extractTouchedSymbols(diffFiles) {
|
|
152
153
|
const symbols = [];
|
|
153
154
|
for (const file of diffFiles) {
|
|
154
155
|
if (file.binary)
|
|
155
156
|
continue;
|
|
156
|
-
const isTsOrJs = file.file.endsWith(".ts") || file.file.endsWith(".js");
|
|
157
|
-
if (!isTsOrJs)
|
|
158
|
-
continue;
|
|
159
157
|
const absFilePath = path_1.default.join(this.repoPath, file.file);
|
|
160
158
|
if (!fs_1.default.existsSync(absFilePath))
|
|
161
159
|
continue;
|
|
162
|
-
const
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
160
|
+
const src = fs_1.default.readFileSync(absFilePath, "utf-8");
|
|
161
|
+
const ext = file.file.split(".").pop()?.toLowerCase() ?? "";
|
|
162
|
+
// JS / TS / JSX / TSX — AST parser
|
|
163
|
+
if (["ts", "tsx", "js", "jsx", "mjs", "cjs"].includes(ext)) {
|
|
164
|
+
try {
|
|
165
|
+
const ast = (0, parser_1.parse)(src, {
|
|
166
|
+
sourceType: "module",
|
|
167
|
+
plugins: ["typescript", "classProperties", "jsx", "decorators-legacy", "classStaticBlock"],
|
|
168
|
+
});
|
|
169
|
+
(0, traverse_1.default)(ast, {
|
|
170
|
+
FunctionDeclaration(p) {
|
|
171
|
+
const name = p?.node?.id?.name;
|
|
172
|
+
if (name)
|
|
173
|
+
symbols.push(`function:${name}`);
|
|
174
|
+
},
|
|
175
|
+
ArrowFunctionExpression(p) {
|
|
176
|
+
const parent = p?.parent;
|
|
177
|
+
if (parent?.type === "VariableDeclarator" && parent?.id?.name) {
|
|
178
|
+
symbols.push(`function:${parent.id.name}`);
|
|
179
|
+
}
|
|
180
|
+
},
|
|
181
|
+
ClassDeclaration(p) {
|
|
182
|
+
const name = p?.node?.id?.name;
|
|
183
|
+
if (name)
|
|
184
|
+
symbols.push(`class:${name}`);
|
|
185
|
+
},
|
|
186
|
+
ClassMethod(p) {
|
|
187
|
+
const name = p?.node?.key?.name;
|
|
188
|
+
if (name && name !== "constructor")
|
|
189
|
+
symbols.push(`method:${name}`);
|
|
190
|
+
},
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
catch {
|
|
194
|
+
for (const m of src.matchAll(/(?:function\s+(\w+)|const\s+(\w+)\s*=\s*(?:async\s*)?\()/g)) {
|
|
195
|
+
const name = m[1] || m[2];
|
|
171
196
|
if (name)
|
|
172
197
|
symbols.push(`function:${name}`);
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
continue;
|
|
201
|
+
}
|
|
202
|
+
// PHP
|
|
203
|
+
if (ext === "php") {
|
|
204
|
+
for (const m of src.matchAll(/(?:function\s+(\w+)\s*\(|class\s+(\w+)(?:\s+extends|\s+implements|\s*\{))/g)) {
|
|
205
|
+
const name = m[1] || m[2];
|
|
206
|
+
if (name)
|
|
207
|
+
symbols.push(m[1] ? `function:${name}` : `class:${name}`);
|
|
208
|
+
}
|
|
209
|
+
continue;
|
|
210
|
+
}
|
|
211
|
+
// Python
|
|
212
|
+
if (ext === "py") {
|
|
213
|
+
for (const m of src.matchAll(/^(?:async\s+)?def\s+(\w+)\s*\(|^class\s+(\w+)/gm)) {
|
|
214
|
+
const name = m[1] || m[2];
|
|
215
|
+
if (name)
|
|
216
|
+
symbols.push(m[1] ? `function:${name}` : `class:${name}`);
|
|
217
|
+
}
|
|
218
|
+
continue;
|
|
219
|
+
}
|
|
220
|
+
// Go
|
|
221
|
+
if (ext === "go") {
|
|
222
|
+
for (const m of src.matchAll(/^func\s+(?:\(\w+\s+\*?\w+\)\s+)?(\w+)\s*\(/gm)) {
|
|
223
|
+
if (m[1])
|
|
224
|
+
symbols.push(`function:${m[1]}`);
|
|
225
|
+
}
|
|
226
|
+
continue;
|
|
180
227
|
}
|
|
181
|
-
|
|
182
|
-
|
|
228
|
+
// Rust
|
|
229
|
+
if (ext === "rs") {
|
|
230
|
+
for (const m of src.matchAll(/^(?:pub\s+)?(?:async\s+)?fn\s+(\w+)|^(?:pub\s+)?struct\s+(\w+)|^(?:pub\s+)?impl\s+(\w+)/gm)) {
|
|
231
|
+
const name = m[1] || m[2] || m[3];
|
|
232
|
+
if (name)
|
|
233
|
+
symbols.push(m[1] ? `function:${name}` : m[2] ? `struct:${name}` : `impl:${name}`);
|
|
234
|
+
}
|
|
235
|
+
continue;
|
|
236
|
+
}
|
|
237
|
+
// Java
|
|
238
|
+
if (ext === "java") {
|
|
239
|
+
for (const m of src.matchAll(/(?:public|private|protected|static|\s)+[\w<>\[\]]+\s+(\w+)\s*\([^)]*\)\s*(?:throws\s+\w+\s*)?\{|(?:public|private|protected)?\s*(?:abstract\s+)?class\s+(\w+)/g)) {
|
|
240
|
+
const name = m[1] || m[2];
|
|
241
|
+
if (name)
|
|
242
|
+
symbols.push(m[1] ? `method:${name}` : `class:${name}`);
|
|
243
|
+
}
|
|
244
|
+
continue;
|
|
245
|
+
}
|
|
246
|
+
// Kotlin
|
|
247
|
+
if (ext === "kt" || ext === "kts") {
|
|
248
|
+
for (const m of src.matchAll(/(?:fun\s+(\w+)\s*\(|class\s+(\w+)|object\s+(\w+))/g)) {
|
|
249
|
+
const name = m[1] || m[2] || m[3];
|
|
250
|
+
if (name)
|
|
251
|
+
symbols.push(m[1] ? `function:${name}` : `class:${name}`);
|
|
252
|
+
}
|
|
253
|
+
continue;
|
|
254
|
+
}
|
|
255
|
+
// Ruby
|
|
256
|
+
if (ext === "rb") {
|
|
257
|
+
for (const m of src.matchAll(/^(?:def\s+(\w+)|class\s+(\w+))/gm)) {
|
|
258
|
+
const name = m[1] || m[2];
|
|
259
|
+
if (name)
|
|
260
|
+
symbols.push(m[1] ? `function:${name}` : `class:${name}`);
|
|
261
|
+
}
|
|
262
|
+
continue;
|
|
263
|
+
}
|
|
264
|
+
// C / C++
|
|
265
|
+
if (["c", "cpp", "cc", "cxx", "h", "hpp"].includes(ext)) {
|
|
266
|
+
for (const m of src.matchAll(/^[\w:*&<>\s]+\s+(\w+)\s*\([^)]*\)\s*(?:const\s*)?\{/gm)) {
|
|
267
|
+
if (m[1] && !["if", "for", "while", "switch", "catch"].includes(m[1])) {
|
|
268
|
+
symbols.push(`function:${m[1]}`);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
continue;
|
|
183
272
|
}
|
|
184
273
|
}
|
|
185
274
|
return Array.from(new Set(symbols));
|
package/dist/commands/init.js
CHANGED
|
@@ -38,10 +38,26 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
38
38
|
return result;
|
|
39
39
|
};
|
|
40
40
|
})();
|
|
41
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
42
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
43
|
+
};
|
|
41
44
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
45
|
exports.registerInitCommand = registerInitCommand;
|
|
43
46
|
const readline = __importStar(require("node:readline"));
|
|
44
47
|
const persistence_config_1 = require("../utils/persistence-config");
|
|
48
|
+
const path_1 = __importDefault(require("path"));
|
|
49
|
+
const fs_1 = __importDefault(require("fs"));
|
|
50
|
+
function findRepoRoot(startPath) {
|
|
51
|
+
let current = startPath;
|
|
52
|
+
while (true) {
|
|
53
|
+
if (fs_1.default.existsSync(path_1.default.join(current, ".git")))
|
|
54
|
+
return current;
|
|
55
|
+
const parent = path_1.default.dirname(current);
|
|
56
|
+
if (parent === current)
|
|
57
|
+
return startPath;
|
|
58
|
+
current = parent;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
45
61
|
// ── Prompt helper ─────────────────────────────────────────────────────────────
|
|
46
62
|
function prompt(rl, question) {
|
|
47
63
|
return new Promise((resolve) => rl.question(question, (ans) => resolve(ans.trim())));
|
|
@@ -119,6 +135,9 @@ function registerInitCommand(program) {
|
|
|
119
135
|
await verifyCloudConnection(apiUrl, token);
|
|
120
136
|
const config = { mode: "cloud", apiUrl, token };
|
|
121
137
|
(0, persistence_config_1.writeConfig)(config);
|
|
138
|
+
// Also save workspace-specific config scoped to this repo
|
|
139
|
+
const repoRoot = findRepoRoot(process.cwd());
|
|
140
|
+
(0, persistence_config_1.writeWorkspaceConfig)(repoRoot, { mode: "cloud", apiUrl, token });
|
|
122
141
|
console.log(`\n✔ Cloud mode configured successfully.`);
|
|
123
142
|
console.log(` API URL : ${apiUrl}`);
|
|
124
143
|
console.log(` Config : ${persistence_config_1.CONFIG_PATH}`);
|
|
@@ -6,6 +6,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.CONFIG_PATH = void 0;
|
|
7
7
|
exports.readConfig = readConfig;
|
|
8
8
|
exports.writeConfig = writeConfig;
|
|
9
|
+
exports.writeWorkspaceConfig = writeWorkspaceConfig;
|
|
10
|
+
exports.readWorkspaceConfig = readWorkspaceConfig;
|
|
9
11
|
exports.isCloudMode = isCloudMode;
|
|
10
12
|
exports.getPersistence = getPersistence;
|
|
11
13
|
/**
|
|
@@ -46,6 +48,16 @@ function writeConfig(config) {
|
|
|
46
48
|
}
|
|
47
49
|
node_fs_1.default.writeFileSync(exports.CONFIG_PATH, JSON.stringify(config, null, 2), "utf-8");
|
|
48
50
|
}
|
|
51
|
+
function writeWorkspaceConfig(repoPath, wsConfig) {
|
|
52
|
+
const existing = readConfig();
|
|
53
|
+
const workspaces = existing.workspaces ?? {};
|
|
54
|
+
workspaces[repoPath] = wsConfig;
|
|
55
|
+
writeConfig({ ...existing, workspaces });
|
|
56
|
+
}
|
|
57
|
+
function readWorkspaceConfig(repoPath) {
|
|
58
|
+
const config = readConfig();
|
|
59
|
+
return config.workspaces?.[repoPath] ?? null;
|
|
60
|
+
}
|
|
49
61
|
function isCloudMode() {
|
|
50
62
|
return readConfig().mode === "cloud";
|
|
51
63
|
}
|