ocpipe 0.5.5 → 0.5.7
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 +10 -2
- package/package.json +2 -2
- package/src/claude-code.ts +60 -12
- package/src/types.ts +2 -0
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:
|
|
16
|
-
|
|
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.
|
|
3
|
+
"version": "0.5.7",
|
|
4
4
|
"description": "SDK for LLM pipelines with OpenCode and Zod",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.ts",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"dependencies": {},
|
|
32
32
|
"peerDependencies": {
|
|
33
33
|
"zod": "4.3.6",
|
|
34
|
-
"@anthropic-ai/claude-agent-sdk": "0.2.
|
|
34
|
+
"@anthropic-ai/claude-agent-sdk": "0.2.20"
|
|
35
35
|
},
|
|
36
36
|
"peerDependenciesMeta": {
|
|
37
37
|
"@anthropic-ai/claude-agent-sdk": {
|
package/src/claude-code.ts
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
82
|
+
printToolEvent(color, name, path)
|
|
51
83
|
} else if (name === 'Glob' || name === 'Grep') {
|
|
52
84
|
const pattern = toolInput?.pattern as string
|
|
53
|
-
|
|
85
|
+
printToolEvent(color, name, pattern)
|
|
54
86
|
} else {
|
|
55
|
-
|
|
87
|
+
printToolEvent(color, name, '')
|
|
56
88
|
}
|
|
57
89
|
|
|
58
90
|
return {}
|
|
@@ -62,7 +94,14 @@ const logToolCall: HookCallback = async (input) => {
|
|
|
62
94
|
export async function runClaudeCodeAgent(
|
|
63
95
|
options: RunAgentOptions,
|
|
64
96
|
): Promise<RunAgentResult> {
|
|
65
|
-
const {
|
|
97
|
+
const {
|
|
98
|
+
prompt,
|
|
99
|
+
model,
|
|
100
|
+
sessionId,
|
|
101
|
+
timeoutSec = 600,
|
|
102
|
+
claudeCode,
|
|
103
|
+
signal,
|
|
104
|
+
} = options
|
|
66
105
|
|
|
67
106
|
// Check if already aborted
|
|
68
107
|
if (signal?.aborted) {
|
|
@@ -87,6 +126,10 @@ export async function runClaudeCodeAgent(
|
|
|
87
126
|
claudeCode?.dangerouslySkipPermissions && {
|
|
88
127
|
allowDangerouslySkipPermissions: true,
|
|
89
128
|
}),
|
|
129
|
+
// Pass through custom executable path if provided
|
|
130
|
+
...(claudeCode?.pathToClaudeCodeExecutable && {
|
|
131
|
+
pathToClaudeCodeExecutable: claudeCode.pathToClaudeCodeExecutable,
|
|
132
|
+
}),
|
|
90
133
|
}
|
|
91
134
|
|
|
92
135
|
console.error(
|
|
@@ -126,13 +169,18 @@ export async function runClaudeCodeAgent(
|
|
|
126
169
|
: null
|
|
127
170
|
|
|
128
171
|
// Set up abort promise
|
|
129
|
-
const abortPromise =
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
172
|
+
const abortPromise =
|
|
173
|
+
signal ?
|
|
174
|
+
new Promise<never>((_, reject) => {
|
|
175
|
+
signal.addEventListener(
|
|
176
|
+
'abort',
|
|
177
|
+
() => {
|
|
178
|
+
reject(new Error('Request aborted'))
|
|
179
|
+
},
|
|
180
|
+
{ once: true },
|
|
181
|
+
)
|
|
182
|
+
})
|
|
183
|
+
: null
|
|
136
184
|
|
|
137
185
|
// Stream the response
|
|
138
186
|
const streamPromise = (async () => {
|
package/src/types.ts
CHANGED
|
@@ -24,6 +24,8 @@ export interface ClaudeCodeOptions {
|
|
|
24
24
|
permissionMode?: PermissionMode
|
|
25
25
|
/** Required when using 'bypassPermissions' mode. */
|
|
26
26
|
dangerouslySkipPermissions?: boolean
|
|
27
|
+
/** Path to Claude Code executable (default: auto-detected). */
|
|
28
|
+
pathToClaudeCodeExecutable?: string
|
|
27
29
|
}
|
|
28
30
|
|
|
29
31
|
/** Model configuration for LLM backends. */
|