From 277d7bd83b1fd0a410ff68f4dde7ffa73609ebb3 Mon Sep 17 00:00:00 2001 From: Helmut Januschka Date: Sat, 3 Jan 2026 22:36:44 +0100 Subject: [PATCH] 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 --- packages/coding-agent/examples/hooks/plan-mode.ts | 13 ------------- packages/coding-agent/src/core/hooks/loader.ts | 6 +++--- packages/coding-agent/src/core/hooks/runner.ts | 14 ++++++++------ .../src/modes/interactive/interactive-mode.ts | 6 +++--- 4 files changed, 14 insertions(+), 25 deletions(-) diff --git a/packages/coding-agent/examples/hooks/plan-mode.ts b/packages/coding-agent/examples/hooks/plan-mode.ts index 5eacaeae..e1d5961f 100644 --- a/packages/coding-agent/examples/hooks/plan-mode.ts +++ b/packages/coding-agent/examples/hooks/plan-mode.ts @@ -322,7 +322,6 @@ export default function planModeHook(pi: HookAPI) { const nextStep = todoItems.find((t) => !t.completed); if (nextStep) { nextStep.completed = true; - console.error(`[plan-mode] Marked step ${nextStep.step} complete (tool): ${nextStep.text}`); updateStatus(ctx); } }); @@ -330,11 +329,9 @@ export default function planModeHook(pi: HookAPI) { // Filter out stale plan mode context messages from LLM context // This ensures the agent only sees the CURRENT state (plan mode on/off) pi.on("context", async (event) => { - console.error(`[plan-mode] context event: planModeEnabled=${planModeEnabled}, executionMode=${executionMode}, msgs=${event.messages.length}`); // Only filter when NOT in plan mode (i.e., when executing) if (planModeEnabled) { - console.error("[plan-mode] skipping filter - plan mode enabled"); return; } @@ -346,26 +343,21 @@ export default function planModeHook(pi: HookAPI) { (c) => c.type === "text" && c.text.includes("[PLAN MODE ACTIVE]"), ); if (hasOldContext) { - console.error("[plan-mode] FILTERING OUT message with [PLAN MODE ACTIVE]"); return false; } } return true; }); - console.error(`[plan-mode] filtered ${beforeCount} -> ${filtered.length} messages`); return { messages: filtered }; }); // Inject plan mode context pi.on("before_agent_start", async () => { - console.error(`[plan-mode] before_agent_start: planModeEnabled=${planModeEnabled}, executionMode=${executionMode}`); if (!planModeEnabled && !executionMode) { - console.error("[plan-mode] before_agent_start: no injection needed"); return; } if (planModeEnabled) { - console.error("[plan-mode] before_agent_start: injecting PLAN MODE ACTIVE"); return { message: { customType: "plan-mode-context", @@ -390,7 +382,6 @@ Do NOT attempt to make changes - just describe what you would do.`, } if (executionMode && todoItems.length > 0) { - console.error("[plan-mode] before_agent_start: injecting EXECUTING PLAN context"); const remaining = todoItems.filter((t) => !t.completed); const todoList = remaining.map((t) => `${t.step}. ${t.text}`).join("\n"); return { @@ -406,7 +397,6 @@ Execute each step in order.`, }, }; } - console.error("[plan-mode] before_agent_start: no context injected (shouldn't reach here)"); }); // After agent finishes @@ -478,8 +468,6 @@ Execute each step in order.`, if (choice?.startsWith("Execute")) { planModeEnabled = false; executionMode = hasTodos; - console.error(`[plan-mode] EXECUTING: planModeEnabled=${planModeEnabled}, executionMode=${executionMode}`); - console.error(`[plan-mode] Setting tools to: ${NORMAL_MODE_TOOLS.join(", ")}`); pi.setActiveTools(NORMAL_MODE_TOOLS); updateStatus(ctx); @@ -554,7 +542,6 @@ Execute each step in order.`, const nextStep = todoItems.find((t) => !t.completed); if (nextStep) { nextStep.completed = true; - console.error(`[plan-mode] Marked step ${nextStep.step} complete (no-tool turn): ${nextStep.text}`); updateStatus(ctx); } } diff --git a/packages/coding-agent/src/core/hooks/loader.ts b/packages/coding-agent/src/core/hooks/loader.ts index 50f4442f..4411021a 100644 --- a/packages/coding-agent/src/core/hooks/loader.ts +++ b/packages/coding-agent/src/core/hooks/loader.ts @@ -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; + handler: (ctx: HookContext) => Promise | 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; + handler: (ctx: HookContext) => Promise | void; }, ): void { shortcuts.set(shortcut, { shortcut, hookPath, ...options }); diff --git a/packages/coding-agent/src/core/hooks/runner.ts b/packages/coding-agent/src/core/hooks/runner.ts index d6155184..620e5367 100644 --- a/packages/coding-agent/src/core/hooks/runner.ts +++ b/packages/coding-agent/src/core/hooks/runner.ts @@ -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 { - const allFlags = new Map(); + getFlags(): Map { + const allFlags = new Map(); 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 { - const allShortcuts = new Map(); + getShortcuts(): Map { + const allShortcuts = new Map(); 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 { const ctx = this.createContext(); let result: BeforeAgentStartEventResult | undefined; diff --git a/packages/coding-agent/src/modes/interactive/interactive-mode.ts b/packages/coding-agent/src/modes/interactive/interactive-mode.ts index c219b29b..4211a9f9 100644 --- a/packages/coding-agent/src/modes/interactive/interactive-mode.ts +++ b/packages/coding-agent/src/modes/interactive/interactive-mode.ts @@ -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(),