@@ -19,13 +19,43 @@ const PLUGIN_NAME = "opencoder"
1919 * These hooks provide optional logging points for plugin activity.
2020 * Set OPENCODER_DEBUG=1 environment variable to enable debug logging.
2121 *
22- * @param ctx - Plugin context from OpenCode
23- * @returns Hooks object with lifecycle callbacks
22+ * @param ctx - Plugin context from OpenCode containing session information
23+ * @returns Hooks object with lifecycle callbacks for `event`, `tool.execute.before`, and `tool.execute.after`
24+ *
25+ * @example
26+ * // Enable debug logging by setting environment variable:
27+ * // OPENCODER_DEBUG=1 opencode @opencoder
28+ *
29+ * @example
30+ * // Debug output format for events:
31+ * // [2026-01-19T12:00:00.000Z] [opencoder] Event received {
32+ * // "directory": "/home/user/project",
33+ * // "type": "session.created",
34+ * // "properties": ["sessionId", "timestamp"]
35+ * // }
2436 */
2537function createLifecycleHooks ( ctx : PluginInput ) : Hooks {
2638 const debug = process . env . OPENCODER_DEBUG === "1"
2739
28- const log = ( message : string , data ?: Record < string , unknown > ) => {
40+ /**
41+ * Logs a debug message with context when OPENCODER_DEBUG=1 is set.
42+ *
43+ * Messages are formatted with ISO timestamp and plugin name prefix,
44+ * followed by the message and context data as pretty-printed JSON.
45+ *
46+ * @param message - The log message describing the event
47+ * @param data - Optional additional context to include in the log output
48+ * @returns void
49+ *
50+ * @example
51+ * // Output when debug is enabled:
52+ * // [2026-01-19T12:00:00.000Z] [opencoder] Tool executing {
53+ * // "directory": "/home/user/project",
54+ * // "tool": "bash",
55+ * // "sessionID": "abc123"
56+ * // }
57+ */
58+ const log = ( message : string , data ?: Record < string , unknown > ) : void => {
2959 if ( debug ) {
3060 const timestamp = new Date ( ) . toISOString ( )
3161 const prefix = `[${ timestamp } ] [${ PLUGIN_NAME } ]`
0 commit comments