feat: tsconfig.json + npm run typecheck

- tsconfig.json simulates pi's ESM TypeScript runtime
- Resolves peer deps from pi's global node_modules
- 'type: module' added to package.json (correct — pi loads as ESM)
- Fixes found by tsc:
  - buffer/writer.ts: correct Dirent import from node:fs
  - messages.ts: toolCall id/name may be undefined, default to empty string
- Remaining warnings: pi event API names (session_switch etc.) not in types;
  these are guarded with try/catch at runtime — acceptable
- npm run typecheck: tsc --noEmit
This commit is contained in:
Johannes Merz 2026-05-16 03:08:02 +02:00
parent 920f6d8fc3
commit 38cad794e2
5 changed files with 67 additions and 5 deletions

View File

@ -17,6 +17,7 @@
*/
import fs from "node:fs/promises";
import type { Dirent } from "node:fs";
import os from "node:os";
import path from "node:path";
import type { SeqNum } from "../sequence.js";
@ -165,7 +166,7 @@ export async function cleanupIdleBuffers(
const maxIdleMs = cfg.idleDays * 24 * 60 * 60 * 1000;
const deleted: string[] = [];
let entries: fs.Dirent[] = [];
let entries: Dirent[] = [];
try {
entries = await fs.readdir(dir, { withFileTypes: true });
} catch {

View File

@ -58,8 +58,8 @@ export function serializeMessage(
const toolCalls = (msg.content as RawContent[])
.filter((c) => c.type === "toolCall")
.map((c) => ({
id: c.id,
name: c.name,
id: c.id ?? "",
name: c.name ?? "",
args: JSON.stringify(c.arguments, null, 2),
}));
return {

17
package-lock.json generated
View File

@ -15,7 +15,8 @@
"devDependencies": {
"@biomejs/biome": "^2.4.12",
"@types/qrcode": "^1.5.6",
"husky": "^9.1.7"
"husky": "^9.1.7",
"typescript": "^6.0.3"
},
"peerDependencies": {
"@earendil-works/pi-coding-agent": "*",
@ -3970,6 +3971,20 @@
"license": "MIT",
"peer": true
},
"node_modules/typescript": {
"version": "6.0.3",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-6.0.3.tgz",
"integrity": "sha512-y2TvuxSZPDyQakkFRPZHKFm+KKVqIisdg9/CZwm9ftvKXLP8NRWj38/ODjNbr43SsoXqNuAisEf1GdCxqWcdBw==",
"dev": true,
"license": "Apache-2.0",
"bin": {
"tsc": "bin/tsc",
"tsserver": "bin/tsserver"
},
"engines": {
"node": ">=14.17"
}
},
"node_modules/uint8array-extras": {
"version": "1.5.0",
"resolved": "https://registry.npmjs.org/uint8array-extras/-/uint8array-extras-1.5.0.tgz",

View File

@ -1,5 +1,6 @@
{
"name": "pi-remote-control",
"type": "module",
"version": "1.0.0",
"description": "Expose a running pi session over HTTP/WebSocket — view and interact from any browser on your network.",
"keywords": [
@ -18,6 +19,7 @@
"lint": "biome check --write .",
"lint:check": "biome check .",
"prepare": "node .husky/install.mjs",
"typecheck": "tsc --noEmit",
"smoke": "node --test scripts/smoke/smoke.mjs",
"smoke:stream": "node --test scripts/smoke/stream.test.mjs",
"smoke:all": "node --test scripts/smoke/smoke.mjs scripts/smoke/stream.test.mjs"
@ -25,6 +27,7 @@
"devDependencies": {
"@biomejs/biome": "^2.4.12",
"@types/qrcode": "^1.5.6",
"husky": "^9.1.7"
"husky": "^9.1.7",
"typescript": "^6.0.3"
}
}

43
tsconfig.json Normal file
View File

@ -0,0 +1,43 @@
{
"compilerOptions": {
// Simulate pi's TypeScript runtime environment
"target": "ES2022",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"lib": ["ES2022"],
// Type-check only, no emit pi handles the actual transpilation
"noEmit": true,
"strict": true,
"exactOptionalPropertyTypes": false,
// Resolve peer deps from pi's global node_modules
"baseUrl": ".",
"paths": {
"@earendil-works/pi-coding-agent": [
"../../../../../../usr/local/lib/node_modules/@earendil-works/pi-coding-agent/dist/index.d.ts"
],
"@earendil-works/pi-tui": [
"../../../../../../usr/local/lib/node_modules/@earendil-works/pi-tui/dist/index.d.ts"
]
},
"typeRoots": [
"./node_modules/@types",
"/usr/local/lib/node_modules/@types"
],
// Project uses .js extensions in imports (NodeNext convention)
"allowImportingTsExtensions": false,
// Relax some checks that are impractical without the real pi runtime
"skipLibCheck": true,
"ignoreDeprecations": "6.0"
},
"include": [
"extensions/remote-control/**/*.ts"
],
"exclude": [
"node_modules",
"build"
]
}