Clean up remaining dead code and dependencies

- Replace unused 'codemirror' barrel dep with explicit @codemirror/{state,
  view,commands,language} sub-packages that were imported but unlisted
- Remove unused exports: writeNamespacedQuery, targetWorkspacePathForRun,
  isWorkspaceDeletionRun, piWebConfigDir, duplicate parsePiWebRuntimeResponse
- Remove unused types: WorkspacePanelFiles, WorkspacePanelHost,
  GetActiveSession, SaveAttachmentsResponse, QueryValues
- Drop now-unused re-exports/imports cascading from the above
- Add knip config + 'npm run knip' script for ongoing dead-code detection
This commit is contained in:
Federico Jaramillo Martinez
2026-06-13 21:57:51 +02:00
parent 5d335a7e72
commit edae57b836
11 changed files with 929 additions and 88 deletions
+17
View File
@@ -0,0 +1,17 @@
{
"$schema": "https://unpkg.com/knip@5/schema.json",
"entry": [
"src/cli.ts",
"src/plugin-api.ts",
"src/plugin-api/unstable.ts",
"extensions/pi-web.ts",
"pi-web-plugins/**/pi-web-plugin.ts",
"scripts/*.mjs"
],
"project": [
"src/**/*.ts",
"extensions/**/*.ts",
"pi-web-plugins/**/*.ts"
],
"ignoreExportsUsedInFile": true
}
+898 -27
View File
File diff suppressed because it is too large Load Diff
+10 -5
View File
@@ -32,6 +32,7 @@
"build:plugin-api": "tsc -p tsconfig.plugin-api.json",
"build:plugins": "tsc -p tsconfig.plugins.json && node scripts/build-plugins.mjs",
"typecheck": "tsc --noEmit",
"knip": "knip",
"lint": "eslint \"src/**/*.ts\" \"extensions/**/*.ts\" \"pi-web-plugins/**/*.ts\" vite.config.ts vitest.config.ts",
"test": "vitest run --config vitest.config.ts",
"verify": "npm run typecheck && npm run lint && npm test",
@@ -48,6 +49,7 @@
"changelog:status": "changeset status"
},
"dependencies": {
"@codemirror/commands": "^6.10.3",
"@codemirror/lang-css": "^6.3.1",
"@codemirror/lang-go": "^6.0.1",
"@codemirror/lang-html": "^6.4.11",
@@ -56,12 +58,14 @@
"@codemirror/lang-markdown": "^6.5.0",
"@codemirror/lang-python": "^6.2.1",
"@codemirror/lang-rust": "^6.0.2",
"@codemirror/language": "^6.12.3",
"@codemirror/legacy-modes": "^6.5.2",
"@codemirror/state": "^6.6.0",
"@codemirror/view": "^6.42.1",
"@fastify/static": "^9.1.3",
"@fastify/websocket": "^11.2.0",
"@xterm/addon-fit": "^0.11.0",
"@xterm/xterm": "^6.0.0",
"codemirror": "^6.0.2",
"diff": "^8.0.4",
"fastify": "^5.6.1",
"lit": "^3.3.1",
@@ -71,18 +75,19 @@
},
"devDependencies": {
"@changesets/cli": "^2.31.0",
"@earendil-works/pi-ai": "^0.79.1",
"@earendil-works/pi-coding-agent": "^0.79.1",
"@eslint/js": "^10.0.1",
"@types/node": "^24.10.1",
"@types/ws": "^8.18.1",
"eslint": "^10.3.0",
"globals": "^17.6.0",
"knip": "^6.16.1",
"tsx": "^4.20.6",
"typescript": "^5.9.3",
"typescript-eslint": "^8.59.2",
"vite": "^7.2.4",
"vitest": "^4.1.5",
"@earendil-works/pi-ai": "^0.79.1"
"vitest": "^4.1.5"
},
"publishConfig": {
"access": "public"
@@ -100,8 +105,8 @@
"homepage": "https://pi-web.dev/",
"packageManager": "[email protected]",
"peerDependencies": {
"@earendil-works/pi-coding-agent": ">=0.78.0 <1",
"@earendil-works/pi-ai": ">=0.78.0 <1"
"@earendil-works/pi-ai": ">=0.78.0 <1",
"@earendil-works/pi-coding-agent": ">=0.78.0 <1"
},
"keywords": [
"pi-package",
-19
View File
@@ -1,5 +1,4 @@
export type QueryValue = string | number | boolean | readonly (string | number | boolean)[];
export type QueryValues = Record<string, QueryValue | undefined | null>;
export function queryNamespace(contributionId: string): string {
return contributionId.replaceAll(":", ".");
@@ -26,24 +25,6 @@ export function readNamespacedString(namespace: string, key: string): string | u
return value === "" ? undefined : value;
}
export function writeNamespacedQuery(namespace: string, values: QueryValues, options?: { replace?: boolean | undefined }): void {
const url = new URL(window.location.href);
const prefix = `${namespace}--`;
for (const key of Array.from(url.searchParams.keys())) {
if (key.startsWith(prefix)) url.searchParams.delete(key);
}
for (const [key, value] of Object.entries(values)) {
if (value === undefined || value === null || value === "") continue;
const namespacedKey = `${prefix}${key}`;
if (Array.isArray(value)) {
for (const item of value) url.searchParams.append(namespacedKey, String(item));
} else {
url.searchParams.set(namespacedKey, String(value));
}
}
commitUrl(url, options);
}
export function setNamespacedQueryKey(namespace: string, key: string, value: QueryValue | undefined | null, options?: { replace?: boolean | undefined }): void {
const url = new URL(window.location.href);
const namespacedKey = `${namespace}--${key}`;
-4
View File
@@ -52,14 +52,10 @@ export interface WorkspaceFiles {
readFile(path: string): Promise<FileContentResponse>;
}
export type WorkspacePanelFiles = WorkspaceFiles;
export interface WorkspaceHost {
requestRender(): void;
}
export type WorkspacePanelHost = WorkspaceHost;
export interface WorkspaceContext {
machine: PluginMachine;
workspace: Workspace;
+2 -9
View File
@@ -1,8 +1,8 @@
import { workspaceDeleteOperation, workspaceDeleteOperationMetadataKey, targetWorkspaceIdMetadataKey, targetWorkspacePathMetadataKey } from "../../shared/workspaceDeletion";
import { workspaceDeleteOperation, workspaceDeleteOperationMetadataKey, targetWorkspaceIdMetadataKey } from "../../shared/workspaceDeletion";
import type { AppState } from "./appState";
import type { TerminalCommandRun, Workspace } from "./api";
export { targetWorkspaceIdMetadataKey, targetWorkspacePathMetadataKey, workspaceDeleteOperation, workspaceDeleteOperationMetadataKey, workspaceDeletionMetadata } from "../../shared/workspaceDeletion";
export { targetWorkspaceIdMetadataKey, workspaceDeleteOperation, workspaceDeleteOperationMetadataKey, workspaceDeletionMetadata } from "../../shared/workspaceDeletion";
export function workspaceDeletionRunFilter(projectId?: string): { projectId?: string; metadata: Record<string, string> } {
return {
@@ -38,14 +38,7 @@ export function targetWorkspaceIdForRun(run: TerminalCommandRun): string | undef
return run.metadata[targetWorkspaceIdMetadataKey];
}
export function targetWorkspacePathForRun(run: TerminalCommandRun): string | undefined {
return run.metadata[targetWorkspacePathMetadataKey];
}
export function isWorkspaceDeletionRunPending(run: TerminalCommandRun): boolean {
return run.status === "queued" || run.status === "running";
}
export function isWorkspaceDeletionRun(run: TerminalCommandRun): boolean {
return run.metadata[workspaceDeleteOperationMetadataKey] === workspaceDeleteOperation;
}
-3
View File
@@ -197,6 +197,3 @@ export function examplePiWebConfig(config: PiWebConfig = {}): string {
return `${JSON.stringify({ host: config.host ?? "127.0.0.1", port: config.port ?? 8504, allowedHosts: config.allowedHosts ?? [] }, null, 2)}\n`;
}
export function piWebConfigDir(env: NodeJS.ProcessEnv = process.env): string {
return dirname(defaultPiWebConfigPath(env));
}
@@ -2,5 +2,3 @@ export interface ActiveSession<TRuntime> {
runtime: TRuntime;
unsubscribe: () => void;
}
export type GetActiveSession<TRuntime> = (sessionId: string) => Promise<ActiveSession<TRuntime>>;
-4
View File
@@ -175,10 +175,6 @@ export interface SavedPromptAttachment {
size: number;
}
export interface SaveAttachmentsResponse {
attachments: SavedPromptAttachment[];
}
export interface SessionModel {
provider?: string;
id?: string;
+1 -14
View File
@@ -1,4 +1,4 @@
import type { PiWebCapability, PiWebComponentStatus, PiWebInstallationInfo, PiWebRuntimeComponent, PiWebRuntimeResponse, PiWebVersionResponse } from "./apiTypes.js";
import type { PiWebCapability, PiWebComponentStatus, PiWebInstallationInfo, PiWebRuntimeComponent, PiWebVersionResponse } from "./apiTypes.js";
import { isPiWebCapability } from "./capabilities.js";
export function parsePiWebVersionResponse(value: unknown): PiWebVersionResponse | undefined {
@@ -13,19 +13,6 @@ export function parsePiWebVersionResponse(value: unknown): PiWebVersionResponse
return { packageName, generatedAt, components: { web, sessiond } };
}
export function parsePiWebRuntimeResponse(value: unknown): PiWebRuntimeResponse | undefined {
if (!isRecord(value)) return undefined;
const packageName = value["packageName"];
const generatedAt = value["generatedAt"];
const components = value["components"];
if (typeof packageName !== "string" || packageName === "" || typeof generatedAt !== "string" || generatedAt === "" || !isRecord(components)) return undefined;
const web = parsePiWebRuntimeComponent(components["web"]);
const sessiond = parsePiWebRuntimeComponent(components["sessiond"]);
const capabilities = parsePiWebCapabilities(value["capabilities"]);
if (web === undefined || sessiond === undefined || capabilities === undefined) return undefined;
return { packageName, generatedAt, components: { web, sessiond }, capabilities };
}
export function parsePiWebRuntimeComponent(value: unknown): PiWebRuntimeComponent | undefined {
if (!isRecord(value)) return undefined;
const component = value["component"];
+1 -1
View File
@@ -1,7 +1,7 @@
export const workspaceDeleteOperation = "workspace.delete";
export const workspaceDeleteOperationMetadataKey = "pi.operation";
export const targetWorkspaceIdMetadataKey = "target.workspaceId";
export const targetWorkspacePathMetadataKey = "target.workspacePath";
const targetWorkspacePathMetadataKey = "target.workspacePath";
export interface WorkspaceDeletionTarget {
id: string;