mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-17 04:02:21 +00:00
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:
parent
a169029a16
commit
277d7bd83b
4 changed files with 14 additions and 25 deletions
|
|
@ -322,7 +322,6 @@ export default function planModeHook(pi: HookAPI) {
|
||||||
const nextStep = todoItems.find((t) => !t.completed);
|
const nextStep = todoItems.find((t) => !t.completed);
|
||||||
if (nextStep) {
|
if (nextStep) {
|
||||||
nextStep.completed = true;
|
nextStep.completed = true;
|
||||||
console.error(`[plan-mode] Marked step ${nextStep.step} complete (tool): ${nextStep.text}`);
|
|
||||||
updateStatus(ctx);
|
updateStatus(ctx);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -330,11 +329,9 @@ export default function planModeHook(pi: HookAPI) {
|
||||||
// Filter out stale plan mode context messages from LLM context
|
// Filter out stale plan mode context messages from LLM context
|
||||||
// This ensures the agent only sees the CURRENT state (plan mode on/off)
|
// This ensures the agent only sees the CURRENT state (plan mode on/off)
|
||||||
pi.on("context", async (event) => {
|
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)
|
// Only filter when NOT in plan mode (i.e., when executing)
|
||||||
if (planModeEnabled) {
|
if (planModeEnabled) {
|
||||||
console.error("[plan-mode] skipping filter - plan mode enabled");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -346,26 +343,21 @@ export default function planModeHook(pi: HookAPI) {
|
||||||
(c) => c.type === "text" && c.text.includes("[PLAN MODE ACTIVE]"),
|
(c) => c.type === "text" && c.text.includes("[PLAN MODE ACTIVE]"),
|
||||||
);
|
);
|
||||||
if (hasOldContext) {
|
if (hasOldContext) {
|
||||||
console.error("[plan-mode] FILTERING OUT message with [PLAN MODE ACTIVE]");
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
console.error(`[plan-mode] filtered ${beforeCount} -> ${filtered.length} messages`);
|
|
||||||
return { messages: filtered };
|
return { messages: filtered };
|
||||||
});
|
});
|
||||||
|
|
||||||
// Inject plan mode context
|
// Inject plan mode context
|
||||||
pi.on("before_agent_start", async () => {
|
pi.on("before_agent_start", async () => {
|
||||||
console.error(`[plan-mode] before_agent_start: planModeEnabled=${planModeEnabled}, executionMode=${executionMode}`);
|
|
||||||
if (!planModeEnabled && !executionMode) {
|
if (!planModeEnabled && !executionMode) {
|
||||||
console.error("[plan-mode] before_agent_start: no injection needed");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (planModeEnabled) {
|
if (planModeEnabled) {
|
||||||
console.error("[plan-mode] before_agent_start: injecting PLAN MODE ACTIVE");
|
|
||||||
return {
|
return {
|
||||||
message: {
|
message: {
|
||||||
customType: "plan-mode-context",
|
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) {
|
if (executionMode && todoItems.length > 0) {
|
||||||
console.error("[plan-mode] before_agent_start: injecting EXECUTING PLAN context");
|
|
||||||
const remaining = todoItems.filter((t) => !t.completed);
|
const remaining = todoItems.filter((t) => !t.completed);
|
||||||
const todoList = remaining.map((t) => `${t.step}. ${t.text}`).join("\n");
|
const todoList = remaining.map((t) => `${t.step}. ${t.text}`).join("\n");
|
||||||
return {
|
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
|
// After agent finishes
|
||||||
|
|
@ -478,8 +468,6 @@ Execute each step in order.`,
|
||||||
if (choice?.startsWith("Execute")) {
|
if (choice?.startsWith("Execute")) {
|
||||||
planModeEnabled = false;
|
planModeEnabled = false;
|
||||||
executionMode = hasTodos;
|
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);
|
pi.setActiveTools(NORMAL_MODE_TOOLS);
|
||||||
updateStatus(ctx);
|
updateStatus(ctx);
|
||||||
|
|
||||||
|
|
@ -554,7 +542,6 @@ Execute each step in order.`,
|
||||||
const nextStep = todoItems.find((t) => !t.completed);
|
const nextStep = todoItems.find((t) => !t.completed);
|
||||||
if (nextStep) {
|
if (nextStep) {
|
||||||
nextStep.completed = true;
|
nextStep.completed = true;
|
||||||
console.error(`[plan-mode] Marked step ${nextStep.step} complete (no-tool turn): ${nextStep.text}`);
|
|
||||||
updateStatus(ctx);
|
updateStatus(ctx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ import { getAgentDir } from "../../config.js";
|
||||||
import type { HookMessage } from "../messages.js";
|
import type { HookMessage } from "../messages.js";
|
||||||
import type { SessionManager } from "../session-manager.js";
|
import type { SessionManager } from "../session-manager.js";
|
||||||
import { execCommand } from "./runner.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
|
// Create require function to resolve module paths at runtime
|
||||||
const require = createRequire(import.meta.url);
|
const require = createRequire(import.meta.url);
|
||||||
|
|
@ -101,7 +101,7 @@ export interface HookShortcut {
|
||||||
/** Description for help */
|
/** Description for help */
|
||||||
description?: string;
|
description?: string;
|
||||||
/** Handler function */
|
/** Handler function */
|
||||||
handler: (ctx: import("./types.js").HookContext) => Promise<void> | void;
|
handler: (ctx: HookContext) => Promise<void> | void;
|
||||||
/** Hook path that registered this shortcut */
|
/** Hook path that registered this shortcut */
|
||||||
hookPath: string;
|
hookPath: string;
|
||||||
}
|
}
|
||||||
|
|
@ -296,7 +296,7 @@ function createHookAPI(
|
||||||
shortcut: string,
|
shortcut: string,
|
||||||
options: {
|
options: {
|
||||||
description?: string;
|
description?: string;
|
||||||
handler: (ctx: import("./types.js").HookContext) => Promise<void> | void;
|
handler: (ctx: HookContext) => Promise<void> | void;
|
||||||
},
|
},
|
||||||
): void {
|
): void {
|
||||||
shortcuts.set(shortcut, { shortcut, hookPath, ...options });
|
shortcuts.set(shortcut, { shortcut, hookPath, ...options });
|
||||||
|
|
|
||||||
|
|
@ -3,13 +3,15 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import type { AgentMessage } from "@mariozechner/pi-agent-core";
|
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 { theme } from "../../modes/interactive/theme/theme.js";
|
||||||
import type { ModelRegistry } from "../model-registry.js";
|
import type { ModelRegistry } from "../model-registry.js";
|
||||||
import type { SessionManager } from "../session-manager.js";
|
import type { SessionManager } from "../session-manager.js";
|
||||||
import type {
|
import type {
|
||||||
AppendEntryHandler,
|
AppendEntryHandler,
|
||||||
BranchHandler,
|
BranchHandler,
|
||||||
|
HookFlag,
|
||||||
|
HookShortcut,
|
||||||
LoadedHook,
|
LoadedHook,
|
||||||
NavigateTreeHandler,
|
NavigateTreeHandler,
|
||||||
NewSessionHandler,
|
NewSessionHandler,
|
||||||
|
|
@ -176,8 +178,8 @@ export class HookRunner {
|
||||||
/**
|
/**
|
||||||
* Get all CLI flags registered by hooks.
|
* Get all CLI flags registered by hooks.
|
||||||
*/
|
*/
|
||||||
getFlags(): Map<string, import("./loader.js").HookFlag> {
|
getFlags(): Map<string, HookFlag> {
|
||||||
const allFlags = new Map<string, import("./loader.js").HookFlag>();
|
const allFlags = new Map<string, HookFlag>();
|
||||||
for (const hook of this.hooks) {
|
for (const hook of this.hooks) {
|
||||||
for (const [name, flag] of hook.flags) {
|
for (const [name, flag] of hook.flags) {
|
||||||
allFlags.set(name, flag);
|
allFlags.set(name, flag);
|
||||||
|
|
@ -221,8 +223,8 @@ export class HookRunner {
|
||||||
* Conflicts with built-in shortcuts are skipped with a warning.
|
* Conflicts with built-in shortcuts are skipped with a warning.
|
||||||
* Conflicts between hooks are logged as warnings.
|
* Conflicts between hooks are logged as warnings.
|
||||||
*/
|
*/
|
||||||
getShortcuts(): Map<string, import("./loader.js").HookShortcut> {
|
getShortcuts(): Map<string, HookShortcut> {
|
||||||
const allShortcuts = new Map<string, import("./loader.js").HookShortcut>();
|
const allShortcuts = new Map<string, HookShortcut>();
|
||||||
for (const hook of this.hooks) {
|
for (const hook of this.hooks) {
|
||||||
for (const [key, shortcut] of hook.shortcuts) {
|
for (const [key, shortcut] of hook.shortcuts) {
|
||||||
const normalizedKey = key.toLowerCase();
|
const normalizedKey = key.toLowerCase();
|
||||||
|
|
@ -486,7 +488,7 @@ export class HookRunner {
|
||||||
*/
|
*/
|
||||||
async emitBeforeAgentStart(
|
async emitBeforeAgentStart(
|
||||||
prompt: string,
|
prompt: string,
|
||||||
images?: import("@mariozechner/pi-ai").ImageContent[],
|
images?: ImageContent[],
|
||||||
): Promise<BeforeAgentStartEventResult | undefined> {
|
): Promise<BeforeAgentStartEventResult | undefined> {
|
||||||
const ctx = this.createContext();
|
const ctx = this.createContext();
|
||||||
let result: BeforeAgentStartEventResult | undefined;
|
let result: BeforeAgentStartEventResult | undefined;
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ import { exec, spawn, spawnSync } from "child_process";
|
||||||
import { APP_NAME, getAuthPath, getDebugLogPath } from "../../config.js";
|
import { APP_NAME, getAuthPath, getDebugLogPath } from "../../config.js";
|
||||||
import type { AgentSession, AgentSessionEvent } from "../../core/agent-session.js";
|
import type { AgentSession, AgentSessionEvent } from "../../core/agent-session.js";
|
||||||
import type { CustomToolSessionEvent, LoadedCustomTool } from "../../core/custom-tools/index.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 { KeybindingsManager } from "../../core/keybindings.js";
|
||||||
import { createCompactionSummaryMessage } from "../../core/messages.js";
|
import { createCompactionSummaryMessage } from "../../core/messages.js";
|
||||||
import { type SessionContext, SessionManager } from "../../core/session-manager.js";
|
import { type SessionContext, SessionManager } from "../../core/session-manager.js";
|
||||||
|
|
@ -581,12 +581,12 @@ export class InteractiveMode {
|
||||||
/**
|
/**
|
||||||
* Set up keyboard shortcuts registered by hooks.
|
* 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();
|
const shortcuts = hookRunner.getShortcuts();
|
||||||
if (shortcuts.size === 0) return;
|
if (shortcuts.size === 0) return;
|
||||||
|
|
||||||
// Create a context for shortcut handlers
|
// Create a context for shortcut handlers
|
||||||
const createContext = (): import("../../core/hooks/types.js").HookContext => ({
|
const createContext = (): HookContext => ({
|
||||||
ui: this.createHookUIContext(),
|
ui: this.createHookUIContext(),
|
||||||
hasUI: true,
|
hasUI: true,
|
||||||
cwd: process.cwd(),
|
cwd: process.cwd(),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue