fix: remove inline imports and debug logging

- Convert all inline import() types to top-level imports
- Remove debug console.error statements from plan-mode hook
This commit is contained in:
Helmut Januschka 2026-01-03 22:36:44 +01:00 committed by Mario Zechner
parent a169029a16
commit 277d7bd83b
4 changed files with 14 additions and 25 deletions

View file

@ -12,7 +12,7 @@ import { getAgentDir } from "../../config.js";
import type { HookMessage } from "../messages.js";
import type { SessionManager } from "../session-manager.js";
import { execCommand } from "./runner.js";
import type { ExecOptions, HookAPI, HookFactory, HookMessageRenderer, RegisteredCommand } from "./types.js";
import type { ExecOptions, HookAPI, HookContext, HookFactory, HookMessageRenderer, RegisteredCommand } from "./types.js";
// Create require function to resolve module paths at runtime
const require = createRequire(import.meta.url);
@ -101,7 +101,7 @@ export interface HookShortcut {
/** Description for help */
description?: string;
/** Handler function */
handler: (ctx: import("./types.js").HookContext) => Promise<void> | void;
handler: (ctx: HookContext) => Promise<void> | void;
/** Hook path that registered this shortcut */
hookPath: string;
}
@ -296,7 +296,7 @@ function createHookAPI(
shortcut: string,
options: {
description?: string;
handler: (ctx: import("./types.js").HookContext) => Promise<void> | void;
handler: (ctx: HookContext) => Promise<void> | void;
},
): void {
shortcuts.set(shortcut, { shortcut, hookPath, ...options });

View file

@ -3,13 +3,15 @@
*/
import type { AgentMessage } from "@mariozechner/pi-agent-core";
import type { Model } from "@mariozechner/pi-ai";
import type { ImageContent, Model } from "@mariozechner/pi-ai";
import { theme } from "../../modes/interactive/theme/theme.js";
import type { ModelRegistry } from "../model-registry.js";
import type { SessionManager } from "../session-manager.js";
import type {
AppendEntryHandler,
BranchHandler,
HookFlag,
HookShortcut,
LoadedHook,
NavigateTreeHandler,
NewSessionHandler,
@ -176,8 +178,8 @@ export class HookRunner {
/**
* Get all CLI flags registered by hooks.
*/
getFlags(): Map<string, import("./loader.js").HookFlag> {
const allFlags = new Map<string, import("./loader.js").HookFlag>();
getFlags(): Map<string, HookFlag> {
const allFlags = new Map<string, HookFlag>();
for (const hook of this.hooks) {
for (const [name, flag] of hook.flags) {
allFlags.set(name, flag);
@ -221,8 +223,8 @@ export class HookRunner {
* Conflicts with built-in shortcuts are skipped with a warning.
* Conflicts between hooks are logged as warnings.
*/
getShortcuts(): Map<string, import("./loader.js").HookShortcut> {
const allShortcuts = new Map<string, import("./loader.js").HookShortcut>();
getShortcuts(): Map<string, HookShortcut> {
const allShortcuts = new Map<string, HookShortcut>();
for (const hook of this.hooks) {
for (const [key, shortcut] of hook.shortcuts) {
const normalizedKey = key.toLowerCase();
@ -486,7 +488,7 @@ export class HookRunner {
*/
async emitBeforeAgentStart(
prompt: string,
images?: import("@mariozechner/pi-ai").ImageContent[],
images?: ImageContent[],
): Promise<BeforeAgentStartEventResult | undefined> {
const ctx = this.createContext();
let result: BeforeAgentStartEventResult | undefined;

View file

@ -31,7 +31,7 @@ import { exec, spawn, spawnSync } from "child_process";
import { APP_NAME, getAuthPath, getDebugLogPath } from "../../config.js";
import type { AgentSession, AgentSessionEvent } from "../../core/agent-session.js";
import type { CustomToolSessionEvent, LoadedCustomTool } from "../../core/custom-tools/index.js";
import type { HookUIContext } from "../../core/hooks/index.js";
import type { HookContext, HookRunner, HookUIContext } from "../../core/hooks/index.js";
import { KeybindingsManager } from "../../core/keybindings.js";
import { createCompactionSummaryMessage } from "../../core/messages.js";
import { type SessionContext, SessionManager } from "../../core/session-manager.js";
@ -581,12 +581,12 @@ export class InteractiveMode {
/**
* Set up keyboard shortcuts registered by hooks.
*/
private setupHookShortcuts(hookRunner: import("../../core/hooks/index.js").HookRunner): void {
private setupHookShortcuts(hookRunner: HookRunner): void {
const shortcuts = hookRunner.getShortcuts();
if (shortcuts.size === 0) return;
// Create a context for shortcut handlers
const createContext = (): import("../../core/hooks/types.js").HookContext => ({
const createContext = (): HookContext => ({
ui: this.createHookUIContext(),
hasUI: true,
cwd: process.cwd(),