ocpipe 0.5.4 → 0.5.6

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.
package/example/index.ts CHANGED
@@ -2,18 +2,26 @@
2
2
  * Hello World example runner.
3
3
  *
4
4
  * Demonstrates running an ocpipe module in a pipeline.
5
+ *
6
+ * Usage:
7
+ * npx tsx example/index.ts # Use opencode backend
8
+ * npx tsx example/index.ts --claude-code # Use claude-code backend
5
9
  */
6
10
 
7
11
  import { Pipeline, createBaseState } from '../src/index.js'
8
12
  import { Greeter } from './module.js'
9
13
 
14
+ const useClaudeCode = process.argv.includes('--claude-code')
15
+
10
16
  async function main() {
11
17
  // Create a pipeline with configuration
12
18
  const pipeline = new Pipeline(
13
19
  {
14
20
  name: 'hello-world',
15
- defaultModel: { providerID: 'opencode', modelID: 'minimax-m2.1-free' },
16
- defaultAgent: 'default',
21
+ defaultModel: useClaudeCode
22
+ ? { backend: 'claude-code', modelID: 'sonnet' }
23
+ : { providerID: 'opencode', modelID: 'minimax-m2.1-free' },
24
+ defaultAgent: useClaudeCode ? 'claude-code' : 'default',
17
25
  checkpointDir: './ckpt',
18
26
  logDir: './logs',
19
27
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ocpipe",
3
- "version": "0.5.4",
3
+ "version": "0.5.6",
4
4
  "description": "SDK for LLM pipelines with OpenCode and Zod",
5
5
  "type": "module",
6
6
  "main": "src/index.ts",
package/src/agent.ts CHANGED
@@ -61,8 +61,6 @@ async function runOpencodeAgent(
61
61
 
62
62
  const args = [
63
63
  'run',
64
- '--dir',
65
- cwd,
66
64
  '--format',
67
65
  'default',
68
66
  '--agent',
@@ -14,6 +14,37 @@ import {
14
14
  } from '@anthropic-ai/claude-agent-sdk'
15
15
  import type { RunAgentOptions, RunAgentResult } from './types.js'
16
16
 
17
+ /** ANSI color codes for terminal output. */
18
+ const Style = {
19
+ TEXT_HIGHLIGHT_BOLD: '\x1b[96m\x1b[1m', // Cyan (Read)
20
+ TEXT_DIM: '\x1b[90m', // Gray (dimmed type text)
21
+ TEXT_NORMAL: '\x1b[0m', // Reset
22
+ TEXT_DANGER_BOLD: '\x1b[91m\x1b[1m', // Red (Bash)
23
+ TEXT_SUCCESS_BOLD: '\x1b[92m\x1b[1m', // Green (Edit, Write)
24
+ TEXT_INFO_BOLD: '\x1b[94m\x1b[1m', // Blue (Glob, Grep)
25
+ }
26
+
27
+ /** Map tool names to their display colors. */
28
+ const TOOL_COLORS: Record<string, string> = {
29
+ Bash: Style.TEXT_DANGER_BOLD,
30
+ Edit: Style.TEXT_SUCCESS_BOLD,
31
+ Write: Style.TEXT_SUCCESS_BOLD,
32
+ Read: Style.TEXT_HIGHLIGHT_BOLD,
33
+ Glob: Style.TEXT_INFO_BOLD,
34
+ Grep: Style.TEXT_INFO_BOLD,
35
+ }
36
+
37
+ /** Print a tool event with colored pipe prefix. */
38
+ function printToolEvent(color: string, type: string, title: string): void {
39
+ const line = [
40
+ color + '|',
41
+ Style.TEXT_NORMAL + Style.TEXT_DIM + ` ${type.padEnd(7)}`,
42
+ '',
43
+ Style.TEXT_NORMAL + title,
44
+ ].join(' ')
45
+ console.error(line)
46
+ }
47
+
17
48
  /** Normalize model ID to Claude Code format (opus, sonnet, haiku). */
18
49
  function normalizeModelId(modelId: string): string {
19
50
  const lower = modelId.toLowerCase()
@@ -40,19 +71,20 @@ const logToolCall: HookCallback = async (input) => {
40
71
  const preInput = input as PreToolUseHookInput
41
72
  const name = preInput.tool_name
42
73
  const toolInput = preInput.tool_input as Record<string, unknown>
74
+ const color = TOOL_COLORS[name] ?? Style.TEXT_DIM
43
75
 
44
76
  if (name === 'Bash') {
45
77
  const cmd = toolInput?.command as string
46
78
  const preview = cmd?.split('\n')[0]?.slice(0, 80)
47
- console.error(`\n[Bash] ${preview}${cmd?.length > 80 ? '...' : ''}`)
79
+ printToolEvent(color, name, preview + (cmd?.length > 80 ? '...' : ''))
48
80
  } else if (name === 'Read' || name === 'Write' || name === 'Edit') {
49
81
  const path = toolInput?.file_path as string
50
- console.error(`\n[${name}] ${path}`)
82
+ printToolEvent(color, name, path)
51
83
  } else if (name === 'Glob' || name === 'Grep') {
52
84
  const pattern = toolInput?.pattern as string
53
- console.error(`\n[${name}] ${pattern}`)
85
+ printToolEvent(color, name, pattern)
54
86
  } else {
55
- console.error(`\n[${name}]`)
87
+ printToolEvent(color, name, '')
56
88
  }
57
89
 
58
90
  return {}