kodingo-cli 1.0.6 → 1.0.8
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/dist/adapters/git-adapter/git-listener.js +112 -23
- package/dist/cli.js +8 -0
- package/dist/commands/aging.js +34 -0
- package/package.json +1 -1
|
@@ -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/cli.js
CHANGED
|
@@ -16,6 +16,7 @@ const init_1 = require("./commands/init");
|
|
|
16
16
|
const install_hook_1 = require("./commands/install-hook");
|
|
17
17
|
const update_1 = require("./commands/update");
|
|
18
18
|
const sync_1 = require("./commands/sync");
|
|
19
|
+
const aging_1 = require("./commands/aging");
|
|
19
20
|
const program = new commander_1.Command();
|
|
20
21
|
program.name("kodingo").description("Kodingo CLI").version("1.0.4");
|
|
21
22
|
// ── init ──────────────────────────────────────────────────────────────────────
|
|
@@ -34,6 +35,13 @@ program
|
|
|
34
35
|
.action(async () => {
|
|
35
36
|
await (0, sync_1.syncCommand)();
|
|
36
37
|
});
|
|
38
|
+
// ── aging ─────────────────────────────────────────────────────────────────────
|
|
39
|
+
program
|
|
40
|
+
.command("aging")
|
|
41
|
+
.description("List stale memory records not updated in 90+ days")
|
|
42
|
+
.action(async () => {
|
|
43
|
+
await (0, aging_1.agingCommand)();
|
|
44
|
+
});
|
|
37
45
|
// ── capture ───────────────────────────────────────────────────────────────────
|
|
38
46
|
program
|
|
39
47
|
.command("capture")
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.agingCommand = agingCommand;
|
|
4
|
+
const persistence_config_1 = require("../utils/persistence-config");
|
|
5
|
+
async function agingCommand() {
|
|
6
|
+
const persistence = (0, persistence_config_1.getPersistence)();
|
|
7
|
+
await persistence.initDb();
|
|
8
|
+
const NINETY_DAYS_MS = 90 * 24 * 60 * 60 * 1000;
|
|
9
|
+
const cutoff = new Date(Date.now() - NINETY_DAYS_MS);
|
|
10
|
+
const results = await persistence.queryMemory("", 200, undefined, {
|
|
11
|
+
includeNonCanonical: true,
|
|
12
|
+
});
|
|
13
|
+
const stale = results.filter((r) => {
|
|
14
|
+
const updated = r.updatedAt instanceof Date ? r.updatedAt : new Date(r.updatedAt);
|
|
15
|
+
return ((r.status === "proposed" || r.status === "ignored") &&
|
|
16
|
+
updated < cutoff);
|
|
17
|
+
});
|
|
18
|
+
if (stale.length === 0) {
|
|
19
|
+
console.log("No stale memories found. Everything is fresh.");
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
console.log(`Found ${stale.length} stale memory record${stale.length === 1 ? "" : "s"} (not updated in 90+ days):\n`);
|
|
23
|
+
for (const r of stale) {
|
|
24
|
+
const updated = r.updatedAt instanceof Date ? r.updatedAt : new Date(r.updatedAt);
|
|
25
|
+
const daysAgo = Math.floor((Date.now() - updated.getTime()) / (1000 * 60 * 60 * 24));
|
|
26
|
+
const title = r.title || r.content.slice(0, 60);
|
|
27
|
+
console.log(` [${r.status.toUpperCase()}] ${title}`);
|
|
28
|
+
console.log(` ID: ${r.id}`);
|
|
29
|
+
console.log(` Symbol: ${r.symbol ?? "none"}`);
|
|
30
|
+
console.log(` Last updated: ${updated.toLocaleDateString()} (${daysAgo} days ago)`);
|
|
31
|
+
console.log(` Run: kodingo deny ${r.id} OR kodingo affirm ${r.id}\n`);
|
|
32
|
+
}
|
|
33
|
+
console.log(`Tip: review these records and affirm, deny, or ignore them to keep your memory base clean.`);
|
|
34
|
+
}
|