pi-lens 3.8.24 → 3.8.25
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/CHANGELOG.md +9 -0
- package/clients/dispatch/runners/similarity.ts +42 -18
- package/clients/lsp/launch.ts +2 -0
- package/clients/metrics-history.ts +20 -0
- package/clients/runtime-session.ts +54 -36
- package/commands/booboo.ts +4 -24
- package/index.ts +7 -2
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,15 @@ All notable changes to pi-lens will be documented in this file.
|
|
|
4
4
|
|
|
5
5
|
## [Unreleased]
|
|
6
6
|
|
|
7
|
+
## [3.8.25] - 2026-04-13
|
|
8
|
+
|
|
9
|
+
### Changed
|
|
10
|
+
- **Go LSP PATH augmentation on Windows** — LSP subprocess PATH now includes common Go install directories (`C:\Program Files\Go\bin`, `C:\Go\bin`) to prevent `gopls` startup/runtime failures when `go` is not in inherited shell PATH.
|
|
11
|
+
- **Similarity runner cold-start behavior** — similarity now skips fast when no cached project index exists and for tiny/trivial files, reducing write/edit pipeline tail latency and eliminating frequent 30s timeout noise in scratch-file workflows.
|
|
12
|
+
|
|
13
|
+
### Fixed
|
|
14
|
+
- **Non-git workspace commit lookup noise** — metrics snapshot commit detection now pre-checks repository context before invoking Git, preventing `fatal: not a git repository` terminal noise in non-repo folders.
|
|
15
|
+
|
|
7
16
|
## [3.8.24] - 2026-04-12
|
|
8
17
|
|
|
9
18
|
### Changed
|
|
@@ -9,8 +9,8 @@ import * as nodeFs from "node:fs";
|
|
|
9
9
|
import * as fs from "node:fs/promises";
|
|
10
10
|
import * as path from "node:path";
|
|
11
11
|
import * as ts from "typescript";
|
|
12
|
-
import { EXCLUDED_DIRS } from "../../file-utils.js";
|
|
13
12
|
import { NativeRustCoreClient } from "../../native-rust-client.js";
|
|
13
|
+
import { collectSourceFiles } from "../../source-filter.js";
|
|
14
14
|
import {
|
|
15
15
|
buildProjectIndex,
|
|
16
16
|
findSimilarFunctions,
|
|
@@ -40,6 +40,7 @@ const CONFIG = {
|
|
|
40
40
|
SIMILARITY_THRESHOLD: 0.96, // align with booboo: stricter to reduce boilerplate false positives
|
|
41
41
|
MIN_TRANSITIONS: 40, // stronger signal floor for structural comparisons
|
|
42
42
|
MIN_FUNCTION_LINES: 8, // Ignore tiny helpers/wrappers
|
|
43
|
+
MIN_FILE_CHARS: 140, // Skip tiny/trivial files early
|
|
43
44
|
MAX_TRANSITION_RATIO: 1.8, // Skip pairs with highly mismatched complexity/size
|
|
44
45
|
MAX_SUGGESTIONS: 3, // Max 3 suggestions per file
|
|
45
46
|
MAX_PER_TARGET_NAME: 1, // Avoid one-to-many spam for the same target utility
|
|
@@ -115,12 +116,26 @@ const similarityRunner: RunnerDefinition = {
|
|
|
115
116
|
return { status: "skipped", diagnostics: [], semantic: "none" };
|
|
116
117
|
}
|
|
117
118
|
|
|
119
|
+
const lineCount = content.split(/\r?\n/).length;
|
|
120
|
+
if (
|
|
121
|
+
content.trim().length < CONFIG.MIN_FILE_CHARS ||
|
|
122
|
+
lineCount < CONFIG.MIN_FUNCTION_LINES + 2 ||
|
|
123
|
+
!/(\bfunction\b|=>)/.test(content)
|
|
124
|
+
) {
|
|
125
|
+
return { status: "skipped", diagnostics: [], semantic: "none" };
|
|
126
|
+
}
|
|
127
|
+
|
|
118
128
|
// Find project root and load index
|
|
119
129
|
const projectRoot = await findProjectRoot(filePath);
|
|
120
130
|
if (!projectRoot) {
|
|
121
131
|
return { status: "skipped", diagnostics: [], semantic: "none" };
|
|
122
132
|
}
|
|
123
133
|
|
|
134
|
+
const cachedIndex = await loadCachedIndex(projectRoot);
|
|
135
|
+
if (!cachedIndex || cachedIndex.entries.size === 0) {
|
|
136
|
+
return { status: "skipped", diagnostics: [], semantic: "none" };
|
|
137
|
+
}
|
|
138
|
+
|
|
124
139
|
// ── Rust fast-path ─────────────────────────────────────────────────────
|
|
125
140
|
// Try Rust for file scanning + similarity detection. If the Rust binary
|
|
126
141
|
// is available, use it. On any failure, fall through to the pure-TS path.
|
|
@@ -139,10 +154,7 @@ const similarityRunner: RunnerDefinition = {
|
|
|
139
154
|
}
|
|
140
155
|
// ── TypeScript fallback ─────────────────────────────────────────────────
|
|
141
156
|
|
|
142
|
-
const index =
|
|
143
|
-
if (!index || index.entries.size === 0) {
|
|
144
|
-
return { status: "skipped", diagnostics: [], semantic: "none" };
|
|
145
|
-
}
|
|
157
|
+
const index = cachedIndex;
|
|
146
158
|
|
|
147
159
|
// Parse the file
|
|
148
160
|
const sourceFile = ts.createSourceFile(
|
|
@@ -512,30 +524,42 @@ async function loadOrBuildIndex(
|
|
|
512
524
|
}
|
|
513
525
|
|
|
514
526
|
// Build new index
|
|
515
|
-
const
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
cwd: projectRoot,
|
|
525
|
-
ignore: ignorePatterns,
|
|
527
|
+
const absoluteFiles = collectSourceFiles(projectRoot, {
|
|
528
|
+
extensions: [".ts"],
|
|
529
|
+
}).filter((filePath) => {
|
|
530
|
+
const normalized = filePath.replace(/\\/g, "/");
|
|
531
|
+
return (
|
|
532
|
+
!normalized.endsWith(".test.ts") &&
|
|
533
|
+
!normalized.endsWith(".spec.ts") &&
|
|
534
|
+
!normalized.endsWith(".poc.test.ts")
|
|
535
|
+
);
|
|
526
536
|
});
|
|
527
537
|
|
|
528
|
-
if (
|
|
538
|
+
if (absoluteFiles.length === 0) {
|
|
529
539
|
return null;
|
|
530
540
|
}
|
|
531
541
|
|
|
532
|
-
const absoluteFiles = files.map((f) => path.join(projectRoot, f));
|
|
533
542
|
const index = await buildProjectIndex(projectRoot, absoluteFiles);
|
|
534
543
|
|
|
535
544
|
indexCache.set(projectRoot, index);
|
|
536
545
|
return index;
|
|
537
546
|
}
|
|
538
547
|
|
|
548
|
+
async function loadCachedIndex(projectRoot: string): Promise<ProjectIndex | null> {
|
|
549
|
+
const cached = indexCache.get(projectRoot);
|
|
550
|
+
if (cached) {
|
|
551
|
+
return cached;
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
const existing = await loadIndex(projectRoot);
|
|
555
|
+
if (!existing) {
|
|
556
|
+
return null;
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
indexCache.set(projectRoot, existing);
|
|
560
|
+
return existing;
|
|
561
|
+
}
|
|
562
|
+
|
|
539
563
|
// ============================================================================
|
|
540
564
|
// Testing Helper
|
|
541
565
|
// ============================================================================
|
package/clients/lsp/launch.ts
CHANGED
|
@@ -35,6 +35,8 @@ function buildAugmentedPath(basePath?: string): string {
|
|
|
35
35
|
candidates.push(path.join(userProfile, ".cargo", "bin"));
|
|
36
36
|
candidates.push(path.join(userProfile, "go", "bin"));
|
|
37
37
|
}
|
|
38
|
+
candidates.push(path.join("C:\\", "Program Files", "Go", "bin"));
|
|
39
|
+
candidates.push(path.join("C:\\", "Go", "bin"));
|
|
38
40
|
candidates.push(path.join("C:\\", "Ruby34-x64", "bin"));
|
|
39
41
|
candidates.push(path.join("C:\\", "Ruby33-x64", "bin"));
|
|
40
42
|
|
|
@@ -45,10 +45,30 @@ const MAX_HISTORY_PER_FILE = 20;
|
|
|
45
45
|
|
|
46
46
|
// --- Git Helpers ---
|
|
47
47
|
|
|
48
|
+
/**
|
|
49
|
+
* Check whether cwd is inside a Git worktree.
|
|
50
|
+
*/
|
|
51
|
+
function isInsideGitRepo(startDir: string): boolean {
|
|
52
|
+
let dir = path.resolve(startDir);
|
|
53
|
+
while (true) {
|
|
54
|
+
if (fs.existsSync(path.join(dir, ".git"))) {
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
const parent = path.dirname(dir);
|
|
58
|
+
if (parent === dir) break;
|
|
59
|
+
dir = parent;
|
|
60
|
+
}
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
|
|
48
64
|
/**
|
|
49
65
|
* Get current git commit hash (short)
|
|
50
66
|
*/
|
|
51
67
|
function getCurrentCommit(): string {
|
|
68
|
+
if (!isInsideGitRepo(process.cwd())) {
|
|
69
|
+
return "unknown";
|
|
70
|
+
}
|
|
71
|
+
|
|
52
72
|
try {
|
|
53
73
|
return execSync("git rev-parse --short HEAD", {
|
|
54
74
|
encoding: "utf-8",
|
|
@@ -10,13 +10,13 @@ import { getKnipIgnorePatterns } from "./file-utils.js";
|
|
|
10
10
|
import type { GoClient } from "./go-client.js";
|
|
11
11
|
import type { JscpdClient } from "./jscpd-client.js";
|
|
12
12
|
import type { KnipClient } from "./knip-client.js";
|
|
13
|
+
import { canRunStartupHeavyScans } from "./language-policy.js";
|
|
13
14
|
import {
|
|
14
15
|
detectProjectLanguageProfile,
|
|
15
16
|
getDefaultStartupTools,
|
|
16
17
|
hasLanguage,
|
|
17
18
|
isLanguageConfigured,
|
|
18
19
|
} from "./language-profile.js";
|
|
19
|
-
import { canRunStartupHeavyScans } from "./language-policy.js";
|
|
20
20
|
import type { MetricsClient } from "./metrics-client.js";
|
|
21
21
|
import {
|
|
22
22
|
buildProjectIndex,
|
|
@@ -64,7 +64,10 @@ interface SessionStartDeps {
|
|
|
64
64
|
|
|
65
65
|
type StartupMode = "full" | "minimal" | "quick";
|
|
66
66
|
|
|
67
|
-
function isCommandAvailable(
|
|
67
|
+
function isCommandAvailable(
|
|
68
|
+
command: string,
|
|
69
|
+
args: string[] = ["--version"],
|
|
70
|
+
): boolean {
|
|
68
71
|
const result = safeSpawn(command, args, { timeout: 5000 });
|
|
69
72
|
return !result.error && result.status === 0;
|
|
70
73
|
}
|
|
@@ -97,7 +100,9 @@ function getLanguageInstallHints(
|
|
|
97
100
|
};
|
|
98
101
|
|
|
99
102
|
if (hasStrongSignal("go") && !isCommandAvailable("gopls")) {
|
|
100
|
-
hints.push(
|
|
103
|
+
hints.push(
|
|
104
|
+
"Go detected: install gopls (`go install golang.org/x/tools/gopls@latest`).",
|
|
105
|
+
);
|
|
101
106
|
}
|
|
102
107
|
if (hasStrongSignal("rust") && !isCommandAvailable("rust-analyzer")) {
|
|
103
108
|
hints.push(
|
|
@@ -174,6 +179,25 @@ export async function handleSessionStart(
|
|
|
174
179
|
delete process.env.PI_LENS_DISABLE_LSP_INSTALL;
|
|
175
180
|
}
|
|
176
181
|
|
|
182
|
+
const hasWorkspaceCwd = typeof ctxCwd === "string" && ctxCwd.length > 0;
|
|
183
|
+
const cwd = ctxCwd ?? process.cwd();
|
|
184
|
+
if (quickMode) {
|
|
185
|
+
runtime.projectRoot = cwd;
|
|
186
|
+
const quickTools: string[] = [];
|
|
187
|
+
if (getFlag("lens-lsp") && !getFlag("no-lsp")) {
|
|
188
|
+
quickTools.push("LSP Service");
|
|
189
|
+
}
|
|
190
|
+
log(`Active tools: ${quickTools.join(", ")}`);
|
|
191
|
+
dbg(
|
|
192
|
+
`session_start tools: ${quickTools.join(", ") || "deferred (quick mode)"}`,
|
|
193
|
+
);
|
|
194
|
+
dbg(
|
|
195
|
+
"session_start: quick mode active - skipping slow tool probes, language profiling, preinstall, scans, and error debt baseline",
|
|
196
|
+
);
|
|
197
|
+
dbg(`session_start total: ${Date.now() - sessionStartMs}ms`);
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
|
|
177
201
|
const tools: string[] = [];
|
|
178
202
|
if (getFlag("lens-lsp") && !getFlag("no-lsp")) {
|
|
179
203
|
tools.push("LSP Service");
|
|
@@ -200,17 +224,6 @@ export async function handleSessionStart(
|
|
|
200
224
|
}
|
|
201
225
|
}
|
|
202
226
|
|
|
203
|
-
const hasWorkspaceCwd = typeof ctxCwd === "string" && ctxCwd.length > 0;
|
|
204
|
-
const cwd = ctxCwd ?? process.cwd();
|
|
205
|
-
if (quickMode) {
|
|
206
|
-
runtime.projectRoot = cwd;
|
|
207
|
-
dbg(
|
|
208
|
-
"session_start: quick mode active - skipping language profiling, preinstall, scans, and error debt baseline",
|
|
209
|
-
);
|
|
210
|
-
dbg(`session_start total: ${Date.now() - sessionStartMs}ms`);
|
|
211
|
-
return;
|
|
212
|
-
}
|
|
213
|
-
|
|
214
227
|
const startupScan = resolveStartupScanContext(cwd);
|
|
215
228
|
const scanRoot = startupScan.projectRoot ?? cwd;
|
|
216
229
|
const useScanRootForSignals =
|
|
@@ -236,18 +249,20 @@ export async function handleSessionStart(
|
|
|
236
249
|
}
|
|
237
250
|
|
|
238
251
|
const lensLspEnabled = !!getFlag("lens-lsp") && !getFlag("no-lsp");
|
|
239
|
-
const startupDefaults = getDefaultStartupTools(languageProfile).filter(
|
|
240
|
-
|
|
241
|
-
(
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
252
|
+
const startupDefaults = getDefaultStartupTools(languageProfile).filter(
|
|
253
|
+
(tool) => {
|
|
254
|
+
if (
|
|
255
|
+
(tool === "typescript-language-server" || tool === "pyright") &&
|
|
256
|
+
!lensLspEnabled
|
|
257
|
+
) {
|
|
258
|
+
return false;
|
|
259
|
+
}
|
|
260
|
+
if (tool === "ruff" && getFlag("no-autofix-ruff")) {
|
|
261
|
+
return false;
|
|
262
|
+
}
|
|
263
|
+
return true;
|
|
264
|
+
},
|
|
265
|
+
);
|
|
251
266
|
|
|
252
267
|
if (!allowBootstrapTasks) {
|
|
253
268
|
dbg("session_start: skipping tool preinstall (startup mode)");
|
|
@@ -369,7 +384,9 @@ export async function handleSessionStart(
|
|
|
369
384
|
runtime.markStartupScanInFlight(name, sessionGeneration);
|
|
370
385
|
void task()
|
|
371
386
|
.then(() => {
|
|
372
|
-
dbg(
|
|
387
|
+
dbg(
|
|
388
|
+
`session_start task ${name}: success (${Date.now() - startedAt}ms)`,
|
|
389
|
+
);
|
|
373
390
|
})
|
|
374
391
|
.catch((err) => {
|
|
375
392
|
dbg(`session_start: ${name} background scan failed: ${err}`);
|
|
@@ -391,7 +408,9 @@ export async function handleSessionStart(
|
|
|
391
408
|
dbg(
|
|
392
409
|
`session_start: skipping heavy scans (${startupScan.reason ?? "unknown"})`,
|
|
393
410
|
);
|
|
394
|
-
dbg(
|
|
411
|
+
dbg(
|
|
412
|
+
`session_start: skipping TODO scan (${startupScan.reason ?? "unknown"})`,
|
|
413
|
+
);
|
|
395
414
|
} else {
|
|
396
415
|
const canRunJsTsHeavyScans = canRunStartupHeavyScans(
|
|
397
416
|
languageProfile,
|
|
@@ -401,9 +420,7 @@ export async function handleSessionStart(
|
|
|
401
420
|
if (canRunJsTsHeavyScans) {
|
|
402
421
|
scanNames.push("knip", "jscpd", "ast-grep exports", "project index");
|
|
403
422
|
}
|
|
404
|
-
dbg(
|
|
405
|
-
`session_start: launching background scans (${scanNames.join(", ")})`,
|
|
406
|
-
);
|
|
423
|
+
dbg(`session_start: launching background scans (${scanNames.join(", ")})`);
|
|
407
424
|
|
|
408
425
|
runStartupTask("todo", async () => {
|
|
409
426
|
if (!runtime.isCurrentSession(sessionGeneration)) return;
|
|
@@ -458,10 +475,9 @@ export async function handleSessionStart(
|
|
|
458
475
|
runStartupTask("jscpd", async () => {
|
|
459
476
|
if (await jscpdClient.ensureAvailable()) {
|
|
460
477
|
if (!runtime.isCurrentSession(sessionGeneration)) return;
|
|
461
|
-
const cached = cacheManager.readCache<
|
|
462
|
-
"
|
|
463
|
-
|
|
464
|
-
);
|
|
478
|
+
const cached = cacheManager.readCache<
|
|
479
|
+
ReturnType<JscpdClient["scan"]>
|
|
480
|
+
>("jscpd", analysisRoot);
|
|
465
481
|
if (cached) {
|
|
466
482
|
if (!runtime.isCurrentSession(sessionGeneration)) return;
|
|
467
483
|
dbg("session_start jscpd: cache hit");
|
|
@@ -527,7 +543,9 @@ export async function handleSessionStart(
|
|
|
527
543
|
);
|
|
528
544
|
} else {
|
|
529
545
|
if (!runtime.isCurrentSession(sessionGeneration)) return;
|
|
530
|
-
dbg(
|
|
546
|
+
dbg(
|
|
547
|
+
`session_start: skipped project index (${tsFiles.length} files)`,
|
|
548
|
+
);
|
|
531
549
|
}
|
|
532
550
|
}
|
|
533
551
|
});
|
package/commands/booboo.ts
CHANGED
|
@@ -369,33 +369,13 @@ export async function handleBooboo(
|
|
|
369
369
|
// Runner 3: Semantic similarity
|
|
370
370
|
await tracker.run("semantic similarity (Amain)", async () => {
|
|
371
371
|
try {
|
|
372
|
-
const
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
ignore: [
|
|
376
|
-
"**/node_modules/**",
|
|
377
|
-
"**/*.test.ts",
|
|
378
|
-
"**/*.test.tsx",
|
|
379
|
-
"**/*.spec.ts",
|
|
380
|
-
"**/*.spec.tsx",
|
|
381
|
-
"**/*.poc.test.ts",
|
|
382
|
-
"**/*.poc.test.tsx",
|
|
383
|
-
"**/test-utils.ts",
|
|
384
|
-
"**/test-*.ts",
|
|
385
|
-
"**/__tests__/**",
|
|
386
|
-
"**/tests/**",
|
|
387
|
-
"**/dist/**",
|
|
388
|
-
],
|
|
389
|
-
});
|
|
372
|
+
const absoluteFiles = collectSourceFiles(targetPath, {
|
|
373
|
+
extensions: [".ts"],
|
|
374
|
+
}).filter(shouldIncludeFile);
|
|
390
375
|
|
|
391
|
-
if (
|
|
376
|
+
if (absoluteFiles.length === 0) {
|
|
392
377
|
return { findings: 0, status: "done" };
|
|
393
378
|
}
|
|
394
|
-
|
|
395
|
-
// Filter out test files using centralized exclusion
|
|
396
|
-
const absoluteFiles = sourceFiles
|
|
397
|
-
.map((f) => path.join(targetPath, f))
|
|
398
|
-
.filter(shouldIncludeFile);
|
|
399
379
|
const index = await buildProjectIndex(targetPath, absoluteFiles);
|
|
400
380
|
const topPairs = findTopSimilarPairs(index, 10);
|
|
401
381
|
|
package/index.ts
CHANGED
|
@@ -13,7 +13,6 @@ import {
|
|
|
13
13
|
getLatencyReports,
|
|
14
14
|
resetDispatchBaselines,
|
|
15
15
|
} from "./clients/dispatch/integration.js";
|
|
16
|
-
import { extractFunctions } from "./clients/dispatch/runners/similarity.js";
|
|
17
16
|
import { resetFormatService } from "./clients/format-service.js";
|
|
18
17
|
import { evaluateGitGuard, isGitCommitOrPushAttempt } from "./clients/git-guard.js";
|
|
19
18
|
import { ensureTool } from "./clients/installer/index.js";
|
|
@@ -506,7 +505,8 @@ pi.on("session_start", async (event, ctx) => {
|
|
|
506
505
|
testRunnerClient,
|
|
507
506
|
goClient,
|
|
508
507
|
rustClient,
|
|
509
|
-
ensureTool
|
|
508
|
+
ensureTool: async (name: string) =>
|
|
509
|
+
(await import("./clients/installer/index.js")).ensureTool(name),
|
|
510
510
|
cleanStaleTsBuildInfo,
|
|
511
511
|
resetDispatchBaselines,
|
|
512
512
|
resetLSPService,
|
|
@@ -594,6 +594,9 @@ pi.on("tool_call", async (event, ctx) => {
|
|
|
594
594
|
const baseline = complexityClient.analyzeFile(filePath);
|
|
595
595
|
if (baseline) {
|
|
596
596
|
runtime.complexityBaselines.set(filePath, baseline);
|
|
597
|
+
const { captureSnapshot } = await import(
|
|
598
|
+
"./clients/metrics-history.js"
|
|
599
|
+
);
|
|
597
600
|
captureSnapshot(filePath, {
|
|
598
601
|
maintainabilityIndex: baseline.maintainabilityIndex,
|
|
599
602
|
cognitiveComplexity: baseline.cognitiveComplexity,
|
|
@@ -659,6 +662,8 @@ pi.on("tool_call", async (event, ctx) => {
|
|
|
659
662
|
ts.ScriptTarget.Latest,
|
|
660
663
|
true,
|
|
661
664
|
);
|
|
665
|
+
const { extractFunctions } = await import("./clients/dispatch/runners/similarity.js");
|
|
666
|
+
const { findSimilarFunctions } = await import("./clients/project-index.js");
|
|
662
667
|
const newFunctions = extractFunctions(sourceFile, newContent);
|
|
663
668
|
const simWarnings: string[] = [];
|
|
664
669
|
let simHintsTruncated = false;
|