kodingo-cli 1.3.5 → 1.4.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/dist/__tests__/branchSettlement.test.js +295 -0
- package/dist/__tests__/deepScanConsentOrdering.test.js +113 -0
- package/dist/__tests__/deepScanHookBranchGate.test.js +136 -0
- package/dist/__tests__/deepScanLocal.test.js +147 -0
- package/dist/__tests__/deepScanNetworkFlows.test.js +154 -0
- package/dist/__tests__/initCoverageShortcut.test.js +54 -0
- package/dist/__tests__/installHook.test.js +62 -0
- package/dist/__tests__/pollAndOutcome.test.js +89 -0
- package/dist/__tests__/repo-identity.test.js +32 -0
- package/dist/__tests__/settleAlreadyCompleteProject.test.js +353 -0
- package/dist/__tests__/versionPolicy.test.js +13 -0
- package/dist/bootstrap.js +74 -0
- package/dist/cli.js +22 -7
- package/dist/commands/deep-scan-process.js +22 -0
- package/dist/commands/deep-scan-worker.js +19 -0
- package/dist/commands/deep-scan.js +878 -0
- package/dist/commands/init.js +119 -27
- package/dist/commands/install-hook.js +23 -6
- package/dist/commands/update.js +18 -6
- package/dist/utils/local-deep-scan-extractor.js +21 -0
- package/dist/utils/repo-identity.js +23 -9
- package/dist/utils/vendoredCodeDetector.js +16 -143
- package/dist/utils/version-policy.js +44 -0
- package/package.json +3 -3
- package/dist/test-buildgraph-debug.js +0 -10
- package/dist/test-calls-debug.js +0 -16
package/dist/commands/init.js
CHANGED
|
@@ -42,6 +42,8 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
42
42
|
};
|
|
43
43
|
})();
|
|
44
44
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
|
+
exports.checkoutCoverageComplete = checkoutCoverageComplete;
|
|
46
|
+
exports.shouldSkipLocalScan = shouldSkipLocalScan;
|
|
45
47
|
exports.registerInitCommand = registerInitCommand;
|
|
46
48
|
const readline = __importStar(require("node:readline"));
|
|
47
49
|
const fs = __importStar(require("fs"));
|
|
@@ -179,14 +181,56 @@ async function createProject(authToken, name, orgId) {
|
|
|
179
181
|
throw new Error(data.error ?? "Failed to create project");
|
|
180
182
|
return data;
|
|
181
183
|
}
|
|
184
|
+
/**
|
|
185
|
+
* The product rule: a project whose read is complete — from ANY source,
|
|
186
|
+
* GitHub or a local scan — does not need another local scan. Completeness
|
|
187
|
+
* is the test, not the commit or the source: this used to also require
|
|
188
|
+
* `status.lastCommit === metadata.commitSha`, which meant the shortcut only
|
|
189
|
+
* ever fired for the EXACT commit a prior scan (of either source) happened
|
|
190
|
+
* to run against — in practice almost never true for a new engineer's
|
|
191
|
+
* checkout, since a GitHub-sourced "complete" project updates its recorded
|
|
192
|
+
* commit on its own schedule (see utils/entityScanScheduler.ts's hourly
|
|
193
|
+
* github_light_backup rows), not this engineer's.
|
|
194
|
+
*
|
|
195
|
+
* `alreadyRegistered` guards the one real risk of dropping the commit
|
|
196
|
+
* check: a multi-repo project where /deep-scan/status's completeness is a
|
|
197
|
+
* PROJECT-wide aggregate, not scoped to any one repo. Only when this
|
|
198
|
+
* checkout's repo was already a genuinely registered repo of the project
|
|
199
|
+
* (not one this very call is registering for the first time) does that
|
|
200
|
+
* aggregate completeness legitimately describe THIS checkout.
|
|
201
|
+
*/
|
|
202
|
+
async function checkoutCoverageComplete(apiUrl, token, alreadyRegistered) {
|
|
203
|
+
if (!alreadyRegistered)
|
|
204
|
+
return false;
|
|
205
|
+
try {
|
|
206
|
+
const response = await fetch(`${apiUrl.replace(/\/$/, "")}/deep-scan/status`, { headers: { "X-Kodingo-Token": token } });
|
|
207
|
+
if (!response.ok)
|
|
208
|
+
return false;
|
|
209
|
+
const status = await response.json();
|
|
210
|
+
return status.state === "complete";
|
|
211
|
+
}
|
|
212
|
+
catch {
|
|
213
|
+
return false;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
/** Pure so --force's override of an otherwise-complete project is directly
|
|
217
|
+
* unit-testable without driving the whole interactive/CI init flow. */
|
|
218
|
+
function shouldSkipLocalScan(force, dryRun, coverageComplete) {
|
|
219
|
+
return !force && !dryRun && coverageComplete;
|
|
220
|
+
}
|
|
182
221
|
// ── Command ───────────────────────────────────────────────────────────────────
|
|
183
222
|
function registerInitCommand(program) {
|
|
184
223
|
program
|
|
185
224
|
.command("init")
|
|
186
|
-
.description("Connect this repository
|
|
225
|
+
.description("Connect this repository, run the first local deep scan, and install incremental capture")
|
|
187
226
|
.option("--logout", "Log out and clear saved credentials")
|
|
227
|
+
.option("--yes", "non-interactive consent (use KODINGO_TOKEN in CI)")
|
|
228
|
+
.option("--dry-run <file>", "write the exact deep-scan payload without uploading")
|
|
229
|
+
.option("--force", "run the full local scan even if Kortex already has complete coverage of this project")
|
|
230
|
+
.option("--verbose", "print the inputs behind each held-scan reconciliation decision (same as KODINGO_DEBUG=1)")
|
|
188
231
|
.action(async (opts) => {
|
|
189
232
|
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
233
|
+
const verbose = Boolean(opts.verbose) || process.env.KODINGO_DEBUG === "1";
|
|
190
234
|
try {
|
|
191
235
|
// ── Logout ──────────────────────────────────────────────────────────
|
|
192
236
|
if (opts.logout) {
|
|
@@ -195,6 +239,36 @@ function registerInitCommand(program) {
|
|
|
195
239
|
console.log("✔ Logged out of Kodingo.");
|
|
196
240
|
return;
|
|
197
241
|
}
|
|
242
|
+
// CI/non-interactive first run: the project-scoped token is already
|
|
243
|
+
// the project match. No browser or project-name prompt is needed.
|
|
244
|
+
const environmentToken = process.env.KODINGO_TOKEN?.trim();
|
|
245
|
+
if (environmentToken) {
|
|
246
|
+
const repoRoot = findRepoRoot(process.cwd());
|
|
247
|
+
const apiUrl = process.env.KODINGO_API_URL?.trim() || API_BASE;
|
|
248
|
+
const existingConfig = (0, persistence_config_1.readConfig)();
|
|
249
|
+
(0, persistence_config_1.writeConfig)({ ...existingConfig, mode: "cloud", apiUrl, machineId: getMachineId() });
|
|
250
|
+
(0, persistence_config_1.writeWorkspaceConfig)(repoRoot, { mode: "cloud", apiUrl, token: environmentToken });
|
|
251
|
+
ensureGitignoreEntry(repoRoot, ".kortex/");
|
|
252
|
+
const registration = await (0, repo_identity_1.resolveRepoRegistration)({ repoRoot, apiUrl, token: environmentToken });
|
|
253
|
+
const coverageComplete = (!opts.force && !opts.dryRun) ? await checkoutCoverageComplete(apiUrl, environmentToken, registration.alreadyRegistered) : false;
|
|
254
|
+
const alreadyComplete = shouldSkipLocalScan(opts.force, opts.dryRun, coverageComplete);
|
|
255
|
+
const { deepScanCommand, settleAndReconcile, settleAlreadyCompleteProject, resolveGitMetadata, deriveBareRepoName } = await Promise.resolve().then(() => __importStar(require("./deep-scan")));
|
|
256
|
+
if (alreadyComplete) {
|
|
257
|
+
const meta = resolveGitMetadata(repoRoot);
|
|
258
|
+
await settleAlreadyCompleteProject({
|
|
259
|
+
apiUrl, token: environmentToken, root: repoRoot, branch: meta.branch, detachedHead: meta.detachedHead,
|
|
260
|
+
repository: meta.repository, repositoryName: deriveBareRepoName(meta.repository), yes: true, verbose,
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
else {
|
|
264
|
+
const handled = opts.dryRun
|
|
265
|
+
? false
|
|
266
|
+
: (await settleAndReconcile({ apiUrl, token: environmentToken, root: repoRoot, yes: true })).handled;
|
|
267
|
+
if (!handled)
|
|
268
|
+
await deepScanCommand({ repo: repoRoot, yes: true, dryRun: opts.dryRun, noUpdate: true });
|
|
269
|
+
}
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
198
272
|
// ── Check if already logged in ───────────────────────────────────────
|
|
199
273
|
let authToken = readAuthToken();
|
|
200
274
|
let email = readAuthEmail();
|
|
@@ -277,9 +351,13 @@ function registerInitCommand(program) {
|
|
|
277
351
|
// contamination — resolved from the git remote (stable across
|
|
278
352
|
// machines and folder names), not the local folder name itself,
|
|
279
353
|
// so the registration this creates is trustworthy for every future
|
|
280
|
-
// scan to resolve against.
|
|
354
|
+
// scan to resolve against. Its result also tells us whether this
|
|
355
|
+
// checkout's repo was ALREADY registered — the gate the
|
|
356
|
+
// complete-coverage shortcut below needs (see
|
|
357
|
+
// checkoutCoverageComplete's own comment for why).
|
|
358
|
+
let registration = { repoName: "", alreadyRegistered: false };
|
|
281
359
|
try {
|
|
282
|
-
await (0, repo_identity_1.
|
|
360
|
+
registration = await (0, repo_identity_1.resolveRepoRegistration)({
|
|
283
361
|
repoRoot,
|
|
284
362
|
apiUrl,
|
|
285
363
|
token: selectedProject.token,
|
|
@@ -287,35 +365,49 @@ function registerInitCommand(program) {
|
|
|
287
365
|
}
|
|
288
366
|
catch { }
|
|
289
367
|
console.log(`✔ Connected. Token saved to ${persistence_config_1.CONFIG_PATH}`);
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
368
|
+
const coverageComplete = (!opts.force && !opts.dryRun) ? await checkoutCoverageComplete(apiUrl, selectedProject.token, registration.alreadyRegistered) : false;
|
|
369
|
+
const alreadyComplete = shouldSkipLocalScan(opts.force, opts.dryRun, coverageComplete);
|
|
370
|
+
if (!alreadyComplete)
|
|
371
|
+
console.log("\nKortex will now read this checkout locally. Review the upload summary before consenting.");
|
|
372
|
+
// The local deep scan is the one first-read path. The retired
|
|
373
|
+
// scan-repo capture is deliberately not run here.
|
|
374
|
+
const { deepScanCommand, settleAndReconcile, settleAlreadyCompleteProject, resolveGitMetadata, deriveBareRepoName } = await Promise.resolve().then(() => __importStar(require("./deep-scan")));
|
|
375
|
+
if (alreadyComplete) {
|
|
376
|
+
try {
|
|
377
|
+
const meta = resolveGitMetadata(repoRoot);
|
|
378
|
+
await settleAlreadyCompleteProject({
|
|
379
|
+
apiUrl, token: selectedProject.token, root: repoRoot, branch: meta.branch, detachedHead: meta.detachedHead,
|
|
380
|
+
repository: meta.repository, repositoryName: deriveBareRepoName(meta.repository), yes: Boolean(opts.yes), verbose,
|
|
381
|
+
});
|
|
382
|
+
}
|
|
383
|
+
catch (err) {
|
|
384
|
+
throw new Error(`Tracked-branch settlement failed: ${err.message}`);
|
|
385
|
+
}
|
|
298
386
|
}
|
|
299
|
-
|
|
300
|
-
|
|
387
|
+
else {
|
|
388
|
+
try {
|
|
389
|
+
// Settle the tracked branch — and reconcile any already-held scan
|
|
390
|
+
// for this exact commit — before uploading anything, so a first
|
|
391
|
+
// scan can apply instead of silently landing held.
|
|
392
|
+
const handled = opts.dryRun
|
|
393
|
+
? false
|
|
394
|
+
: (await settleAndReconcile({ apiUrl, token: selectedProject.token, root: repoRoot, yes: Boolean(opts.yes) })).handled;
|
|
395
|
+
if (!handled)
|
|
396
|
+
await deepScanCommand({ repo: repoRoot, yes: Boolean(opts.yes), dryRun: opts.dryRun });
|
|
397
|
+
}
|
|
398
|
+
catch (err) {
|
|
399
|
+
throw new Error(`Initial deep scan failed: ${err.message}`);
|
|
400
|
+
}
|
|
301
401
|
}
|
|
302
|
-
//
|
|
303
|
-
// rather than waiting for the next commit to trigger the hook.
|
|
402
|
+
// Install only after the user has reviewed/accepted the first scan.
|
|
304
403
|
try {
|
|
305
|
-
const {
|
|
306
|
-
await
|
|
404
|
+
const { installHookCommand } = await Promise.resolve().then(() => __importStar(require("./install-hook")));
|
|
405
|
+
const installed = await installHookCommand({ repo: repoRoot });
|
|
406
|
+
console.log(installed ? "✔ Incremental commit hook installed.\n" : "✔ Incremental commit hook already installed.\n");
|
|
307
407
|
}
|
|
308
|
-
catch {
|
|
309
|
-
|
|
310
|
-
try {
|
|
311
|
-
const { scanRepoCommand } = await Promise.resolve().then(() => __importStar(require("./scan-repo")));
|
|
312
|
-
console.log("🔍 Scanning existing codebase for functions without memory...");
|
|
313
|
-
const captured = await scanRepoCommand({ repo: repoRoot, silent: false });
|
|
314
|
-
if (captured === 0) {
|
|
315
|
-
console.log(" No existing functions found — Kortex will capture them as you write and commit code.");
|
|
316
|
-
}
|
|
408
|
+
catch (err) {
|
|
409
|
+
console.log(`⚠ Could not install the hook (${err.message}). Run \`kodingo install-hook\` later.\n`);
|
|
317
410
|
}
|
|
318
|
-
catch { }
|
|
319
411
|
}
|
|
320
412
|
catch (err) {
|
|
321
413
|
console.error(`\n✖ ${err.message}`);
|
|
@@ -6,6 +6,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.installHookCommand = installHookCommand;
|
|
7
7
|
const fs_1 = __importDefault(require("fs"));
|
|
8
8
|
const path_1 = __importDefault(require("path"));
|
|
9
|
+
/** Returns true when a hook block was newly installed, false when one was
|
|
10
|
+
* already present (nothing written). Callers decide what to print — this
|
|
11
|
+
* used to print its own "Hook already installed"/"Kodingo hook installed"
|
|
12
|
+
* line unconditionally, which `kodingo init` then followed with its own
|
|
13
|
+
* "Incremental commit hook installed" regardless of which case this was,
|
|
14
|
+
* producing a contradictory pair of lines on a repeat `init`. */
|
|
9
15
|
async function installHookCommand(options) {
|
|
10
16
|
const repoRoot = resolveRepoRoot(options);
|
|
11
17
|
const hooksDir = path_1.default.join(repoRoot, ".git", "hooks");
|
|
@@ -16,10 +22,22 @@ async function installHookCommand(options) {
|
|
|
16
22
|
const hookPath = path_1.default.join(hooksDir, "post-commit");
|
|
17
23
|
const hookBlock = [
|
|
18
24
|
"# <kodingo>",
|
|
19
|
-
"# Kodingo: auto-infer decision memory from git commits",
|
|
20
|
-
|
|
25
|
+
"# Kodingo: auto-infer decision memory from git commits — backgrounded and",
|
|
26
|
+
"# silenced so a failure here is never visible on (or blocks) the commit.",
|
|
27
|
+
`"${kodingoBin}" scan-git --repo "$(git rev-parse --show-toplevel)" >/dev/null 2>&1 &`,
|
|
21
28
|
"# Kodingo Security: keep dependency data current for vulnerability scanning",
|
|
22
|
-
`"${kodingoBin}" sync-dependencies --repo "$(git rev-parse --show-toplevel)" &`,
|
|
29
|
+
`"${kodingoBin}" sync-dependencies --repo "$(git rev-parse --show-toplevel)" >/dev/null 2>&1 &`,
|
|
30
|
+
"# Kortex Deep Scan: extract only the committed files locally; never block the",
|
|
31
|
+
"# commit. A portable watchdog (sleep+kill) enforces the timeout regardless of",
|
|
32
|
+
"# whether the GNU `timeout` binary is installed on this machine.",
|
|
33
|
+
"(",
|
|
34
|
+
` "${kodingoBin}" deep-scan --repo "$(git rev-parse --show-toplevel)" --changed --yes --no-update >/dev/null 2>&1 &`,
|
|
35
|
+
" kodingo_scan_pid=$!",
|
|
36
|
+
" ( sleep 120; kill -9 \"$kodingo_scan_pid\" ) >/dev/null 2>&1 &",
|
|
37
|
+
" kodingo_watchdog_pid=$!",
|
|
38
|
+
" wait \"$kodingo_scan_pid\" >/dev/null 2>&1",
|
|
39
|
+
" kill \"$kodingo_watchdog_pid\" >/dev/null 2>&1",
|
|
40
|
+
") &",
|
|
23
41
|
"# </kodingo>",
|
|
24
42
|
].join("\n");
|
|
25
43
|
// Pre-commit hook — runs synchronously to enforce guardrails
|
|
@@ -47,8 +65,7 @@ async function installHookCommand(options) {
|
|
|
47
65
|
if (fs_1.default.existsSync(hookPath)) {
|
|
48
66
|
const existing = fs_1.default.readFileSync(hookPath, "utf-8");
|
|
49
67
|
if (existing.includes("# <kodingo>")) {
|
|
50
|
-
|
|
51
|
-
return;
|
|
68
|
+
return false;
|
|
52
69
|
}
|
|
53
70
|
// Append to existing hook
|
|
54
71
|
const updated = existing.endsWith("\n")
|
|
@@ -62,7 +79,7 @@ async function installHookCommand(options) {
|
|
|
62
79
|
fs_1.default.writeFileSync(hookPath, content, "utf-8");
|
|
63
80
|
}
|
|
64
81
|
fs_1.default.chmodSync(hookPath, 0o755);
|
|
65
|
-
|
|
82
|
+
return true;
|
|
66
83
|
}
|
|
67
84
|
function resolveRepoRoot(options) {
|
|
68
85
|
if (options.repo && options.repo.trim()) {
|
package/dist/commands/update.js
CHANGED
|
@@ -2,18 +2,18 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.updateCommand = updateCommand;
|
|
4
4
|
const child_process_1 = require("child_process");
|
|
5
|
-
async function updateCommand() {
|
|
5
|
+
async function updateCommand(targetVersion) {
|
|
6
6
|
console.log("Checking for updates...");
|
|
7
7
|
let currentVersion;
|
|
8
8
|
let latestVersion;
|
|
9
9
|
try {
|
|
10
|
-
currentVersion = (0, child_process_1.
|
|
10
|
+
currentVersion = (0, child_process_1.execFileSync)("kodingo", ["--version"], { encoding: "utf-8" }).trim();
|
|
11
11
|
}
|
|
12
12
|
catch {
|
|
13
13
|
currentVersion = "unknown";
|
|
14
14
|
}
|
|
15
15
|
try {
|
|
16
|
-
latestVersion = (0, child_process_1.
|
|
16
|
+
latestVersion = targetVersion ?? (0, child_process_1.execFileSync)("npm", ["view", "kodingo-cli", "version"], { encoding: "utf-8" }).trim();
|
|
17
17
|
}
|
|
18
18
|
catch {
|
|
19
19
|
console.error("Could not fetch latest version. Check your internet connection.");
|
|
@@ -25,11 +25,23 @@ async function updateCommand() {
|
|
|
25
25
|
}
|
|
26
26
|
console.log(`Updating from ${currentVersion} to ${latestVersion}...`);
|
|
27
27
|
try {
|
|
28
|
-
(0, child_process_1.
|
|
28
|
+
const integrity = (0, child_process_1.execFileSync)("npm", ["view", `kodingo-cli@${latestVersion}`, "dist.integrity"], { encoding: "utf8" }).trim();
|
|
29
|
+
if (!integrity.startsWith("sha512-"))
|
|
30
|
+
throw new Error("registry did not provide an sha512 integrity value");
|
|
31
|
+
(0, child_process_1.execFileSync)("npm", ["install", "-g", `kodingo-cli@${latestVersion}`], { stdio: "inherit" });
|
|
32
|
+
const installed = (0, child_process_1.execFileSync)("kodingo", ["--version"], { encoding: "utf8" }).trim();
|
|
33
|
+
if (installed !== latestVersion)
|
|
34
|
+
throw new Error(`installed version ${installed} does not match ${latestVersion}`);
|
|
29
35
|
console.log(`Updated to ${latestVersion} successfully.`);
|
|
30
36
|
}
|
|
31
|
-
catch {
|
|
37
|
+
catch (error) {
|
|
38
|
+
if (currentVersion !== "unknown") {
|
|
39
|
+
try {
|
|
40
|
+
(0, child_process_1.execFileSync)("npm", ["install", "-g", `kodingo-cli@${currentVersion}`], { stdio: "ignore" });
|
|
41
|
+
}
|
|
42
|
+
catch { /* best-effort rollback; exact recovery command is printed below */ }
|
|
43
|
+
}
|
|
32
44
|
console.error("Update failed. Try running: npm install -g kodingo-cli@latest");
|
|
33
|
-
|
|
45
|
+
throw error;
|
|
34
46
|
}
|
|
35
47
|
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.redactSecrets = exports.privacySafeExcerpt = exports.isNeverReadPath = exports.EVIDENCE_EXCERPT_LIMIT = exports.EXTRACTOR_FORMAT_VERSION = void 0;
|
|
4
|
+
exports.extractLocalFile = extractLocalFile;
|
|
5
|
+
exports.sanitizeLocalExtraction = sanitizeLocalExtraction;
|
|
6
|
+
/** Compatibility wrapper around the single shared extractor package. */
|
|
7
|
+
const kodingo_core_1 = require("kodingo-core");
|
|
8
|
+
Object.defineProperty(exports, "EXTRACTOR_FORMAT_VERSION", { enumerable: true, get: function () { return kodingo_core_1.EXTRACTOR_FORMAT_VERSION; } });
|
|
9
|
+
Object.defineProperty(exports, "EVIDENCE_EXCERPT_LIMIT", { enumerable: true, get: function () { return kodingo_core_1.DEFAULT_EVIDENCE_EXCERPT_LIMIT; } });
|
|
10
|
+
Object.defineProperty(exports, "isNeverReadPath", { enumerable: true, get: function () { return kodingo_core_1.isNeverReadPath; } });
|
|
11
|
+
Object.defineProperty(exports, "privacySafeExcerpt", { enumerable: true, get: function () { return kodingo_core_1.privacySafeExcerpt; } });
|
|
12
|
+
Object.defineProperty(exports, "redactSecrets", { enumerable: true, get: function () { return kodingo_core_1.redactSecrets; } });
|
|
13
|
+
async function extractLocalFile(filePath, blobSha, bytes) {
|
|
14
|
+
const result = await (0, kodingo_core_1.extractFile)({ path: filePath, blobSha, bytes });
|
|
15
|
+
if (result.skipped)
|
|
16
|
+
return null;
|
|
17
|
+
return (0, kodingo_core_1.sanitizeForUpload)(result);
|
|
18
|
+
}
|
|
19
|
+
function sanitizeLocalExtraction(result, includeExcerpts) {
|
|
20
|
+
return (0, kodingo_core_1.sanitizeForUpload)(result, includeExcerpts);
|
|
21
|
+
}
|
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.parseRepoNameFromRemote = parseRepoNameFromRemote;
|
|
7
7
|
exports.getRemoteUrl = getRemoteUrl;
|
|
8
8
|
exports.deriveCandidateRepoName = deriveCandidateRepoName;
|
|
9
|
+
exports.resolveRepoRegistration = resolveRepoRegistration;
|
|
9
10
|
exports.resolveCanonicalRepoName = resolveCanonicalRepoName;
|
|
10
11
|
/**
|
|
11
12
|
* Resolves the canonical `repo` identity sent to the server, instead of
|
|
@@ -56,13 +57,14 @@ async function deriveCandidateRepoName(repoRoot) {
|
|
|
56
57
|
return { candidateName: path_1.default.basename(repoRoot), hasRemote: false };
|
|
57
58
|
}
|
|
58
59
|
/**
|
|
59
|
-
* Returns the canonical repo label to send with this scan
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
60
|
+
* Returns the canonical repo label to send with this scan, AND whether that
|
|
61
|
+
* label was already a registered repo for this project before this call
|
|
62
|
+
* (as opposed to one this call just registered, or one resolved only by
|
|
63
|
+
* local fallback because the server was unreachable). Fails open to the
|
|
64
|
+
* locally derived candidate (alreadyRegistered:false) if the server is
|
|
65
|
+
* unreachable — a scan should never be blocked by this resolution.
|
|
64
66
|
*/
|
|
65
|
-
async function
|
|
67
|
+
async function resolveRepoRegistration(params) {
|
|
66
68
|
const { candidateName, hasRemote } = await deriveCandidateRepoName(params.repoRoot);
|
|
67
69
|
try {
|
|
68
70
|
const res = await fetch(`${params.apiUrl}/cli/repo/resolve`, {
|
|
@@ -72,12 +74,24 @@ async function resolveCanonicalRepoName(params) {
|
|
|
72
74
|
});
|
|
73
75
|
if (res.ok) {
|
|
74
76
|
const data = (await res.json());
|
|
75
|
-
if (data.repoName)
|
|
76
|
-
|
|
77
|
+
if (data.repoName) {
|
|
78
|
+
const alreadyRegistered = data.matched === "single-registered" || data.matched === "multi-matched";
|
|
79
|
+
return { repoName: data.repoName, alreadyRegistered };
|
|
80
|
+
}
|
|
77
81
|
}
|
|
78
82
|
}
|
|
79
83
|
catch {
|
|
80
84
|
// offline / server unreachable — fail open below
|
|
81
85
|
}
|
|
82
|
-
return candidateName;
|
|
86
|
+
return { repoName: candidateName, alreadyRegistered: false };
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Returns the canonical repo label to send with this scan. Fails open to
|
|
90
|
+
* the locally derived candidate if the server is unreachable — a scan
|
|
91
|
+
* should never be blocked by this resolution, and the git-remote-derived
|
|
92
|
+
* candidate is already more stable than the old folder-basename behaviour
|
|
93
|
+
* even without a round-trip to the server.
|
|
94
|
+
*/
|
|
95
|
+
async function resolveCanonicalRepoName(params) {
|
|
96
|
+
return (await resolveRepoRegistration(params)).repoName;
|
|
83
97
|
}
|
|
@@ -1,145 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
* brief: "Stop capturing vendored/third-party code as if it were the
|
|
8
|
-
* client's own" (2026-09-22). Mirrored, identically-designed module in
|
|
9
|
-
* kodingo-api (utils/vendoredCodeDetector.ts) and kodingo-vscode
|
|
10
|
-
* (src/utils/vendoredCodeDetector.ts) — each repo has its own real,
|
|
11
|
-
* separate walk/extract pipeline with no shared low-level utility package
|
|
12
|
-
* between them (kodingo-core is explicitly scoped to decision/memory
|
|
13
|
-
* lifecycle domain logic, not general file classification), so this is
|
|
14
|
-
* duplicated by design, matching this codebase's own established
|
|
15
|
-
* precedent (e.g. IGNORED_DIRS is already independently duplicated across
|
|
16
|
-
* scan-repo.ts and security-scan.ts within this same repo). See this
|
|
17
|
-
* brief's own final report for the full reasoning.
|
|
18
|
-
*
|
|
19
|
-
* Real, confirmed evidence this fixes: an admin deep scan of a real
|
|
20
|
-
* .NET/WebForms project (TestHaven/FOTX) captured real jQuery internals
|
|
21
|
-
* (domManip, isWindow, movePrevious) and real ASP.NET WebForms framework
|
|
22
|
-
* internals (WebPartManager_InitiateWebPartDragDrop,
|
|
23
|
-
* WebForm_GetElementByTagName, Zone_UpdatePosition) as if they were the
|
|
24
|
-
* client's own business logic — diluting a real answer to "what is this
|
|
25
|
-
* project" into near-nothing.
|
|
26
|
-
*
|
|
27
|
-
* Three real, independent layers, checked cheapest/most-certain first:
|
|
28
|
-
* 1. Path/directory conventions — reliable across languages/ecosystems,
|
|
29
|
-
* needs only the file path.
|
|
30
|
-
* 2. File-naming conventions (.min.js/.min.css) — same, path-only.
|
|
31
|
-
* 3. Content heuristics (minified shape, an explicit auto-generated
|
|
32
|
-
* header) — needs real file content.
|
|
33
|
-
* A fourth, explicitly-acknowledged-INCOMPLETE layer: a real, growing list
|
|
34
|
-
* of specific, well-known bundled framework files. This list will NEVER be
|
|
35
|
-
* complete — it exists because layers 1-2, by design, cannot catch every
|
|
36
|
-
* real case: these specific files are frequently checked in un-minified,
|
|
37
|
-
* under an ordinarily-legitimate-looking folder name (e.g. "Scripts/",
|
|
38
|
-
* which is NOT treated as a vendored-directory convention here precisely
|
|
39
|
-
* because plenty of real WebForms projects also put their OWN
|
|
40
|
-
* app-specific JS there — see isVendoredPath's own reasoning below).
|
|
41
|
-
*/
|
|
42
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
43
|
-
exports.isVendoredPath = isVendoredPath;
|
|
44
|
-
exports.isVendoredContent = isVendoredContent;
|
|
45
|
-
exports.isVendoredCode = isVendoredCode;
|
|
46
|
-
const NOT_VENDORED = { vendored: false, reason: null };
|
|
47
|
-
// ── Layer 1: path/directory conventions ─────────────────────────────────────
|
|
48
|
-
const VENDORED_DIR_SEGMENTS = [
|
|
49
|
-
"node_modules", "vendor", "bower_components", "jspm_packages", "pods",
|
|
50
|
-
".venv", "venv", "site-packages",
|
|
51
|
-
];
|
|
52
|
-
// "wwwroot/lib/" specifically is ASP.NET Core's real, well-known convention
|
|
53
|
-
// for client-side libraries pulled in via LibMan/npm — directly relevant
|
|
54
|
-
// to this exact client's real stack. "lib/" alone is NOT treated as
|
|
55
|
-
// vendored — an extremely common real application folder name on its own.
|
|
56
|
-
const VENDORED_PATH_PAIRS = [
|
|
57
|
-
["wwwroot", "lib"],
|
|
58
|
-
];
|
|
59
|
-
// Classic NuGet packages/ convention: packages/<PackageName>.<Version>/...
|
|
60
|
-
// Deliberately NOT a bare "packages/" match — that would false-positive on
|
|
61
|
-
// the equally common JS/TS monorepo convention (Lerna/Yarn/npm workspaces)
|
|
62
|
-
// where packages/<name>/ holds the CLIENT'S OWN first-party code.
|
|
63
|
-
const NUGET_VERSIONED_DIR = /^[A-Za-z0-9_.-]+\.\d+\.\d+(\.\d+)?(-[A-Za-z0-9.]+)?$/;
|
|
64
|
-
function pathSegments(filePath) {
|
|
65
|
-
return filePath.replace(/\\/g, "/").split("/").filter(Boolean);
|
|
66
|
-
}
|
|
67
|
-
function isVendoredPath(filePath) {
|
|
68
|
-
const segments = pathSegments(filePath);
|
|
69
|
-
const lowerSegments = segments.map(s => s.toLowerCase());
|
|
70
|
-
for (const dir of VENDORED_DIR_SEGMENTS) {
|
|
71
|
-
if (lowerSegments.includes(dir)) {
|
|
72
|
-
return { vendored: true, reason: `Path contains the "${dir}/" vendored-dependency directory convention.` };
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
for (const [first, second] of VENDORED_PATH_PAIRS) {
|
|
76
|
-
for (let i = 0; i < lowerSegments.length - 1; i++) {
|
|
77
|
-
if (lowerSegments[i] === first && lowerSegments[i + 1] === second) {
|
|
78
|
-
return { vendored: true, reason: `Path contains the "${first}/${second}/" vendored-dependency directory convention.` };
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
const packagesIdx = lowerSegments.indexOf("packages");
|
|
83
|
-
if (packagesIdx !== -1 && packagesIdx + 1 < segments.length && NUGET_VERSIONED_DIR.test(segments[packagesIdx + 1])) {
|
|
84
|
-
return { vendored: true, reason: `Path matches the classic NuGet "packages/<Name>.<Version>/" vendored-package convention.` };
|
|
85
|
-
}
|
|
86
|
-
const basename = segments[segments.length - 1] ?? "";
|
|
87
|
-
if (/\.min\.(js|css)$/i.test(basename) || /-min\.(js|css)$/i.test(basename)) {
|
|
88
|
-
return { vendored: true, reason: `Filename "${basename}" follows the minified-distribution naming convention (.min.js/.min.css).` };
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
89
7
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
if (AUTO_GENERATED_HEADER_PATTERN.test(header)) {
|
|
102
|
-
return { vendored: true, reason: "File header contains an explicit auto-generated marker." };
|
|
103
|
-
}
|
|
104
|
-
if (content.length >= MIN_CONTENT_LENGTH_FOR_MINIFICATION_CHECK) {
|
|
105
|
-
const lineCount = content.split("\n").length;
|
|
106
|
-
const avgLineLength = content.length / Math.max(1, lineCount);
|
|
107
|
-
if (avgLineLength > MINIFIED_AVG_LINE_LENGTH_THRESHOLD) {
|
|
108
|
-
return {
|
|
109
|
-
vendored: true,
|
|
110
|
-
reason: `Unusually long average line length (${Math.round(avgLineLength)} chars/line across ${lineCount} lines) consistent with minified/bundled code, not hand-written source.`,
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
return NOT_VENDORED;
|
|
115
|
-
}
|
|
116
|
-
// ── Layer 3 (secondary, explicitly incomplete): known bundled framework files ──
|
|
117
|
-
const KNOWN_VENDORED_FILENAME_PATTERNS = [
|
|
118
|
-
/^jquery(-\d+(\.\d+){1,2})?(\.min)?\.js$/i,
|
|
119
|
-
/^jquery-ui(-\d+(\.\d+){1,2})?(\.min)?\.js$/i,
|
|
120
|
-
/^jquery\.validate(\.unobtrusive)?(\.min)?\.js$/i,
|
|
121
|
-
/^jquery\.unobtrusive-ajax(\.min)?\.js$/i,
|
|
122
|
-
/^WebUIValidation\.js$/i,
|
|
123
|
-
/^WebForms\.js$/i,
|
|
124
|
-
/^MicrosoftAjax(WebForms|Timer)?(\.debug)?\.js$/i,
|
|
125
|
-
/^SmartNav\.js$/i,
|
|
126
|
-
/^bootstrap(\.bundle)?(\.min)?\.(js|css)$/i,
|
|
127
|
-
/^modernizr(-\d+(\.\d+){1,2})?(\.min)?\.js$/i,
|
|
128
|
-
];
|
|
129
|
-
function matchKnownVendoredFile(basename) {
|
|
130
|
-
for (const pattern of KNOWN_VENDORED_FILENAME_PATTERNS) {
|
|
131
|
-
if (pattern.test(basename)) {
|
|
132
|
-
return `Filename "${basename}" matches a real, known bundled/vendored framework file (secondary, explicitly-incomplete list — see this module's own file header).`;
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
return null;
|
|
136
|
-
}
|
|
137
|
-
// ── Combined convenience ─────────────────────────────────────────────────────
|
|
138
|
-
function isVendoredCode(filePath, content) {
|
|
139
|
-
const pathResult = isVendoredPath(filePath);
|
|
140
|
-
if (pathResult.vendored)
|
|
141
|
-
return pathResult;
|
|
142
|
-
if (content !== null)
|
|
143
|
-
return isVendoredContent(content);
|
|
144
|
-
return NOT_VENDORED;
|
|
145
|
-
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
/** Compatibility facade; canonical vendored-code policy lives in kodingo-core. */
|
|
18
|
+
__exportStar(require("kodingo-core/dist/src/entity-extractor/vendoredCodeDetector"), exports);
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.compareVersions = compareVersions;
|
|
4
|
+
exports.enforceVersionPolicy = enforceVersionPolicy;
|
|
5
|
+
const persistence_config_1 = require("./persistence-config");
|
|
6
|
+
const local_deep_scan_extractor_1 = require("./local-deep-scan-extractor");
|
|
7
|
+
const update_1 = require("../commands/update");
|
|
8
|
+
const { version: CLI_VERSION } = require("../../package.json");
|
|
9
|
+
function compareVersions(left, right) {
|
|
10
|
+
const a = left.split(".").map(Number), b = right.split(".").map(Number);
|
|
11
|
+
for (let i = 0; i < Math.max(a.length, b.length); i++) {
|
|
12
|
+
const delta = (a[i] ?? 0) - (b[i] ?? 0);
|
|
13
|
+
if (delta)
|
|
14
|
+
return delta > 0 ? 1 : -1;
|
|
15
|
+
}
|
|
16
|
+
return 0;
|
|
17
|
+
}
|
|
18
|
+
async function enforceVersionPolicy(args = process.argv.slice(2)) {
|
|
19
|
+
if (process.env.KODINGO_SKIP_UPDATE_CHECK === "true" || args[0] === "update")
|
|
20
|
+
return;
|
|
21
|
+
const apiUrl = ((0, persistence_config_1.readConfig)().apiUrl ?? "https://kodingo-api.onrender.com").replace(/\/$/, "");
|
|
22
|
+
let policy;
|
|
23
|
+
try {
|
|
24
|
+
const response = await fetch(`${apiUrl}/cli/version-policy`, { signal: AbortSignal.timeout(3000) });
|
|
25
|
+
if (!response.ok)
|
|
26
|
+
return;
|
|
27
|
+
policy = await response.json();
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
if (local_deep_scan_extractor_1.EXTRACTOR_FORMAT_VERSION < policy.minimumExtractorFormat || local_deep_scan_extractor_1.EXTRACTOR_FORMAT_VERSION > policy.maximumExtractorFormat)
|
|
33
|
+
throw new Error(`${policy.message} Run: ${policy.updateCommand}`);
|
|
34
|
+
if (compareVersions(CLI_VERSION, policy.minimumCliVersion) < 0)
|
|
35
|
+
throw new Error(`Kodingo CLI ${CLI_VERSION} is below the required ${policy.minimumCliVersion}. Run: ${policy.updateCommand}`);
|
|
36
|
+
const nonInteractive = Boolean(process.env.CI) || args.includes("--no-update") || process.env.KODINGO_NO_AUTO_UPDATE === "true";
|
|
37
|
+
if (compareVersions(CLI_VERSION, policy.latestCliVersion) < 0) {
|
|
38
|
+
if (nonInteractive) {
|
|
39
|
+
console.warn(`Kodingo CLI ${policy.latestCliVersion} is available. Run: ${policy.updateCommand}`);
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
await (0, update_1.updateCommand)(policy.latestCliVersion);
|
|
43
|
+
}
|
|
44
|
+
}
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kodingo-cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.1",
|
|
4
4
|
"description": "Kodingo CLI",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"private": false,
|
|
7
7
|
"type": "commonjs",
|
|
8
8
|
"main": "dist/cli.js",
|
|
9
9
|
"bin": {
|
|
10
|
-
"kodingo": "dist/
|
|
10
|
+
"kodingo": "dist/bootstrap.js"
|
|
11
11
|
},
|
|
12
12
|
"files": [
|
|
13
13
|
"dist"
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"@typescript-eslint/typescript-estree": "^8.61.1",
|
|
27
27
|
"commander": "^12.1.0",
|
|
28
28
|
"kodingo-agent": "^0.2.0",
|
|
29
|
-
"kodingo-core": "^0.3.
|
|
29
|
+
"kodingo-core": "^0.3.7",
|
|
30
30
|
"open": "^11.0.0",
|
|
31
31
|
"simple-git": "^3.30.0",
|
|
32
32
|
"tree-sitter-wasms": "^0.1.13",
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const graph_builder_1 = require("./utils/graph-builder");
|
|
4
|
-
async function main() {
|
|
5
|
-
const repoRoot = process.argv[2];
|
|
6
|
-
const graph = await (0, graph_builder_1.buildGraph)(repoRoot);
|
|
7
|
-
const node = Object.values(graph.nodes).find(n => n.name === "projectRoutes");
|
|
8
|
-
console.log(node);
|
|
9
|
-
}
|
|
10
|
-
main();
|