mirror of
https://github.com/earendil-works/pi.git
synced 2026-06-18 15:54:04 +08:00
chore: enforce erasable TypeScript syntax
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
- Check node_modules for external API type definitions instead of guessing
|
||||
- **NEVER use inline imports** - no `await import("./foo.js")`, no `import("pkg").Type` in type positions, no dynamic imports for types. Always use standard top-level imports.
|
||||
- NEVER remove or downgrade code to fix type errors from outdated dependencies; upgrade the dependency instead
|
||||
- In core source packages (`packages/ai/src`, `packages/agent/src`, `packages/coding-agent/src`), use only erasable TypeScript syntax compatible with Node strip-only mode. Do not use constructor parameter properties, `enum`, `namespace`/`module`, `import =`, `export =`, or other TypeScript constructs that require JavaScript emit. Use explicit fields and constructor assignments instead of parameter properties.
|
||||
- Always ask before removing functionality or code that appears to be intentional
|
||||
- Do not preserve backward compatibility unless the user explicitly asks for it
|
||||
- Never hardcode key checks with, eg. `matchesKey(keyData, "ctrl+x")`. All keybindings must be configurable. Add default to matching object (`DEFAULT_EDITOR_KEYBINDINGS` or `DEFAULT_APP_KEYBINDINGS`)
|
||||
|
||||
+2
-1
@@ -15,7 +15,8 @@
|
||||
"build": "cd packages/tui && npm run build && cd ../ai && npm run build && cd ../agent && npm run build && cd ../coding-agent && npm run build && cd ../web-ui && npm run build",
|
||||
"dev": "concurrently --names \"ai,agent,coding-agent,web-ui,tui\" --prefix-colors \"cyan,yellow,red,green,magenta\" \"cd packages/ai && npm run dev\" \"cd packages/agent && npm run dev\" \"cd packages/coding-agent && npm run dev\" \"cd packages/web-ui && npm run dev\" \"cd packages/tui && npm run dev\"",
|
||||
"dev:tsc": "concurrently --names \"ai,web-ui\" --prefix-colors \"cyan,green\" \"cd packages/ai && npm run dev:tsc\" \"cd packages/web-ui && npm run dev:tsc\"",
|
||||
"check": "biome check --write --error-on-warnings . && tsgo --noEmit && npm run check:browser-smoke && cd packages/web-ui && npm run check",
|
||||
"check": "biome check --write --error-on-warnings . && tsgo --noEmit && npm run check:erasable-types && npm run check:browser-smoke && cd packages/web-ui && npm run check",
|
||||
"check:erasable-types": "tsgo -p packages/ai/tsconfig.build.json --noEmit --erasableSyntaxOnly && tsgo -p packages/agent/tsconfig.build.json --noEmit --erasableSyntaxOnly && tsgo -p packages/coding-agent/tsconfig.build.json --noEmit --erasableSyntaxOnly",
|
||||
"check:browser-smoke": "node scripts/check-browser-smoke.mjs",
|
||||
"profile:tui": "node scripts/profile-coding-agent-node.mjs --mode tui",
|
||||
"profile:rpc": "node scripts/profile-coding-agent-node.mjs --mode rpc",
|
||||
|
||||
@@ -2,6 +2,10 @@
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
### Changed
|
||||
|
||||
- Changed source syntax to avoid TypeScript constructs that require JavaScript emit, keeping the package compatible with Node.js strip-only TypeScript checks.
|
||||
|
||||
### Fixed
|
||||
|
||||
- Fixed tool-call preflight to stop preparing sibling tool calls after the run is aborted ([#4276](https://github.com/earendil-works/pi/issues/4276)).
|
||||
|
||||
@@ -117,8 +117,11 @@ export interface AgentOptions {
|
||||
|
||||
class PendingMessageQueue {
|
||||
private messages: AgentMessage[] = [];
|
||||
public mode: QueueMode;
|
||||
|
||||
constructor(public mode: QueueMode) {}
|
||||
constructor(mode: QueueMode) {
|
||||
this.mode = mode;
|
||||
}
|
||||
|
||||
enqueue(message: AgentMessage): void {
|
||||
this.messages.push(message);
|
||||
|
||||
@@ -120,16 +120,16 @@ export type FileErrorCode =
|
||||
|
||||
/** Error returned by {@link FileSystem} file operations. */
|
||||
export class FileError extends Error {
|
||||
constructor(
|
||||
/** Backend-independent error code. */
|
||||
public code: FileErrorCode,
|
||||
message: string,
|
||||
/** Absolute addressed path associated with the failure, when available. */
|
||||
public path?: string,
|
||||
cause?: Error,
|
||||
) {
|
||||
/** Backend-independent error code. */
|
||||
public code: FileErrorCode;
|
||||
/** Absolute addressed path associated with the failure, when available. */
|
||||
public path?: string;
|
||||
|
||||
constructor(code: FileErrorCode, message: string, path?: string, cause?: Error) {
|
||||
super(message, cause === undefined ? undefined : { cause });
|
||||
this.name = "FileError";
|
||||
this.code = code;
|
||||
this.path = path;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -144,14 +144,13 @@ export type ExecutionErrorCode =
|
||||
|
||||
/** Error returned by {@link ExecutionEnv.exec}. */
|
||||
export class ExecutionError extends Error {
|
||||
constructor(
|
||||
/** Backend-independent error code. */
|
||||
public code: ExecutionErrorCode,
|
||||
message: string,
|
||||
cause?: Error,
|
||||
) {
|
||||
/** Backend-independent error code. */
|
||||
public code: ExecutionErrorCode;
|
||||
|
||||
constructor(code: ExecutionErrorCode, message: string, cause?: Error) {
|
||||
super(message, cause === undefined ? undefined : { cause });
|
||||
this.name = "ExecutionError";
|
||||
this.code = code;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -160,14 +159,13 @@ export type CompactionErrorCode = "aborted" | "summarization_failed" | "invalid_
|
||||
|
||||
/** Error returned by compaction helpers. */
|
||||
export class CompactionError extends Error {
|
||||
constructor(
|
||||
/** Backend-independent error code. */
|
||||
public code: CompactionErrorCode,
|
||||
message: string,
|
||||
cause?: Error,
|
||||
) {
|
||||
/** Backend-independent error code. */
|
||||
public code: CompactionErrorCode;
|
||||
|
||||
constructor(code: CompactionErrorCode, message: string, cause?: Error) {
|
||||
super(message, cause === undefined ? undefined : { cause });
|
||||
this.name = "CompactionError";
|
||||
this.code = code;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -176,14 +174,13 @@ export type BranchSummaryErrorCode = "aborted" | "summarization_failed" | "inval
|
||||
|
||||
/** Error returned by branch summarization helpers. */
|
||||
export class BranchSummaryError extends Error {
|
||||
constructor(
|
||||
/** Backend-independent error code. */
|
||||
public code: BranchSummaryErrorCode,
|
||||
message: string,
|
||||
cause?: Error,
|
||||
) {
|
||||
/** Backend-independent error code. */
|
||||
public code: BranchSummaryErrorCode;
|
||||
|
||||
constructor(code: BranchSummaryErrorCode, message: string, cause?: Error) {
|
||||
super(message, cause === undefined ? undefined : { cause });
|
||||
this.name = "BranchSummaryError";
|
||||
this.code = code;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -197,14 +194,13 @@ export type SessionErrorCode =
|
||||
|
||||
/** Error thrown by session storage, repositories, and session tree operations. */
|
||||
export class SessionError extends Error {
|
||||
constructor(
|
||||
/** Session subsystem error code. */
|
||||
public code: SessionErrorCode,
|
||||
message: string,
|
||||
cause?: Error,
|
||||
) {
|
||||
/** Session subsystem error code. */
|
||||
public code: SessionErrorCode;
|
||||
|
||||
constructor(code: SessionErrorCode, message: string, cause?: Error) {
|
||||
super(message, cause === undefined ? undefined : { cause });
|
||||
this.name = "SessionError";
|
||||
this.code = code;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -221,13 +217,12 @@ export type AgentHarnessErrorCode =
|
||||
|
||||
/** Public AgentHarness failure with a stable top-level classification. */
|
||||
export class AgentHarnessError extends Error {
|
||||
constructor(
|
||||
public code: AgentHarnessErrorCode,
|
||||
message: string,
|
||||
cause?: Error,
|
||||
) {
|
||||
public code: AgentHarnessErrorCode;
|
||||
|
||||
constructor(code: AgentHarnessErrorCode, message: string, cause?: Error) {
|
||||
super(message, cause === undefined ? undefined : { cause });
|
||||
this.name = "AgentHarnessError";
|
||||
this.code = code;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,10 @@
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
### Changed
|
||||
|
||||
- Changed source syntax to avoid TypeScript constructs that require JavaScript emit, keeping the package compatible with Node.js strip-only TypeScript checks.
|
||||
|
||||
### Fixed
|
||||
|
||||
- Fixed OpenAI-compatible `streamSimple()` requests to stop sending model-derived default output token caps, avoiding context-window reservation failures on servers such as vLLM while preserving explicit `maxTokens` and required Anthropic `max_tokens` handling ([#4675](https://github.com/earendil-works/pi/issues/4675)).
|
||||
|
||||
@@ -7,11 +7,12 @@ export class EventStream<T, R = T> implements AsyncIterable<T> {
|
||||
private done = false;
|
||||
private finalResultPromise: Promise<R>;
|
||||
private resolveFinalResult!: (result: R) => void;
|
||||
private isComplete: (event: T) => boolean;
|
||||
private extractResult: (event: T) => R;
|
||||
|
||||
constructor(
|
||||
private isComplete: (event: T) => boolean,
|
||||
private extractResult: (event: T) => R,
|
||||
) {
|
||||
constructor(isComplete: (event: T) => boolean, extractResult: (event: T) => R) {
|
||||
this.isComplete = isComplete;
|
||||
this.extractResult = extractResult;
|
||||
this.finalResultPromise = new Promise((resolve) => {
|
||||
this.resolveFinalResult = resolve;
|
||||
});
|
||||
|
||||
@@ -2,6 +2,10 @@
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
### Changed
|
||||
|
||||
- Changed source syntax to avoid TypeScript constructs that require JavaScript emit, keeping core sources compatible with Node.js strip-only TypeScript checks.
|
||||
|
||||
### Fixed
|
||||
|
||||
- Fixed the system prompt to tell models to resolve pi docs and examples under the absolute package paths before reading topic-specific relative references ([#4752](https://github.com/earendil-works/pi/issues/4752)).
|
||||
|
||||
@@ -67,14 +67,25 @@ function extractUserMessageText(content: string | Array<{ type: string; text?: s
|
||||
export class AgentSessionRuntime {
|
||||
private rebindSession?: (session: AgentSession) => Promise<void>;
|
||||
private beforeSessionInvalidate?: () => void;
|
||||
private _session: AgentSession;
|
||||
private _services: AgentSessionServices;
|
||||
private readonly createRuntime: CreateAgentSessionRuntimeFactory;
|
||||
private _diagnostics: AgentSessionRuntimeDiagnostic[];
|
||||
private _modelFallbackMessage?: string;
|
||||
|
||||
constructor(
|
||||
private _session: AgentSession,
|
||||
private _services: AgentSessionServices,
|
||||
private readonly createRuntime: CreateAgentSessionRuntimeFactory,
|
||||
private _diagnostics: AgentSessionRuntimeDiagnostic[] = [],
|
||||
private _modelFallbackMessage?: string,
|
||||
) {}
|
||||
_session: AgentSession,
|
||||
_services: AgentSessionServices,
|
||||
createRuntime: CreateAgentSessionRuntimeFactory,
|
||||
_diagnostics: AgentSessionRuntimeDiagnostic[] = [],
|
||||
_modelFallbackMessage?: string,
|
||||
) {
|
||||
this._session = _session;
|
||||
this._services = _services;
|
||||
this.createRuntime = createRuntime;
|
||||
this._diagnostics = _diagnostics;
|
||||
this._modelFallbackMessage = _modelFallbackMessage;
|
||||
}
|
||||
|
||||
get services(): AgentSessionServices {
|
||||
return this._services;
|
||||
|
||||
@@ -50,7 +50,11 @@ export interface AuthStorageBackend {
|
||||
}
|
||||
|
||||
export class FileAuthStorageBackend implements AuthStorageBackend {
|
||||
constructor(private authPath: string = join(getAgentDir(), "auth.json")) {}
|
||||
private authPath: string;
|
||||
|
||||
constructor(authPath: string = join(getAgentDir(), "auth.json")) {
|
||||
this.authPath = authPath;
|
||||
}
|
||||
|
||||
private ensureParentDir(): void {
|
||||
const dir = dirname(this.authPath);
|
||||
@@ -194,8 +198,10 @@ export class AuthStorage {
|
||||
private fallbackResolver?: (provider: string) => string | undefined;
|
||||
private loadError: Error | null = null;
|
||||
private errors: Error[] = [];
|
||||
private storage: AuthStorageBackend;
|
||||
|
||||
private constructor(private storage: AuthStorageBackend) {
|
||||
private constructor(storage: AuthStorageBackend) {
|
||||
this.storage = storage;
|
||||
this.reload();
|
||||
}
|
||||
|
||||
|
||||
@@ -334,11 +334,12 @@ export class ModelRegistry {
|
||||
private modelRequestHeaders: Map<string, Record<string, string>> = new Map();
|
||||
private registeredProviders: Map<string, ProviderConfigInput> = new Map();
|
||||
private loadError: string | undefined = undefined;
|
||||
readonly authStorage: AuthStorage;
|
||||
private modelsJsonPath: string | undefined;
|
||||
|
||||
private constructor(
|
||||
readonly authStorage: AuthStorage,
|
||||
private modelsJsonPath: string | undefined,
|
||||
) {
|
||||
private constructor(authStorage: AuthStorage, modelsJsonPath: string | undefined) {
|
||||
this.authStorage = authStorage;
|
||||
this.modelsJsonPath = modelsJsonPath;
|
||||
this.loadModels();
|
||||
}
|
||||
|
||||
|
||||
@@ -7,13 +7,14 @@ import type { TUI } from "@earendil-works/pi-tui";
|
||||
export class CountdownTimer {
|
||||
private intervalId: ReturnType<typeof setInterval> | undefined;
|
||||
private remainingSeconds: number;
|
||||
private tui: TUI | undefined;
|
||||
private onTick: (seconds: number) => void;
|
||||
private onExpire: () => void;
|
||||
|
||||
constructor(
|
||||
timeoutMs: number,
|
||||
private tui: TUI | undefined,
|
||||
private onTick: (seconds: number) => void,
|
||||
private onExpire: () => void,
|
||||
) {
|
||||
constructor(timeoutMs: number, tui: TUI | undefined, onTick: (seconds: number) => void, onExpire: () => void) {
|
||||
this.tui = tui;
|
||||
this.onTick = onTick;
|
||||
this.onExpire = onExpire;
|
||||
this.remainingSeconds = Math.ceil(timeoutMs / 1000);
|
||||
this.onTick(this.remainingSeconds);
|
||||
|
||||
|
||||
@@ -32,11 +32,13 @@ function formatTokens(count: number): string {
|
||||
*/
|
||||
export class FooterComponent implements Component {
|
||||
private autoCompactEnabled = true;
|
||||
private session: AgentSession;
|
||||
private footerData: ReadonlyFooterDataProvider;
|
||||
|
||||
constructor(
|
||||
private session: AgentSession,
|
||||
private footerData: ReadonlyFooterDataProvider,
|
||||
) {}
|
||||
constructor(session: AgentSession, footerData: ReadonlyFooterDataProvider) {
|
||||
this.session = session;
|
||||
this.footerData = footerData;
|
||||
}
|
||||
|
||||
setSession(session: AgentSession): void {
|
||||
this.session = session;
|
||||
|
||||
@@ -15,6 +15,7 @@ export class LoginDialogComponent extends Container implements Focusable {
|
||||
private abortController = new AbortController();
|
||||
private inputResolver?: (value: string) => void;
|
||||
private inputRejecter?: (error: Error) => void;
|
||||
private onComplete: (success: boolean, message?: string) => void;
|
||||
|
||||
// Focusable implementation - propagate to input for IME cursor positioning
|
||||
private _focused = false;
|
||||
@@ -29,12 +30,13 @@ export class LoginDialogComponent extends Container implements Focusable {
|
||||
constructor(
|
||||
tui: TUI,
|
||||
providerId: string,
|
||||
private onComplete: (success: boolean, message?: string) => void,
|
||||
onComplete: (success: boolean, message?: string) => void,
|
||||
providerNameOverride?: string,
|
||||
titleOverride?: string,
|
||||
) {
|
||||
super();
|
||||
this.tui = tui;
|
||||
this.onComplete = onComplete;
|
||||
|
||||
const providerInfo = getOAuthProviders().find((p) => p.id === providerId);
|
||||
const providerName = providerNameOverride || providerInfo?.name || providerId;
|
||||
|
||||
@@ -1056,7 +1056,11 @@ class TreeList implements Component {
|
||||
|
||||
/** Component that displays the current search query */
|
||||
class SearchLine implements Component {
|
||||
constructor(private treeList: TreeList) {}
|
||||
private treeList: TreeList;
|
||||
|
||||
constructor(treeList: TreeList) {
|
||||
this.treeList = treeList;
|
||||
}
|
||||
|
||||
invalidate(): void {}
|
||||
|
||||
|
||||
@@ -147,14 +147,19 @@ function isExpandable(obj: unknown): obj is Expandable {
|
||||
}
|
||||
|
||||
class ExpandableText extends Text implements Expandable {
|
||||
private readonly getCollapsedText: () => string;
|
||||
private readonly getExpandedText: () => string;
|
||||
|
||||
constructor(
|
||||
private readonly getCollapsedText: () => string,
|
||||
private readonly getExpandedText: () => string,
|
||||
getCollapsedText: () => string,
|
||||
getExpandedText: () => string,
|
||||
expanded = false,
|
||||
paddingX = 0,
|
||||
paddingY = 0,
|
||||
) {
|
||||
super(expanded ? getExpandedText() : getCollapsedText(), paddingX, paddingY);
|
||||
this.getCollapsedText = getCollapsedText;
|
||||
this.getExpandedText = getExpandedText;
|
||||
}
|
||||
|
||||
setExpanded(expanded: boolean): void {
|
||||
@@ -334,6 +339,8 @@ export class InteractiveMode {
|
||||
// Custom header from extension (undefined = use built-in header)
|
||||
private customHeader: (Component & { dispose?(): void }) | undefined = undefined;
|
||||
|
||||
private options: InteractiveModeOptions;
|
||||
|
||||
// Convenience accessors
|
||||
private get session(): AgentSession {
|
||||
return this.runtimeHost.session;
|
||||
@@ -348,11 +355,9 @@ export class InteractiveMode {
|
||||
return this.session.settingsManager;
|
||||
}
|
||||
|
||||
constructor(
|
||||
runtimeHost: AgentSessionRuntime,
|
||||
private options: InteractiveModeOptions = {},
|
||||
) {
|
||||
constructor(runtimeHost: AgentSessionRuntime, options: InteractiveModeOptions = {}) {
|
||||
this.runtimeHost = runtimeHost;
|
||||
this.options = options;
|
||||
this.runtimeHost.setBeforeSessionInvalidate(() => {
|
||||
this.resetExtensionUI();
|
||||
});
|
||||
|
||||
@@ -59,8 +59,11 @@ export class RpcClient {
|
||||
new Map();
|
||||
private requestId = 0;
|
||||
private stderr = "";
|
||||
private options: RpcClientOptions;
|
||||
|
||||
constructor(private options: RpcClientOptions = {}) {}
|
||||
constructor(options: RpcClientOptions = {}) {
|
||||
this.options = options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Start the RPC agent process.
|
||||
|
||||
Reference in New Issue
Block a user