chore: include pre-built dist for github install
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
import type { PluginInput } from "@opencode-ai/plugin";
|
||||
import type { PluginConfig } from "./types";
|
||||
import type { ContextCollector } from "../../features/context-injector";
|
||||
export declare function createClaudeCodeHooksHook(ctx: PluginInput, config?: PluginConfig, contextCollector?: ContextCollector): {
|
||||
"experimental.session.compacting": (input: {
|
||||
sessionID: string;
|
||||
}, output: {
|
||||
context: string[];
|
||||
}) => Promise<void>;
|
||||
"chat.message": (input: {
|
||||
sessionID: string;
|
||||
agent?: string;
|
||||
model?: {
|
||||
providerID: string;
|
||||
modelID: string;
|
||||
};
|
||||
messageID?: string;
|
||||
}, output: {
|
||||
message: Record<string, unknown>;
|
||||
parts: Array<{
|
||||
type: string;
|
||||
text?: string;
|
||||
[key: string]: unknown;
|
||||
}>;
|
||||
}) => Promise<void>;
|
||||
"tool.execute.before": (input: {
|
||||
tool: string;
|
||||
sessionID: string;
|
||||
callID: string;
|
||||
}, output: {
|
||||
args: Record<string, unknown>;
|
||||
}) => Promise<void>;
|
||||
"tool.execute.after": (input: {
|
||||
tool: string;
|
||||
sessionID: string;
|
||||
callID: string;
|
||||
}, output: {
|
||||
title: string;
|
||||
output: string;
|
||||
metadata: unknown;
|
||||
} | undefined) => Promise<void>;
|
||||
event: (input: {
|
||||
event: {
|
||||
type: string;
|
||||
properties?: unknown;
|
||||
};
|
||||
}) => Promise<void>;
|
||||
};
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
import type { ClaudeHookEvent } from "./types";
|
||||
export interface DisabledHooksConfig {
|
||||
Stop?: string[];
|
||||
PreToolUse?: string[];
|
||||
PostToolUse?: string[];
|
||||
UserPromptSubmit?: string[];
|
||||
PreCompact?: string[];
|
||||
}
|
||||
export interface PluginExtendedConfig {
|
||||
disabledHooks?: DisabledHooksConfig;
|
||||
}
|
||||
export declare function loadPluginExtendedConfig(): Promise<PluginExtendedConfig>;
|
||||
export declare function isHookCommandDisabled(eventType: ClaudeHookEvent, command: string, config: PluginExtendedConfig | null): boolean;
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
import type { ClaudeHooksConfig } from "./types";
|
||||
export declare function getClaudeSettingsPaths(customPath?: string): string[];
|
||||
export declare function loadClaudeHooksConfig(customSettingsPath?: string): Promise<ClaudeHooksConfig | null>;
|
||||
@@ -0,0 +1,4 @@
|
||||
import type { HookAction } from "./types";
|
||||
import type { CommandResult } from "../../shared/command-executor/execute-hook-command";
|
||||
export declare function getHookIdentifier(hook: HookAction): string;
|
||||
export declare function dispatchHook(hook: HookAction, stdinJson: string, cwd: string): Promise<CommandResult>;
|
||||
@@ -0,0 +1,4 @@
|
||||
import type { HookHttp } from "./types";
|
||||
import type { CommandResult } from "../../shared/command-executor/execute-hook-command";
|
||||
export declare function interpolateEnvVars(value: string, allowedEnvVars: string[]): string;
|
||||
export declare function executeHttpHook(hook: HookHttp, stdin: string): Promise<CommandResult>;
|
||||
@@ -0,0 +1,19 @@
|
||||
import type { PluginInput } from "@opencode-ai/plugin";
|
||||
import type { PluginConfig } from "../types";
|
||||
import type { ContextCollector } from "../../../features/context-injector";
|
||||
export declare function createChatMessageHandler(ctx: PluginInput, config: PluginConfig, contextCollector?: ContextCollector): (input: {
|
||||
sessionID: string;
|
||||
agent?: string;
|
||||
model?: {
|
||||
providerID: string;
|
||||
modelID: string;
|
||||
};
|
||||
messageID?: string;
|
||||
}, output: {
|
||||
message: Record<string, unknown>;
|
||||
parts: Array<{
|
||||
type: string;
|
||||
text?: string;
|
||||
[key: string]: unknown;
|
||||
}>;
|
||||
}) => Promise<void>;
|
||||
@@ -0,0 +1,7 @@
|
||||
import type { PluginInput } from "@opencode-ai/plugin";
|
||||
import type { PluginConfig } from "../types";
|
||||
export declare function createPreCompactHandler(ctx: PluginInput, config: PluginConfig): (input: {
|
||||
sessionID: string;
|
||||
}, output: {
|
||||
context: string[];
|
||||
}) => Promise<void>;
|
||||
@@ -0,0 +1,8 @@
|
||||
import type { PluginInput } from "@opencode-ai/plugin";
|
||||
import type { PluginConfig } from "../types";
|
||||
export declare function createSessionEventHandler(ctx: PluginInput, config: PluginConfig): (input: {
|
||||
event: {
|
||||
type: string;
|
||||
properties?: unknown;
|
||||
};
|
||||
}) => Promise<void>;
|
||||
@@ -0,0 +1,11 @@
|
||||
import type { PluginInput } from "@opencode-ai/plugin";
|
||||
import type { PluginConfig } from "../types";
|
||||
export declare function createToolExecuteAfterHandler(ctx: PluginInput, config: PluginConfig): (input: {
|
||||
tool: string;
|
||||
sessionID: string;
|
||||
callID: string;
|
||||
}, output: {
|
||||
title: string;
|
||||
output: string;
|
||||
metadata: unknown;
|
||||
} | undefined) => Promise<void>;
|
||||
@@ -0,0 +1,9 @@
|
||||
import type { PluginInput } from "@opencode-ai/plugin";
|
||||
import type { PluginConfig } from "../types";
|
||||
export declare function createToolExecuteBeforeHandler(ctx: PluginInput, config: PluginConfig): (input: {
|
||||
tool: string;
|
||||
sessionID: string;
|
||||
callID: string;
|
||||
}, output: {
|
||||
args: Record<string, unknown>;
|
||||
}) => Promise<void>;
|
||||
+1
@@ -0,0 +1 @@
|
||||
export { createClaudeCodeHooksHook } from "./claude-code-hooks-hook";
|
||||
@@ -0,0 +1,8 @@
|
||||
/**
|
||||
* Plugin configuration for Claude Code hooks execution
|
||||
* Contains settings for hook command execution (zsh, etc.)
|
||||
*/
|
||||
export declare const DEFAULT_CONFIG: {
|
||||
forceZsh: boolean;
|
||||
zshPath: string;
|
||||
};
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
import type { ClaudeHooksConfig } from "./types";
|
||||
import { type PluginExtendedConfig } from "./config-loader";
|
||||
export interface PostToolUseClient {
|
||||
session: {
|
||||
messages: (opts: {
|
||||
path: {
|
||||
id: string;
|
||||
};
|
||||
query?: {
|
||||
directory: string;
|
||||
};
|
||||
}) => Promise<unknown>;
|
||||
};
|
||||
}
|
||||
export interface PostToolUseContext {
|
||||
sessionId: string;
|
||||
toolName: string;
|
||||
toolInput: Record<string, unknown>;
|
||||
toolOutput: Record<string, unknown>;
|
||||
cwd: string;
|
||||
transcriptPath?: string;
|
||||
toolUseId?: string;
|
||||
client?: PostToolUseClient;
|
||||
permissionMode?: "default" | "plan" | "acceptEdits" | "bypassPermissions";
|
||||
}
|
||||
export interface PostToolUseResult {
|
||||
block: boolean;
|
||||
reason?: string;
|
||||
message?: string;
|
||||
warnings?: string[];
|
||||
elapsedMs?: number;
|
||||
hookName?: string;
|
||||
toolName?: string;
|
||||
additionalContext?: string;
|
||||
continue?: boolean;
|
||||
stopReason?: string;
|
||||
suppressOutput?: boolean;
|
||||
systemMessage?: string;
|
||||
}
|
||||
export declare function executePostToolUseHooks(ctx: PostToolUseContext, config: ClaudeHooksConfig | null, extendedConfig?: PluginExtendedConfig | null): Promise<PostToolUseResult>;
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
import type { ClaudeHooksConfig } from "./types";
|
||||
import { type PluginExtendedConfig } from "./config-loader";
|
||||
export interface PreCompactContext {
|
||||
sessionId: string;
|
||||
cwd: string;
|
||||
}
|
||||
export interface PreCompactResult {
|
||||
context: string[];
|
||||
elapsedMs?: number;
|
||||
hookName?: string;
|
||||
continue?: boolean;
|
||||
stopReason?: string;
|
||||
suppressOutput?: boolean;
|
||||
systemMessage?: string;
|
||||
}
|
||||
export declare function executePreCompactHooks(ctx: PreCompactContext, config: ClaudeHooksConfig | null, extendedConfig?: PluginExtendedConfig | null): Promise<PreCompactResult>;
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
import type { PermissionDecision, ClaudeHooksConfig } from "./types";
|
||||
import { type PluginExtendedConfig } from "./config-loader";
|
||||
export interface PreToolUseContext {
|
||||
sessionId: string;
|
||||
toolName: string;
|
||||
toolInput: Record<string, unknown>;
|
||||
cwd: string;
|
||||
transcriptPath?: string;
|
||||
toolUseId?: string;
|
||||
permissionMode?: "default" | "plan" | "acceptEdits" | "bypassPermissions";
|
||||
}
|
||||
export interface PreToolUseResult {
|
||||
decision: PermissionDecision;
|
||||
reason?: string;
|
||||
modifiedInput?: Record<string, unknown>;
|
||||
elapsedMs?: number;
|
||||
hookName?: string;
|
||||
toolName?: string;
|
||||
inputLines?: string;
|
||||
continue?: boolean;
|
||||
stopReason?: string;
|
||||
suppressOutput?: boolean;
|
||||
systemMessage?: string;
|
||||
}
|
||||
export declare function executePreToolUseHooks(ctx: PreToolUseContext, config: ClaudeHooksConfig | null, extendedConfig?: PluginExtendedConfig | null): Promise<PreToolUseResult>;
|
||||
@@ -0,0 +1,9 @@
|
||||
export declare const sessionFirstMessageProcessed: Set<string>;
|
||||
export declare const sessionErrorState: Map<string, {
|
||||
hasError: boolean;
|
||||
errorMessage?: string;
|
||||
}>;
|
||||
export declare const sessionInterruptState: Map<string, {
|
||||
interrupted: boolean;
|
||||
}>;
|
||||
export declare function clearSessionHookState(sessionID: string): void;
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
import type { ClaudeHooksConfig } from "./types";
|
||||
import { type PluginExtendedConfig } from "./config-loader";
|
||||
export declare function setStopHookActive(sessionId: string, active: boolean): void;
|
||||
export declare function getStopHookActive(sessionId: string): boolean;
|
||||
export interface StopContext {
|
||||
sessionId: string;
|
||||
parentSessionId?: string;
|
||||
cwd: string;
|
||||
transcriptPath?: string;
|
||||
permissionMode?: "default" | "acceptEdits" | "bypassPermissions";
|
||||
stopHookActive?: boolean;
|
||||
}
|
||||
export interface StopResult {
|
||||
block: boolean;
|
||||
reason?: string;
|
||||
stopHookActive?: boolean;
|
||||
permissionMode?: "default" | "plan" | "acceptEdits" | "bypassPermissions";
|
||||
injectPrompt?: string;
|
||||
}
|
||||
export declare function executeStopHooks(ctx: StopContext, config: ClaudeHooksConfig | null, extendedConfig?: PluginExtendedConfig | null): Promise<StopResult>;
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
import type { TodoFile } from "./types";
|
||||
export declare function getTodoPath(sessionId: string): string;
|
||||
export interface OpenCodeTodo {
|
||||
content: string;
|
||||
status: string;
|
||||
priority: string;
|
||||
id: string;
|
||||
}
|
||||
export declare function loadTodoFile(sessionId: string): TodoFile | null;
|
||||
export declare function saveTodoFile(sessionId: string, file: TodoFile): void;
|
||||
export declare function saveOpenCodeTodos(sessionId: string, todos: OpenCodeTodo[]): void;
|
||||
export declare function deleteTodoFile(sessionId: string): void;
|
||||
@@ -0,0 +1,5 @@
|
||||
/**
|
||||
* Caches tool_input from PreToolUse for PostToolUse
|
||||
*/
|
||||
export declare function cacheToolInput(sessionId: string, toolName: string, invocationId: string, toolInput: Record<string, unknown>): void;
|
||||
export declare function getToolInput(sessionId: string, toolName: string, invocationId: string): Record<string, unknown> | null;
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
import type { TranscriptEntry } from "./types";
|
||||
export declare function getTranscriptPath(sessionId: string): string;
|
||||
export declare function appendTranscriptEntry(sessionId: string, entry: TranscriptEntry): void;
|
||||
/**
|
||||
* Clear transcript cache for a specific session or all sessions.
|
||||
* Call on session.deleted to prevent memory accumulation.
|
||||
*/
|
||||
export declare function clearTranscriptCache(sessionId?: string): void;
|
||||
/**
|
||||
* Build Claude Code compatible transcript from session messages.
|
||||
* Uses per-session cache to avoid redundant session.messages() API calls.
|
||||
* First call fetches and caches; subsequent calls reuse cached base entries.
|
||||
*/
|
||||
export declare function buildTranscriptFromSession(client: {
|
||||
session: {
|
||||
messages: (opts: {
|
||||
path: {
|
||||
id: string;
|
||||
};
|
||||
query?: {
|
||||
directory: string;
|
||||
};
|
||||
}) => Promise<unknown>;
|
||||
};
|
||||
}, sessionId: string, directory: string, currentToolName: string, currentToolInput: Record<string, unknown>): Promise<string | null>;
|
||||
/**
|
||||
* Delete temp transcript file (call in finally block)
|
||||
*/
|
||||
export declare function deleteTempTranscript(path: string | null): void;
|
||||
+191
@@ -0,0 +1,191 @@
|
||||
/**
|
||||
* Claude Code Hooks Type Definitions
|
||||
* Maps Claude Code hook concepts to OpenCode plugin events
|
||||
*/
|
||||
export type ClaudeHookEvent = "PreToolUse" | "PostToolUse" | "UserPromptSubmit" | "Stop" | "PreCompact";
|
||||
export interface HookMatcher {
|
||||
matcher: string;
|
||||
hooks: HookAction[];
|
||||
}
|
||||
export interface HookCommand {
|
||||
type: "command";
|
||||
command: string;
|
||||
}
|
||||
export interface HookHttp {
|
||||
type: "http";
|
||||
url: string;
|
||||
headers?: Record<string, string>;
|
||||
allowedEnvVars?: string[];
|
||||
timeout?: number;
|
||||
}
|
||||
export type HookAction = HookCommand | HookHttp;
|
||||
export interface ClaudeHooksConfig {
|
||||
PreToolUse?: HookMatcher[];
|
||||
PostToolUse?: HookMatcher[];
|
||||
UserPromptSubmit?: HookMatcher[];
|
||||
Stop?: HookMatcher[];
|
||||
PreCompact?: HookMatcher[];
|
||||
}
|
||||
export interface PreToolUseInput {
|
||||
session_id: string;
|
||||
transcript_path?: string;
|
||||
cwd: string;
|
||||
permission_mode?: PermissionMode;
|
||||
hook_event_name: "PreToolUse";
|
||||
tool_name: string;
|
||||
tool_input: Record<string, unknown>;
|
||||
tool_use_id?: string;
|
||||
hook_source?: HookSource;
|
||||
}
|
||||
export interface PostToolUseInput {
|
||||
session_id: string;
|
||||
transcript_path?: string;
|
||||
cwd: string;
|
||||
permission_mode?: PermissionMode;
|
||||
hook_event_name: "PostToolUse";
|
||||
tool_name: string;
|
||||
tool_input: Record<string, unknown>;
|
||||
tool_response: {
|
||||
title?: string;
|
||||
output?: string;
|
||||
[key: string]: unknown;
|
||||
};
|
||||
tool_use_id?: string;
|
||||
hook_source?: HookSource;
|
||||
}
|
||||
export interface UserPromptSubmitInput {
|
||||
session_id: string;
|
||||
cwd: string;
|
||||
permission_mode?: PermissionMode;
|
||||
hook_event_name: "UserPromptSubmit";
|
||||
prompt: string;
|
||||
session?: {
|
||||
id: string;
|
||||
};
|
||||
hook_source?: HookSource;
|
||||
}
|
||||
export type PermissionMode = "default" | "plan" | "acceptEdits" | "bypassPermissions";
|
||||
export type HookSource = "opencode-plugin";
|
||||
export interface StopInput {
|
||||
session_id: string;
|
||||
transcript_path?: string;
|
||||
cwd: string;
|
||||
permission_mode?: PermissionMode;
|
||||
hook_event_name: "Stop";
|
||||
stop_hook_active: boolean;
|
||||
todo_path?: string;
|
||||
hook_source?: HookSource;
|
||||
}
|
||||
export interface PreCompactInput {
|
||||
session_id: string;
|
||||
cwd: string;
|
||||
hook_event_name: "PreCompact";
|
||||
hook_source?: HookSource;
|
||||
}
|
||||
export type PermissionDecision = "allow" | "deny" | "ask";
|
||||
/**
|
||||
* Common JSON fields for all hook outputs (Claude Code spec)
|
||||
*/
|
||||
export interface HookCommonOutput {
|
||||
/** If false, Claude stops entirely */
|
||||
continue?: boolean;
|
||||
/** Message shown to user when continue=false */
|
||||
stopReason?: string;
|
||||
/** Suppress output from transcript */
|
||||
suppressOutput?: boolean;
|
||||
/** Warning/message displayed to user */
|
||||
systemMessage?: string;
|
||||
}
|
||||
export interface PreToolUseOutput extends HookCommonOutput {
|
||||
/** Deprecated: use hookSpecificOutput.permissionDecision instead */
|
||||
decision?: "allow" | "deny" | "approve" | "block" | "ask";
|
||||
/** Deprecated: use hookSpecificOutput.permissionDecisionReason instead */
|
||||
reason?: string;
|
||||
hookSpecificOutput?: {
|
||||
hookEventName: "PreToolUse";
|
||||
permissionDecision: PermissionDecision;
|
||||
permissionDecisionReason?: string;
|
||||
updatedInput?: Record<string, unknown>;
|
||||
};
|
||||
}
|
||||
export interface PostToolUseOutput extends HookCommonOutput {
|
||||
decision?: "block";
|
||||
reason?: string;
|
||||
hookSpecificOutput?: {
|
||||
hookEventName: "PostToolUse";
|
||||
/** Additional context to provide to Claude */
|
||||
additionalContext?: string;
|
||||
};
|
||||
}
|
||||
export interface HookResult {
|
||||
exitCode: number;
|
||||
stdout?: string;
|
||||
stderr?: string;
|
||||
}
|
||||
export interface TranscriptEntry {
|
||||
type: "tool_use" | "tool_result" | "user" | "assistant";
|
||||
timestamp: string;
|
||||
tool_name?: string;
|
||||
tool_input?: Record<string, unknown>;
|
||||
tool_output?: Record<string, unknown>;
|
||||
content?: string;
|
||||
}
|
||||
export interface TodoItem {
|
||||
id: string;
|
||||
content: string;
|
||||
status: "pending" | "in_progress" | "completed" | "cancelled";
|
||||
priority?: "low" | "medium" | "high";
|
||||
created_at: string;
|
||||
updated_at?: string;
|
||||
}
|
||||
export interface ClaudeCodeTodoItem {
|
||||
content: string;
|
||||
status: string;
|
||||
activeForm: string;
|
||||
}
|
||||
export interface TodoFile {
|
||||
session_id: string;
|
||||
items: TodoItem[];
|
||||
created_at: string;
|
||||
updated_at: string;
|
||||
}
|
||||
export interface StopOutput {
|
||||
decision?: "block" | "continue";
|
||||
reason?: string;
|
||||
stop_hook_active?: boolean;
|
||||
permission_mode?: PermissionMode;
|
||||
inject_prompt?: string;
|
||||
}
|
||||
export interface PreCompactOutput extends HookCommonOutput {
|
||||
/** Additional context to inject into compaction prompt */
|
||||
context?: string[];
|
||||
hookSpecificOutput?: {
|
||||
hookEventName: "PreCompact";
|
||||
/** Additional context strings to inject */
|
||||
additionalContext?: string[];
|
||||
};
|
||||
}
|
||||
export type ClaudeCodeContent = {
|
||||
type: "text";
|
||||
text: string;
|
||||
} | {
|
||||
type: "tool_use";
|
||||
id: string;
|
||||
name: string;
|
||||
input: Record<string, unknown>;
|
||||
} | {
|
||||
type: "tool_result";
|
||||
tool_use_id: string;
|
||||
content: string;
|
||||
};
|
||||
export interface ClaudeCodeMessage {
|
||||
type: "user" | "assistant";
|
||||
message: {
|
||||
role: "user" | "assistant";
|
||||
content: ClaudeCodeContent[];
|
||||
};
|
||||
}
|
||||
export interface PluginConfig {
|
||||
disabledHooks?: boolean | ClaudeHookEvent[];
|
||||
keywordDetectorDisabled?: boolean;
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
import type { ClaudeHooksConfig } from "./types";
|
||||
import { type PluginExtendedConfig } from "./config-loader";
|
||||
export interface MessagePart {
|
||||
type: "text" | "tool_use" | "tool_result";
|
||||
text?: string;
|
||||
[key: string]: unknown;
|
||||
}
|
||||
export interface UserPromptSubmitContext {
|
||||
sessionId: string;
|
||||
parentSessionId?: string;
|
||||
prompt: string;
|
||||
parts: MessagePart[];
|
||||
cwd: string;
|
||||
permissionMode?: "default" | "acceptEdits" | "bypassPermissions";
|
||||
}
|
||||
export interface UserPromptSubmitResult {
|
||||
block: boolean;
|
||||
reason?: string;
|
||||
modifiedParts: MessagePart[];
|
||||
messages: string[];
|
||||
}
|
||||
export declare function executeUserPromptSubmitHooks(ctx: UserPromptSubmitContext, config: ClaudeHooksConfig | null, extendedConfig?: PluginExtendedConfig | null): Promise<UserPromptSubmitResult>;
|
||||
Reference in New Issue
Block a user