mirror of
https://github.com/apmantza/pi-lens.git
synced 2026-11-23 15:21:07 +08:00
feat(status): add opt-in pi-lens-issues diagnostics summary (refs #5588)
Publish a `pi-lens-issues` extension status from the widget header's own tallies: errors, warnings, unchecked files, and the clean gate. The feature is off by default (`--lens-issues-status` / `ui.issuesStatus`), so the footer is unchanged when unset, and the text is plain with no ANSI so hosts and bridges can read it as written. `getWidgetSummary()` extracts the tally block `renderWidget` already computes, so both surfaces share one counter. An activation-scoped store-change listener publishes every mutation, including RPC and non-TUI modes, and one publish after `adoptHandoff` covers resumed state and `/new`; identical consecutive text is dropped because `setStatus` repaints the host.
This commit is contained in:
1 parent
ecf5a8defc
commit
eb9db1d912
18 files changed
+697
-27
No files matched your search
@@ -0,0 +1,12 @@
|
||||
---
|
||||
section: Added
|
||||
audience: user
|
||||
area: host
|
||||
---
|
||||
|
||||
- **An opt-in `pi-lens-issues` footer status shows diagnostics counts.** `--lens-issues-status` (or
|
||||
`ui.issuesStatus: true`) publishes `●<N>E`, `!<N>W`, both side by side,
|
||||
`⚠ <N> unchecked`, or `✓ clean`, drawn from the widget header's own tallies so
|
||||
the footer and the widget cannot disagree. Off by default; the footer is
|
||||
unchanged when the flag is unset. The text is plain, with no terminal color
|
||||
escapes, so a status-rendering host or bridge reads it as written. (refs #5588)
|
||||
@@ -35,7 +35,8 @@ export interface HostPorts {
|
||||
bus(channel: string, payload: unknown): void;
|
||||
};
|
||||
readonly status: {
|
||||
set(name: string, value: string): void;
|
||||
/** `undefined` removes the key, mirroring the host's `ui.setStatus`. */
|
||||
set(name: string, value: string | undefined): void;
|
||||
};
|
||||
readonly spawn: {
|
||||
abortSignal(): AbortSignal | undefined;
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
/**
|
||||
* Footer issues-status text for the `pi-lens-issues` extension status key.
|
||||
*
|
||||
* A projection of the widget header's tallies ({@link WidgetSummary}), never a
|
||||
* second counter (#1892): the same errors, warnings, unchecked files and clean
|
||||
* gate the widget draws become one plain-text line. Plain text, not theme
|
||||
* colors: the key is read by hosts and bridges that render the raw string, so
|
||||
* ANSI would leak into their own footer.
|
||||
*/
|
||||
|
||||
import type { WidgetSummary } from "./widget-state.js";
|
||||
|
||||
/**
|
||||
* `●<N>E`, `!<N>W`, both side by side, `⚠ <N> unchecked`, `✓ clean`, or
|
||||
* `undefined` when no analyzed file has a state to report.
|
||||
*/
|
||||
export function formatIssuesStatus(summary: WidgetSummary): string | undefined {
|
||||
if (!summary.hasFiles) return undefined;
|
||||
const errors =
|
||||
summary.totalErrors > 0 ? `●${summary.totalErrors}E` : undefined;
|
||||
const warnings =
|
||||
summary.totalWarnings > 0 ? `!${summary.totalWarnings}W` : undefined;
|
||||
if (errors && warnings) return `${errors} ${warnings}`;
|
||||
if (errors) return errors;
|
||||
if (warnings) return warnings;
|
||||
if (summary.uncheckedCount > 0) {
|
||||
return `⚠ ${summary.uncheckedCount} unchecked`;
|
||||
}
|
||||
if (summary.hasRenderableCheckedFile && !summary.hasPendingAnalysis) {
|
||||
return "✓ clean";
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
@@ -310,6 +310,11 @@ export const LENS_FLAGS: readonly LensFlagSpec[] = [
|
||||
"Opt-in (#3959): render the pi-lens widget as ONE summary line (languages + error/warning totals) instead of also stacking file rows, the suppressed count and blocker details below it. Default off. Also via ui.compactWidget=true in ~/.pi-lens/config.json.",
|
||||
"ui.compactWidget",
|
||||
),
|
||||
globalOptInFlag(
|
||||
"lens-issues-status",
|
||||
"Opt-in: publish a compact pi-lens-issues footer status (●<N>E, !<N>W, ⚠ <N> unchecked, ✓ clean) projected from the widget header. Default off. Also via ui.issuesStatus=true in ~/.pi-lens/config.json.",
|
||||
"ui.issuesStatus",
|
||||
),
|
||||
{
|
||||
name: "no-lazy-tools",
|
||||
description:
|
||||
|
||||
+90
-17
@@ -361,6 +361,15 @@ interface LspRecord {
|
||||
const files = new Map<string, FileRecord>();
|
||||
let sessionLanguages: string[] = [];
|
||||
let requestRenderFn: (() => void) | null = null;
|
||||
/**
|
||||
* Activation-scoped listener beside {@link requestRenderFn}. The render
|
||||
* callback is session state (the TUI mount sets it and `clearWidgetState`
|
||||
* drops it); a consumer that projects the store outside the TUI, such as the
|
||||
* `pi-lens-issues` status, needs a feed that survives a session reset. This
|
||||
* one is wired once per activation and deliberately NOT cleared with the
|
||||
* store.
|
||||
*/
|
||||
let widgetChangeFn: (() => void) | null = null;
|
||||
|
||||
/**
|
||||
* Guards `recordDiagnostics` writes against the same race class fixed for
|
||||
@@ -434,6 +443,16 @@ export function setRenderCallback(fn: () => void): void {
|
||||
requestRenderFn = fn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the activation-scoped store-change listener. Unlike
|
||||
* {@link setRenderCallback}, {@link clearWidgetState} keeps it: it is
|
||||
* activation wiring, not session state, and a reset still has to notify the
|
||||
* projection that the old session's data is gone.
|
||||
*/
|
||||
export function setWidgetChangeCallback(fn: () => void): void {
|
||||
widgetChangeFn = fn;
|
||||
}
|
||||
|
||||
/** Reconcile a mark through the same apply/count/commit path as dispatch. */
|
||||
export function reconcileWidgetDisposition(
|
||||
cwd: string,
|
||||
@@ -711,6 +730,8 @@ export function clearWidgetState(): void {
|
||||
lspServers.clear();
|
||||
sessionLanguages = [];
|
||||
requestRenderFn = null;
|
||||
// `widgetChangeFn` survives: it is activation wiring, and the reset's
|
||||
// emptiness is itself a change the projection has to publish.
|
||||
diagnosticsWriteGuard.clear();
|
||||
runnerWriteGuard.clear();
|
||||
nextInactivePruneSize = MAX_INACTIVE_FILE_RECORDS + 1;
|
||||
@@ -2387,6 +2408,54 @@ function fitCompactHeader(
|
||||
return fitLine(` ${label}${langs}${tail}`, width);
|
||||
}
|
||||
|
||||
/**
|
||||
* The widget header's tallies, and the issue-status projection's only source.
|
||||
* One store, one tally: the status line must never recount independently
|
||||
* (#1892). `hasRenderableCheckedFile` mirrors the header's `✓ clean` gate —
|
||||
* a drawn row for a file no check can cover is not a completed check (#5287).
|
||||
*/
|
||||
export interface WidgetSummary {
|
||||
totalBlocking: number;
|
||||
totalErrors: number;
|
||||
totalWarnings: number;
|
||||
totalSuppressed: number;
|
||||
hasPendingAnalysis: boolean;
|
||||
uncheckedCount: number;
|
||||
hasRenderableCheckedFile: boolean;
|
||||
hasFiles: boolean;
|
||||
}
|
||||
|
||||
function summarizeWidget(
|
||||
records: readonly FileRecord[],
|
||||
renderable: readonly FileRecord[],
|
||||
unchecked: readonly FileRecord[],
|
||||
): WidgetSummary {
|
||||
return {
|
||||
totalBlocking: countBlockingIn(records),
|
||||
totalErrors: countTotalIn("error", records),
|
||||
totalWarnings: countTotalIn("warning", records),
|
||||
totalSuppressed: countSuppressedIn(records),
|
||||
hasPendingAnalysis: records.some(isPendingAnalysis),
|
||||
uncheckedCount: unchecked.length,
|
||||
hasRenderableCheckedFile: renderable.some(
|
||||
(rec) => rec.uncheckedInapplicable !== true,
|
||||
),
|
||||
hasFiles: records.length > 0,
|
||||
};
|
||||
}
|
||||
|
||||
/** The current store's tallies, without rendering a widget frame. */
|
||||
export function getWidgetSummary(): WidgetSummary {
|
||||
const records = [...files.values()];
|
||||
const renderable: FileRecord[] = [];
|
||||
const unchecked: FileRecord[] = [];
|
||||
for (const rec of records) {
|
||||
if (shouldRenderFile(rec)) renderable.push(rec);
|
||||
if (isUncheckedClean(rec)) unchecked.push(rec);
|
||||
}
|
||||
return summarizeWidget(records, renderable, unchecked);
|
||||
}
|
||||
|
||||
export function renderWidget(
|
||||
width: number,
|
||||
theme: {
|
||||
@@ -2421,27 +2490,28 @@ export function renderWidget(
|
||||
.slice(0, 5)
|
||||
.sort((a, b) => b.touchedAt - a.touchedAt);
|
||||
const langStr = sessionLanguages.slice(0, 6).join(" ");
|
||||
const totalBlocking = countBlockingIn(records);
|
||||
const totalErrors = countTotalIn("error", records);
|
||||
const totalWarnings = countTotalIn("warning", records);
|
||||
const totalSuppressed = countSuppressedIn(records);
|
||||
const hasPendingAnalysis = records.some(isPendingAnalysis);
|
||||
const uncheckedFiles = records.filter(isUncheckedClean);
|
||||
const summaryFacts = summarizeWidget(records, renderable, uncheckedFiles);
|
||||
const errorChunk =
|
||||
totalErrors > 0
|
||||
? (totalBlocking > 0 ? red : yellow)(`●${totalErrors}E`)
|
||||
summaryFacts.totalErrors > 0
|
||||
? (summaryFacts.totalBlocking > 0 ? red : yellow)(
|
||||
`●${summaryFacts.totalErrors}E`,
|
||||
)
|
||||
: "";
|
||||
const warningChunk =
|
||||
summaryFacts.totalWarnings > 0
|
||||
? yellow(`!${summaryFacts.totalWarnings}W`)
|
||||
: "";
|
||||
const warningChunk = totalWarnings > 0 ? yellow(`!${totalWarnings}W`) : "";
|
||||
const summary = errorChunk
|
||||
? errorChunk + (warningChunk ? " " + warningChunk : "")
|
||||
: warningChunk
|
||||
? warningChunk
|
||||
: uncheckedFiles.length > 0
|
||||
? yellow(`⚠ ${uncheckedFiles.length} unchecked`)
|
||||
: summaryFacts.uncheckedCount > 0
|
||||
? yellow(`⚠ ${summaryFacts.uncheckedCount} unchecked`)
|
||||
: // #5287: a formatter row for a file no check can cover (a generated
|
||||
// file) is not a completed check; `✓ clean` needs one that is.
|
||||
renderable.some((rec) => rec.uncheckedInapplicable !== true) &&
|
||||
!hasPendingAnalysis
|
||||
summaryFacts.hasRenderableCheckedFile &&
|
||||
!summaryFacts.hasPendingAnalysis
|
||||
? green("✓ clean")
|
||||
: "";
|
||||
|
||||
@@ -2473,8 +2543,10 @@ export function renderWidget(
|
||||
|
||||
const header = ` ${cyan("pi-lens")}${langStr ? " " + dim(langStr) : ""}${lspChip}${summary ? " " + summary : ""}`;
|
||||
lines.push(fitLine(header, w));
|
||||
if (totalSuppressed > 0) {
|
||||
lines.push(fitLine(` ${dim(`suppressed: ${totalSuppressed}`)}`, w));
|
||||
if (summaryFacts.totalSuppressed > 0) {
|
||||
lines.push(
|
||||
fitLine(` ${dim(`suppressed: ${summaryFacts.totalSuppressed}`)}`, w),
|
||||
);
|
||||
}
|
||||
|
||||
const labelOf = (rec: FileRecord) => rowLabel(rec, records);
|
||||
@@ -2890,7 +2962,7 @@ function capStoredDiagnostics(
|
||||
|
||||
function countTotalIn(
|
||||
severity: "error" | "warning",
|
||||
recs: FileRecord[],
|
||||
recs: readonly FileRecord[],
|
||||
): number {
|
||||
let n = 0;
|
||||
for (const rec of recs) {
|
||||
@@ -2900,7 +2972,7 @@ function countTotalIn(
|
||||
return n;
|
||||
}
|
||||
|
||||
function countSuppressedIn(recs: FileRecord[]): number {
|
||||
function countSuppressedIn(recs: readonly FileRecord[]): number {
|
||||
let n = 0;
|
||||
for (const rec of recs) {
|
||||
for (const diagnostic of rec.allDiagnostics) {
|
||||
@@ -2910,7 +2982,7 @@ function countSuppressedIn(recs: FileRecord[]): number {
|
||||
return n;
|
||||
}
|
||||
|
||||
function countBlockingIn(recs: FileRecord[]): number {
|
||||
function countBlockingIn(recs: readonly FileRecord[]): number {
|
||||
let n = 0;
|
||||
for (const rec of recs) n += rec.diagnosticCounts.blocking;
|
||||
return n;
|
||||
@@ -2918,6 +2990,7 @@ function countBlockingIn(recs: FileRecord[]): number {
|
||||
|
||||
function requestRender(): void {
|
||||
requestRenderFn?.();
|
||||
widgetChangeFn?.();
|
||||
}
|
||||
|
||||
function osc8(uri: string, label: string): string {
|
||||
|
||||
@@ -37,6 +37,7 @@
|
||||
"./clients/instance-reaper.js",
|
||||
"./clients/instance-registry.js",
|
||||
"./clients/io-bridge.js",
|
||||
"./clients/issues-status.js",
|
||||
"./clients/language-profile.js",
|
||||
"./clients/latency-logger.js",
|
||||
"./clients/lens-config.js",
|
||||
|
||||
@@ -40,6 +40,7 @@ Each runtime toggle is settable from the CLI *and* from `config.json`. The two a
|
||||
| `--lens-compact-lsp-status` | `ui.compactLspStatus` | `false` |
|
||||
| `--lens-hide-lsp-status` | `ui.hideLspStatus` | `false` |
|
||||
| `--lens-compact-widget` | `ui.compactWidget` | `false` |
|
||||
| `--lens-issues-status` | `ui.issuesStatus` | `false` |
|
||||
| `--no-lazy-tools` | `tools.lazy` | `true` |
|
||||
| `--lens-turn-end-madge` | `turnEnd.madge.enabled` | `false` |
|
||||
| `--lens-fallow` | `fallow.enabled` | `false` |
|
||||
|
||||
@@ -94,6 +94,7 @@ column is the effective behavior when nothing is set.
|
||||
| `--lens-compact-lsp-status` | `ui.compactLspStatus` | global | **off** (footer lists the active server names) |
|
||||
| `--lens-hide-lsp-status` | `ui.hideLspStatus` | global | **off** (footer publishes the `pi-lens-lsp` status; outranks `ui.compactLspStatus` when both are set) |
|
||||
| `--lens-compact-widget` | `ui.compactWidget` | global | **off** (widget stacks file rows, suppressed count and blocker details below its summary header; **on** renders only that header — languages + totals, plus the `LSP↑` chip while servers are spawning) |
|
||||
| `--lens-issues-status` | `ui.issuesStatus` | global | **off** (footer publishes no `pi-lens-issues` status; **on** publishes `●<N>E`, `!<N>W`, `⚠ <N> unchecked`, or `✓ clean` from the widget header's tallies) |
|
||||
| `--no-lazy-tools` | `tools.lazy` | global | `true`: the five situational tools start inactive on every model (`"auto"` only on a model that keeps mid-conversation system messages, `false` never) |
|
||||
| `--no-tool=<name>` | `tools.<name>.enabled` | project | every lens tool **on** |
|
||||
| `--lens-turn-end-madge` | `turnEnd.madge.enabled` | global | **off** (madge runs at session start, not per turn) |
|
||||
|
||||
@@ -121,6 +121,7 @@ pi --lens-compact-tool-line # Render tool results as one compact, theme-aware
|
||||
pi --lens-compact-lsp-status # Collapse the footer LSP status to one state glyph instead of the server names (refs #3099)
|
||||
pi --lens-hide-lsp-status # Publish no pi-lens-lsp footer status at all, so a status-rendering host stops showing the key (closes #3099)
|
||||
pi --lens-compact-widget # Render the widget as one summary line (languages + totals, LSP↑ chip while servers spawn) with no file rows or blocker details (refs #3959)
|
||||
pi --lens-issues-status # Publish a compact pi-lens-issues footer status from the widget summary (●<N>E, !<N>W, ⚠ <N> unchecked, ✓ clean)
|
||||
pi --no-lazy-tools # Keep every pi-lens tool active instead of activating the situational ones on demand
|
||||
pi --lens-turn-end-madge # Run the madge circular-dependency check at every turn end, not just at session start
|
||||
pi --lens-fallow # Run fallow-lsp beside the TypeScript server on JS/TS files (advisory unused-code, duplication and cycle findings; opt-in)
|
||||
|
||||
@@ -63,12 +63,15 @@ import { resolveSkillPaths } from "./clients/skills-resolver.js";
|
||||
import {
|
||||
getFailedLspServerIds,
|
||||
getSessionLanguages,
|
||||
getWidgetSummary,
|
||||
reconcileCascadeNeighborLspErrors,
|
||||
renderWidget,
|
||||
scheduleStaleReconcile,
|
||||
setRenderCallback,
|
||||
setWidgetChangeCallback,
|
||||
wireWidgetDispositionSubscriber,
|
||||
} from "./clients/widget-state.js";
|
||||
import { formatIssuesStatus } from "./clients/issues-status.js";
|
||||
import { selectLspStatus } from "./clients/lsp-status.js";
|
||||
import {
|
||||
branchToolResultIds,
|
||||
@@ -1053,6 +1056,31 @@ function activateExtension(hostPi: ExtensionAPI) {
|
||||
// never captured once — a session replacement invalidates the old ctx.ui.
|
||||
// #1334 S2: the ports notifier owns mode suppression + live-ctx resolution
|
||||
// (per-call, never captured -- the #338/#798 detached-callback rule).
|
||||
// The `pi-lens-issues` key is a projection of the widget store, published
|
||||
// from the live status port so RPC and non-TUI modes reach it too. The
|
||||
// flag is read at publish time (#4913 forbids a factory-time read), and
|
||||
// identical consecutive text is dropped: `setStatus` repaints the host.
|
||||
let issuesStatusPublished = false;
|
||||
let lastIssuesStatus: string | undefined;
|
||||
function resetIssuesStatusPublish(): void {
|
||||
issuesStatusPublished = false;
|
||||
lastIssuesStatus = undefined;
|
||||
}
|
||||
function updateIssuesStatus(): void {
|
||||
try {
|
||||
const enabled = getLensFlag("lens-issues-status") === true;
|
||||
const next = enabled ? formatIssuesStatus(getWidgetSummary()) : undefined;
|
||||
if (issuesStatusPublished && next === lastIssuesStatus) return;
|
||||
// Flag off from the start: publish nothing, so the footer is
|
||||
// byte-identical to a pi-lens without the feature.
|
||||
if (!enabled && !issuesStatusPublished) return;
|
||||
issuesStatusPublished = true;
|
||||
lastIssuesStatus = next;
|
||||
hostPorts.status.set("pi-lens-issues", next);
|
||||
} catch (err) {
|
||||
dbg(`issues status update skipped: ${err}`);
|
||||
}
|
||||
}
|
||||
const refreshCtxDerivedPlumbing = (): void => {
|
||||
// These targets are module singletons, while hostPorts is scoped to this
|
||||
// extension activation. A sibling activation can overwrite them and then
|
||||
@@ -1078,6 +1106,7 @@ function activateExtension(hostPi: ExtensionAPI) {
|
||||
wireDispositionBusEmitterGetter(getLiveEmit);
|
||||
wireFormatEventsBusEmitterGetter(getLiveEmit);
|
||||
setRenderCallback(() => hostPorts.render.invalidate());
|
||||
setWidgetChangeCallback(updateIssuesStatus);
|
||||
};
|
||||
refreshCtxDerivedPlumbing();
|
||||
// #485: read-only bus subscriber — never publishes, so the #482 loop guard
|
||||
@@ -2596,6 +2625,10 @@ function activateExtension(hostPi: ExtensionAPI) {
|
||||
);
|
||||
}
|
||||
rememberOwnEventCtx(ctx);
|
||||
// The host clears extension statuses when a session resets, so the
|
||||
// dedupe below must not suppress the first publish of the new
|
||||
// session; `updateIssuesStatus()` runs again after adoption.
|
||||
resetIssuesStatusPublish();
|
||||
refreshCtxDerivedPlumbing();
|
||||
const sessionStartFiredAt = Date.now();
|
||||
try {
|
||||
@@ -3081,6 +3114,9 @@ function activateExtension(hostPi: ExtensionAPI) {
|
||||
dbg(
|
||||
`session_start: ${sessionReason ?? "startup"} — session stores from ${handoffSource}`,
|
||||
);
|
||||
// Resumed state and `/new` both land in the store above; publish
|
||||
// once now rather than only on the next store mutation.
|
||||
updateIssuesStatus();
|
||||
|
||||
if (lensWidgetVisible) {
|
||||
mountLensWidget(ctx.ui, readExtensionMode(ctx));
|
||||
|
||||
@@ -0,0 +1,153 @@
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
import { formatIssuesStatus } from "../../clients/issues-status.js";
|
||||
import {
|
||||
type WidgetSummary,
|
||||
clearWidgetState,
|
||||
getWidgetSummary,
|
||||
recordDiagnostics,
|
||||
recordFormatter,
|
||||
recordRunner,
|
||||
renderWidget,
|
||||
setSessionLanguages,
|
||||
} from "../../clients/widget-state.js";
|
||||
|
||||
const theme = { fg: (_color: string, s: string) => s };
|
||||
|
||||
function summary(overrides: Partial<WidgetSummary> = {}): WidgetSummary {
|
||||
return {
|
||||
totalBlocking: 0,
|
||||
totalErrors: 0,
|
||||
totalWarnings: 0,
|
||||
totalSuppressed: 0,
|
||||
hasPendingAnalysis: false,
|
||||
uncheckedCount: 0,
|
||||
hasRenderableCheckedFile: true,
|
||||
hasFiles: true,
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
|
||||
afterEach(() => {
|
||||
clearWidgetState();
|
||||
});
|
||||
|
||||
describe("formatIssuesStatus", () => {
|
||||
it("renders errors only", () => {
|
||||
expect(formatIssuesStatus(summary({ totalErrors: 2 }))).toBe("●2E");
|
||||
});
|
||||
|
||||
it("renders warnings only", () => {
|
||||
expect(formatIssuesStatus(summary({ totalWarnings: 3 }))).toBe("!3W");
|
||||
});
|
||||
|
||||
it("renders errors and warnings side by side", () => {
|
||||
expect(
|
||||
formatIssuesStatus(summary({ totalErrors: 2, totalWarnings: 3 })),
|
||||
).toBe("●2E !3W");
|
||||
});
|
||||
|
||||
it("renders the unchecked count when no error or warning exists", () => {
|
||||
expect(formatIssuesStatus(summary({ uncheckedCount: 4 }))).toBe(
|
||||
"⚠ 4 unchecked",
|
||||
);
|
||||
});
|
||||
|
||||
it("renders clean only for a checked renderable file", () => {
|
||||
expect(formatIssuesStatus(summary())).toBe("✓ clean");
|
||||
});
|
||||
|
||||
it("renders no text when no analyzed file exists", () => {
|
||||
expect(formatIssuesStatus(summary({ hasFiles: false }))).toBeUndefined();
|
||||
});
|
||||
|
||||
it("renders no clean claim while a file is still pending", () => {
|
||||
expect(
|
||||
formatIssuesStatus(summary({ hasPendingAnalysis: true })),
|
||||
).toBeUndefined();
|
||||
});
|
||||
|
||||
it("does not claim clean for a file no check can cover", () => {
|
||||
expect(
|
||||
formatIssuesStatus(summary({ hasRenderableCheckedFile: false })),
|
||||
).toBeUndefined();
|
||||
});
|
||||
|
||||
it("matches the widget header's tallies for the same store", () => {
|
||||
setSessionLanguages(["jsts"]);
|
||||
recordDiagnostics("/repo/issue-a.ts", [
|
||||
{
|
||||
severity: "error",
|
||||
semantic: "blocking",
|
||||
message: "blocking",
|
||||
line: 1,
|
||||
rule: "typescript:1",
|
||||
},
|
||||
{
|
||||
severity: "warning",
|
||||
message: "warning",
|
||||
line: 2,
|
||||
rule: "ts-react-antipatterns",
|
||||
},
|
||||
]);
|
||||
recordDiagnostics("/repo/issue-b.ts", [
|
||||
{
|
||||
severity: "error",
|
||||
semantic: "blocking",
|
||||
message: "another blocking",
|
||||
line: 3,
|
||||
rule: "typescript:2",
|
||||
},
|
||||
]);
|
||||
|
||||
const header = renderWidget(120, theme)[0] ?? "";
|
||||
const formatted = formatIssuesStatus(getWidgetSummary());
|
||||
|
||||
expect(header).toContain("2E");
|
||||
expect(header).toContain("1W");
|
||||
expect(formatted).toBe("●2E !1W");
|
||||
expect(header).toContain(formatted ?? "");
|
||||
});
|
||||
|
||||
it("matches the header when same-named files hold different findings", () => {
|
||||
const dir = process.cwd();
|
||||
recordRunner(`${dir}/pi-lens/index.ts`, "tsc", "failed", 1);
|
||||
recordDiagnostics(`${dir}/pi-lens/index.ts`, [
|
||||
{
|
||||
severity: "error",
|
||||
semantic: "blocking",
|
||||
message: "blocking",
|
||||
line: 1,
|
||||
rule: "E1",
|
||||
},
|
||||
]);
|
||||
recordRunner(`${dir}/pi-webaio/index.ts`, "tsc", "succeeded", 1);
|
||||
recordDiagnostics(`${dir}/pi-webaio/index.ts`, []);
|
||||
|
||||
const header = renderWidget(120, theme)[0] ?? "";
|
||||
expect(formatIssuesStatus(getWidgetSummary())).toBe("●1E");
|
||||
expect(header).toContain("●1E");
|
||||
expect(header).not.toContain("✓ clean");
|
||||
});
|
||||
|
||||
it("withholds clean while the header does", () => {
|
||||
recordFormatter("/repo/pending.ts", "prettier", false, true);
|
||||
|
||||
const header = renderWidget(120, theme).join("\n");
|
||||
expect(getWidgetSummary().hasPendingAnalysis).toBe(true);
|
||||
expect(formatIssuesStatus(getWidgetSummary())).toBeUndefined();
|
||||
expect(header).not.toContain("✓ clean");
|
||||
});
|
||||
|
||||
it("matches the widget header's unchecked and clean summaries", () => {
|
||||
const reason = "no primary checker is enabled for this kind";
|
||||
recordDiagnostics("/repo/open.ts", [], undefined, undefined, { reason });
|
||||
expect(renderWidget(120, theme)[0]).toContain(
|
||||
formatIssuesStatus(getWidgetSummary()) ?? "",
|
||||
);
|
||||
expect(formatIssuesStatus(getWidgetSummary())).toBe("⚠ 1 unchecked");
|
||||
|
||||
recordDiagnostics("/repo/open.ts", []);
|
||||
expect(formatIssuesStatus(getWidgetSummary())).toBe("✓ clean");
|
||||
expect(renderWidget(120, theme)[0]).toContain("✓ clean");
|
||||
});
|
||||
});
|
||||
@@ -17,6 +17,7 @@ import {
|
||||
getFileDiagnostics,
|
||||
getFileDiagnosticSummaries,
|
||||
getSessionLanguages,
|
||||
getWidgetSummary,
|
||||
importWidgetState,
|
||||
incrementWidgetDependencyDriftDelivery,
|
||||
isBlocking,
|
||||
@@ -3196,3 +3197,71 @@ describe("a file no check can ever cover (#5287)", () => {
|
||||
expect(renderWidget(120, theme).join("\n")).toContain("1 unchecked");
|
||||
});
|
||||
});
|
||||
|
||||
// The widget header and the `pi-lens-issues` status come from one tally. These
|
||||
// cases pin the projection's fields to what the header actually draws, so a
|
||||
// future header change cannot leave the status counting on its own.
|
||||
describe("getWidgetSummary", () => {
|
||||
it("reports the same counts the header draws for errors and warnings", () => {
|
||||
recordDiagnostics("/repo/summary.ts", [
|
||||
{
|
||||
severity: "error",
|
||||
semantic: "blocking",
|
||||
message: "blocking",
|
||||
line: 1,
|
||||
rule: "typescript:1",
|
||||
},
|
||||
{
|
||||
severity: "warning",
|
||||
message: "warning",
|
||||
line: 2,
|
||||
rule: "ts-react-antipatterns",
|
||||
},
|
||||
]);
|
||||
|
||||
const bag = getWidgetSummary();
|
||||
expect(bag).toMatchObject({
|
||||
totalBlocking: 1,
|
||||
totalErrors: 1,
|
||||
totalWarnings: 1,
|
||||
totalSuppressed: 0,
|
||||
hasPendingAnalysis: false,
|
||||
uncheckedCount: 0,
|
||||
hasRenderableCheckedFile: true,
|
||||
hasFiles: true,
|
||||
});
|
||||
const header = renderWidget(120, theme)[0] ?? "";
|
||||
expect(header).toContain(`●${bag.totalErrors}E`);
|
||||
expect(header).toContain(`!${bag.totalWarnings}W`);
|
||||
});
|
||||
|
||||
it("reports clean only when the header draws ✓ clean", () => {
|
||||
recordDiagnostics("/repo/clean.ts", []);
|
||||
|
||||
const bag = getWidgetSummary();
|
||||
expect(bag.hasPendingAnalysis).toBe(false);
|
||||
expect(bag.uncheckedCount).toBe(0);
|
||||
expect(bag.hasRenderableCheckedFile).toBe(true);
|
||||
expect(renderWidget(120, theme).join("\n")).toContain("✓ clean");
|
||||
});
|
||||
|
||||
it("reports the unchecked count the header draws", () => {
|
||||
recordDiagnostics("/repo/unchecked.ts", [], undefined, undefined, {
|
||||
reason: "no primary checker is enabled for this kind",
|
||||
});
|
||||
|
||||
const bag = getWidgetSummary();
|
||||
expect(bag.uncheckedCount).toBe(1);
|
||||
expect(renderWidget(120, theme).join("\n")).toContain("⚠ 1 unchecked");
|
||||
});
|
||||
|
||||
it("reports no files and no clean claim on an empty store", () => {
|
||||
const bag = getWidgetSummary();
|
||||
expect(bag.hasFiles).toBe(false);
|
||||
expect(bag.totalErrors).toBe(0);
|
||||
expect(bag.totalWarnings).toBe(0);
|
||||
// A record with no final snapshot is unfinished evidence, not clean.
|
||||
recordFormatter("/repo/formatted.ts", "prettier", false, true);
|
||||
expect(getWidgetSummary().hasPendingAnalysis).toBe(true);
|
||||
});
|
||||
});
|
||||
@@ -1992,7 +1992,9 @@ const PINS: Readonly<Record<string, Readonly<Record<string, number>>>> = {
|
||||
"tools/lsp-structured-output.ts": 3,
|
||||
"mcp/analyze-cli.ts": 2,
|
||||
"mcp/server.ts": 1,
|
||||
"index.ts": 2,
|
||||
// 2 -> 3 (#5588): `hostPorts.status.set`, the extension-status port,
|
||||
// publishes the issues line; it names no delivery status.
|
||||
"index.ts": 3,
|
||||
},
|
||||
telemetry: {
|
||||
"clients/lsp-mutation.ts": 11,
|
||||
|
||||
@@ -96,6 +96,10 @@ const CONVERSATION_MODULE_STATE: Readonly<Record<string, readonly string[]>> = {
|
||||
"runnerWriteGuard",
|
||||
"sessionLanguages",
|
||||
"staleReconcileTimer",
|
||||
// #5588: the activation-scoped store-change listener. Not a store: it
|
||||
// holds one callback and no conversation facts, and `clearWidgetState`
|
||||
// deliberately keeps it so a reset still reaches the projection.
|
||||
"widgetChangeFn",
|
||||
],
|
||||
"index.ts": [
|
||||
"_bridgeGetFlag",
|
||||
@@ -129,6 +133,10 @@ const ACTIVATION_STATE: Readonly<Record<string, string>> = {
|
||||
"the /lens-context-toggle choice; D6 was not approved, so it resets per activation (N6 accepted)",
|
||||
enabledLazyTools:
|
||||
"the lazy tools the config enables, derived once per activation (design B6)",
|
||||
issuesStatusPublished:
|
||||
"whether this activation has published the issues status, so a session reset republishes even identical text while a disabled flag stays silent (#5588)",
|
||||
lastIssuesStatus:
|
||||
"the last text this activation published to the issues status; the dedupe key for a host call that repaints the footer (#5588)",
|
||||
lensEnabled:
|
||||
"the /lens-toggle choice; D6 was not approved, so it resets per activation (N6 accepted)",
|
||||
lensWidgetVisible:
|
||||
|
||||
@@ -1291,10 +1291,10 @@ const BASELINE: Readonly<Record<string, Admission>> = {
|
||||
reason: PRE_RULE,
|
||||
}, // :196, :204, :228, :333, :572
|
||||
"index.ts": {
|
||||
silent: 49,
|
||||
identities: "b48916790863d67b",
|
||||
silent: 50,
|
||||
identities: "813e41def8c519da",
|
||||
reason: SHARP_HOST,
|
||||
}, // :522, :673, :779, :783, :1118, :1141, :1454, :1604, :1761, :1780, :1789, :1832, :1899, :2143, :2154, :2187, :2238, :2268, :2401, :2453, :2543, :2571, :2644, :2745, :2757, :2814, :2820, :2946, :2970, :3047, :3222, :3270, :3369, :3495, :3527, :3603, :3777, :3854, :3959, :3992, :4079, :4116, :4131, :4158, :4193, :4204, :4537, :4544, :4877
|
||||
}, // :542, :693, :799, :803, :1080, :1186, :1209, :1528, :1678, :1835, :1854, :1863, :1904, :1971, :2226, :2237, :2271, :2322, :2366, :2513, :2565, :2685, :2713, :2786, :2891, :2903, :2960, :2966, :3097, :3147, :3224, :3463, :3514, :3616, :3765, :3800, :3881, :4059, :4143, :4248, :4281, :4368, :4405, :4420, :4447, :4482, :4493, :4828, :4835, :5200
|
||||
"mcp/analyze-cli.ts": {
|
||||
silent: 1,
|
||||
identities: "e823b8d7883207bc",
|
||||
|
||||
@@ -0,0 +1,268 @@
|
||||
import * as fs from "node:fs";
|
||||
import * as path from "node:path";
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
import { _resetSessionLifecycleForTests } from "../clients/session-lifecycle.js";
|
||||
import {
|
||||
clearWidgetState,
|
||||
exportWidgetState,
|
||||
recordDiagnostics,
|
||||
recordLsp,
|
||||
} from "../clients/widget-state.js";
|
||||
import { saveSessionState } from "../clients/session-state-store.js";
|
||||
import extension from "../index.js";
|
||||
import { useGlobalConfig } from "./support/global-config.js";
|
||||
import { endMockSessions } from "./support/mock-session-teardown.js";
|
||||
import { createPiMock, makeCtx } from "./support/pi-mock.js";
|
||||
import { setupTestEnvironment } from "./clients/test-utils.js";
|
||||
|
||||
const INTEGRATION_TIMEOUT_MS = 45_000;
|
||||
const setGlobalConfig = useGlobalConfig();
|
||||
const ISSUES_KEY = "pi-lens-issues";
|
||||
|
||||
function issueStatuses(ctx: {
|
||||
statusCalls: Array<{ key: string; text?: string }>;
|
||||
}) {
|
||||
return ctx.statusCalls
|
||||
.filter((call) => call.key === ISSUES_KEY)
|
||||
.map((call) => call.text);
|
||||
}
|
||||
|
||||
async function startSession(
|
||||
config: Record<string, unknown>,
|
||||
options: {
|
||||
mode?: "tui" | "rpc";
|
||||
cwd: string;
|
||||
sessionId?: string;
|
||||
reason?: string;
|
||||
} = { cwd: process.cwd() },
|
||||
) {
|
||||
_resetSessionLifecycleForTests();
|
||||
setGlobalConfig(config);
|
||||
const pi = createPiMock();
|
||||
extension(pi.asExtensionAPI());
|
||||
const ctx = makeCtx({
|
||||
cwd: options.cwd,
|
||||
sessionId: options.sessionId ?? "issues-status-session",
|
||||
mode: options.mode ?? "tui",
|
||||
});
|
||||
await pi.emit("session_start", { reason: options.reason ?? "startup" }, ctx);
|
||||
return ctx;
|
||||
}
|
||||
|
||||
afterEach(async () => {
|
||||
await endMockSessions();
|
||||
_resetSessionLifecycleForTests();
|
||||
clearWidgetState();
|
||||
});
|
||||
|
||||
describe("pi-lens-issues status", () => {
|
||||
it(
|
||||
"publishes nothing when lens-issues-status is off",
|
||||
async () => {
|
||||
const { tmpDir, cleanup } = setupTestEnvironment("pi-lens-issues-off-");
|
||||
try {
|
||||
const ctx = await startSession({}, { cwd: tmpDir });
|
||||
recordDiagnostics(path.join(tmpDir, "off.ts"), [
|
||||
{
|
||||
severity: "error",
|
||||
semantic: "blocking",
|
||||
message: "blocking",
|
||||
line: 1,
|
||||
rule: "typescript:1",
|
||||
},
|
||||
]);
|
||||
|
||||
expect(issueStatuses(ctx)).toEqual([]);
|
||||
} finally {
|
||||
cleanup();
|
||||
}
|
||||
},
|
||||
INTEGRATION_TIMEOUT_MS,
|
||||
);
|
||||
|
||||
it(
|
||||
"publishes live from the widget store without a turn",
|
||||
async () => {
|
||||
const { tmpDir, cleanup } = setupTestEnvironment("pi-lens-issues-live-");
|
||||
try {
|
||||
const ctx = await startSession(
|
||||
{ ui: { issuesStatus: true } },
|
||||
{ cwd: tmpDir },
|
||||
);
|
||||
recordDiagnostics(path.join(tmpDir, "live.ts"), [
|
||||
{
|
||||
severity: "error",
|
||||
semantic: "blocking",
|
||||
message: "blocking",
|
||||
line: 1,
|
||||
rule: "typescript:1",
|
||||
},
|
||||
{
|
||||
severity: "warning",
|
||||
message: "warning",
|
||||
line: 2,
|
||||
rule: "ts-react-antipatterns",
|
||||
},
|
||||
]);
|
||||
|
||||
expect(issueStatuses(ctx).at(-1)).toBe("●1E !1W");
|
||||
} finally {
|
||||
cleanup();
|
||||
}
|
||||
},
|
||||
INTEGRATION_TIMEOUT_MS,
|
||||
);
|
||||
|
||||
it(
|
||||
"publishes undefined once when the flag is on but no file is analyzed",
|
||||
async () => {
|
||||
const { tmpDir, cleanup } = setupTestEnvironment("pi-lens-issues-empty-");
|
||||
try {
|
||||
const ctx = await startSession(
|
||||
{ ui: { issuesStatus: true } },
|
||||
{ cwd: tmpDir },
|
||||
);
|
||||
|
||||
expect(issueStatuses(ctx)).toEqual([undefined]);
|
||||
} finally {
|
||||
cleanup();
|
||||
}
|
||||
},
|
||||
INTEGRATION_TIMEOUT_MS,
|
||||
);
|
||||
|
||||
it(
|
||||
"publishes a resumed snapshot after adoptHandoff",
|
||||
async () => {
|
||||
const { tmpDir, cleanup } = setupTestEnvironment(
|
||||
"pi-lens-issues-resume-",
|
||||
);
|
||||
const sessionId = "issues-status-resume";
|
||||
const filePath = path.join(tmpDir, "resumed.ts");
|
||||
try {
|
||||
fs.writeFileSync(filePath, "const a = 1;\n");
|
||||
const past = new Date(Date.now() - 60_000);
|
||||
fs.utimesSync(filePath, past, past);
|
||||
clearWidgetState();
|
||||
recordDiagnostics(filePath, [
|
||||
{
|
||||
severity: "error",
|
||||
semantic: "blocking",
|
||||
message: "resumed blocking",
|
||||
line: 1,
|
||||
rule: "typescript:1",
|
||||
},
|
||||
]);
|
||||
await saveSessionState(tmpDir, sessionId, {
|
||||
widget: exportWidgetState(),
|
||||
});
|
||||
clearWidgetState();
|
||||
|
||||
const ctx = await startSession(
|
||||
{ ui: { issuesStatus: true } },
|
||||
{ cwd: tmpDir, sessionId, reason: "resume" },
|
||||
);
|
||||
|
||||
expect(issueStatuses(ctx).at(-1)).toBe("●1E");
|
||||
} finally {
|
||||
cleanup();
|
||||
}
|
||||
},
|
||||
INTEGRATION_TIMEOUT_MS,
|
||||
);
|
||||
|
||||
it(
|
||||
"dedupes identical consecutive text",
|
||||
async () => {
|
||||
const { tmpDir, cleanup } = setupTestEnvironment(
|
||||
"pi-lens-issues-dedupe-",
|
||||
);
|
||||
try {
|
||||
const ctx = await startSession(
|
||||
{ ui: { issuesStatus: true } },
|
||||
{ cwd: tmpDir },
|
||||
);
|
||||
const before = issueStatuses(ctx).length;
|
||||
recordDiagnostics(path.join(tmpDir, "dedupe.ts"), [
|
||||
{
|
||||
severity: "error",
|
||||
semantic: "blocking",
|
||||
message: "blocking",
|
||||
line: 1,
|
||||
rule: "typescript:1",
|
||||
},
|
||||
]);
|
||||
const afterFirst = issueStatuses(ctx);
|
||||
expect(afterFirst.at(-1)).toBe("●1E");
|
||||
expect(afterFirst.length).toBe(before + 1);
|
||||
|
||||
// An LSP-state mutation repaints the store without changing the
|
||||
// tallies; the identical text must not reach the host again.
|
||||
recordLsp("typescript", tmpDir, "spawn_success");
|
||||
expect(issueStatuses(ctx).length).toBe(afterFirst.length);
|
||||
} finally {
|
||||
cleanup();
|
||||
}
|
||||
},
|
||||
INTEGRATION_TIMEOUT_MS,
|
||||
);
|
||||
|
||||
it(
|
||||
"republishes after a session reset even when the text is unchanged",
|
||||
async () => {
|
||||
const { tmpDir, cleanup } = setupTestEnvironment("pi-lens-issues-reset-");
|
||||
try {
|
||||
_resetSessionLifecycleForTests();
|
||||
setGlobalConfig({ ui: { issuesStatus: true } });
|
||||
const pi = createPiMock();
|
||||
extension(pi.asExtensionAPI());
|
||||
|
||||
const first = makeCtx({
|
||||
cwd: tmpDir,
|
||||
sessionId: "issues-status-reset-1",
|
||||
});
|
||||
await pi.emit("session_start", { reason: "startup" }, first);
|
||||
expect(issueStatuses(first)).toEqual([undefined]);
|
||||
|
||||
// The host clears extension statuses on a session reset, so the
|
||||
// unchanged `undefined` still has to reach the new footer.
|
||||
await pi.emit("session_shutdown", { reason: "new" }, first);
|
||||
const second = makeCtx({
|
||||
cwd: tmpDir,
|
||||
sessionId: "issues-status-reset-2",
|
||||
});
|
||||
await pi.emit("session_start", { reason: "new" }, second);
|
||||
expect(issueStatuses(second)).toEqual([undefined]);
|
||||
} finally {
|
||||
cleanup();
|
||||
}
|
||||
},
|
||||
INTEGRATION_TIMEOUT_MS,
|
||||
);
|
||||
|
||||
it(
|
||||
"publishes in rpc mode",
|
||||
async () => {
|
||||
const { tmpDir, cleanup } = setupTestEnvironment("pi-lens-issues-rpc-");
|
||||
try {
|
||||
const ctx = await startSession(
|
||||
{ ui: { issuesStatus: true } },
|
||||
{ cwd: tmpDir, mode: "rpc" },
|
||||
);
|
||||
recordDiagnostics(path.join(tmpDir, "rpc.ts"), [
|
||||
{
|
||||
severity: "warning",
|
||||
message: "warning",
|
||||
line: 2,
|
||||
rule: "ts-react-antipatterns",
|
||||
},
|
||||
]);
|
||||
|
||||
expect(issueStatuses(ctx).at(-1)).toBe("!1W");
|
||||
} finally {
|
||||
cleanup();
|
||||
}
|
||||
},
|
||||
INTEGRATION_TIMEOUT_MS,
|
||||
);
|
||||
});
|
||||
@@ -30,8 +30,9 @@ export function aliveServerHolder(initialAliveIds: string[] = ["typescript"]) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Identity-theme `ctx.ui` double that records every `setStatus` call, plus a
|
||||
* `lspStatuses()` reader for the `pi-lens-lsp` writes only.
|
||||
* Identity-theme `ctx.ui` double that records every `setStatus` call, plus
|
||||
* `statusesFor(id)` for the writes to one key. `lspStatuses()` is the
|
||||
* `pi-lens-lsp` shorthand.
|
||||
*/
|
||||
export function lspStatusRecorder() {
|
||||
const statusUpdates: Array<[string, string | undefined]> = [];
|
||||
@@ -41,7 +42,8 @@ export function lspStatusRecorder() {
|
||||
statusUpdates.push([id, text]),
|
||||
theme: { fg: (_color: string, text: string) => text },
|
||||
};
|
||||
const lspStatuses = () =>
|
||||
statusUpdates.flatMap(([id, text]) => (id === "pi-lens-lsp" ? [text] : []));
|
||||
return { ui, lspStatuses };
|
||||
const statusesFor = (id: string) =>
|
||||
statusUpdates.flatMap(([key, text]) => (key === id ? [text] : []));
|
||||
const lspStatuses = () => statusesFor("pi-lens-lsp");
|
||||
return { ui, lspStatuses, statusesFor };
|
||||
}
|
||||
@@ -57,6 +57,10 @@ export const PI_MOCK_IMPORTERS: Readonly<Record<string, string>> = {
|
||||
"index-4504-opaque-prescan-root-witness.test.ts": "internal-seam",
|
||||
"index-drain-refresh-straddle.test.ts": "internal-seam",
|
||||
"index-integration.test.ts": "internal-seam",
|
||||
// Seeds the process-global widget store and the session sidecar that the
|
||||
// extension's adopt path reads, then observes the status port the factory
|
||||
// publishes through.
|
||||
"index-issues-status.test.ts": "internal-seam",
|
||||
"index-loop-block-wiring.test.ts": "internal-seam",
|
||||
"index-lsp-idle-reset.test.ts": "internal-seam",
|
||||
"index-lsp-config-root-eviction.test.ts": "internal-seam",
|
||||
|
||||
Reference in new issue
Block a user