ocpipe 0.5.1 → 0.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/claude-code.ts +28 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ocpipe",
3
- "version": "0.5.1",
3
+ "version": "0.5.2",
4
4
  "description": "SDK for LLM pipelines with OpenCode and Zod",
5
5
  "type": "module",
6
6
  "main": "src/index.ts",
@@ -7,6 +7,8 @@
7
7
  import {
8
8
  unstable_v2_createSession,
9
9
  unstable_v2_resumeSession,
10
+ type HookCallback,
11
+ type PreToolUseHookInput,
10
12
  type SDKMessage,
11
13
  type SDKSessionOptions,
12
14
  } from '@anthropic-ai/claude-agent-sdk'
@@ -33,6 +35,29 @@ function getAssistantText(msg: SDKMessage): string | null {
33
35
  return textParts.join('')
34
36
  }
35
37
 
38
+ /** logToolCall logs tool calls in a compact format during execution. */
39
+ const logToolCall: HookCallback = async (input) => {
40
+ const preInput = input as PreToolUseHookInput
41
+ const name = preInput.tool_name
42
+ const toolInput = preInput.tool_input as Record<string, unknown>
43
+
44
+ if (name === 'Bash') {
45
+ const cmd = toolInput?.command as string
46
+ const preview = cmd?.split('\n')[0]?.slice(0, 80)
47
+ console.error(`\n[Bash] ${preview}${cmd?.length > 80 ? '...' : ''}`)
48
+ } else if (name === 'Read' || name === 'Write' || name === 'Edit') {
49
+ const path = toolInput?.file_path as string
50
+ console.error(`\n[${name}] ${path}`)
51
+ } else if (name === 'Glob' || name === 'Grep') {
52
+ const pattern = toolInput?.pattern as string
53
+ console.error(`\n[${name}] ${pattern}`)
54
+ } else {
55
+ console.error(`\n[${name}]`)
56
+ }
57
+
58
+ return {}
59
+ }
60
+
36
61
  /** runClaudeCodeAgent executes a Claude Code agent with a prompt. */
37
62
  export async function runClaudeCodeAgent(
38
63
  options: RunAgentOptions,
@@ -49,6 +74,9 @@ export async function runClaudeCodeAgent(
49
74
  const sessionOptions: SDKSessionOptions = {
50
75
  model: modelStr,
51
76
  permissionMode,
77
+ hooks: {
78
+ PreToolUse: [{ hooks: [logToolCall] }],
79
+ },
52
80
  // bypassPermissions requires explicit opt-in
53
81
  ...(permissionMode === 'bypassPermissions' &&
54
82
  claudeCode?.dangerouslySkipPermissions && {