Files
oh-my-opencode-free-fork/src/hooks/agent-usage-reminder/storage.ts
YeonGyu-Kim 2c6dfeadce feat(hooks): add agent-usage-reminder hook for background agent recommendations
Implements hook that tracks whether explore/librarian agents have been used in a session.
When target tools (Grep, Glob, WebFetch, context7, websearch_exa, grep_app) are called
without prior agent usage, appends reminder message recommending parallel background_task calls.

State persists across tool calls and resets on session compaction, allowing fresh reminders
after context compaction - similar to directory-readme-injector pattern.

Files:
- src/hooks/agent-usage-reminder/: New hook implementation
  - types.ts: AgentUsageState interface
  - constants.ts: TARGET_TOOLS, AGENT_TOOLS, REMINDER_MESSAGE
  - storage.ts: File-based state persistence with compaction handling
  - index.ts: Hook implementation with tool.execute.after and event handlers
- src/config/schema.ts: Add 'agent-usage-reminder' to HookNameSchema
- src/hooks/index.ts: Export createAgentUsageReminderHook
- src/index.ts: Instantiate and register hook handlers

🤖 GENERATED WITH ASSISTANCE OF [OhMyOpenCode](https://github.com/code-yeongyu/oh-my-opencode)
2025-12-13 21:47:56 +09:00

43 lines
1.1 KiB
TypeScript

import {
existsSync,
mkdirSync,
readFileSync,
writeFileSync,
unlinkSync,
} from "node:fs";
import { join } from "node:path";
import { AGENT_USAGE_REMINDER_STORAGE } from "./constants";
import type { AgentUsageState } from "./types";
function getStoragePath(sessionID: string): string {
return join(AGENT_USAGE_REMINDER_STORAGE, `${sessionID}.json`);
}
export function loadAgentUsageState(sessionID: string): AgentUsageState | null {
const filePath = getStoragePath(sessionID);
if (!existsSync(filePath)) return null;
try {
const content = readFileSync(filePath, "utf-8");
return JSON.parse(content) as AgentUsageState;
} catch {
return null;
}
}
export function saveAgentUsageState(state: AgentUsageState): void {
if (!existsSync(AGENT_USAGE_REMINDER_STORAGE)) {
mkdirSync(AGENT_USAGE_REMINDER_STORAGE, { recursive: true });
}
const filePath = getStoragePath(state.sessionID);
writeFileSync(filePath, JSON.stringify(state, null, 2));
}
export function clearAgentUsageState(sessionID: string): void {
const filePath = getStoragePath(sessionID);
if (existsSync(filePath)) {
unlinkSync(filePath);
}
}