ocpipe 0.5.11 → 0.5.13
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/package.json +10 -10
- package/src/claude-code.ts +29 -1
- package/src/types.ts +5 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ocpipe",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.13",
|
|
4
4
|
"description": "SDK for LLM pipelines with OpenCode and Zod",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.ts",
|
|
@@ -39,17 +39,17 @@
|
|
|
39
39
|
}
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@anthropic-ai/claude-agent-sdk": "^0.2.
|
|
43
|
-
"@eslint/js": "^
|
|
44
|
-
"bun-types": "^1.3.
|
|
45
|
-
"eslint": "^
|
|
46
|
-
"globals": "^17.
|
|
42
|
+
"@anthropic-ai/claude-agent-sdk": "^0.2.42",
|
|
43
|
+
"@eslint/js": "^10.0.1",
|
|
44
|
+
"bun-types": "^1.3.9",
|
|
45
|
+
"eslint": "^10.0.0",
|
|
46
|
+
"globals": "^17.3.0",
|
|
47
47
|
"jiti": "^2.6.1",
|
|
48
|
-
"prettier": "^3.
|
|
48
|
+
"prettier": "^3.8.1",
|
|
49
49
|
"typescript": "^5.0.0",
|
|
50
|
-
"typescript-eslint": "^8.
|
|
51
|
-
"@typescript/native-preview": "^7.0.0-dev.
|
|
52
|
-
"vitest": "^4.0.
|
|
50
|
+
"typescript-eslint": "^8.55.0",
|
|
51
|
+
"@typescript/native-preview": "^7.0.0-dev.20260213.1",
|
|
52
|
+
"vitest": "^4.0.18"
|
|
53
53
|
},
|
|
54
54
|
"scripts": {
|
|
55
55
|
"lint": "eslint .",
|
package/src/claude-code.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import { execSync } from 'child_process'
|
|
8
|
-
import { existsSync } from 'fs'
|
|
8
|
+
import { existsSync, readFileSync } from 'fs'
|
|
9
9
|
import { join } from 'path'
|
|
10
10
|
import { homedir } from 'os'
|
|
11
11
|
import {
|
|
@@ -85,6 +85,21 @@ function normalizeModelId(modelId: string): string {
|
|
|
85
85
|
return modelId
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
+
/** loadAgentDefinition loads an OpenCode agent definition file and extracts the
|
|
89
|
+
* markdown body (stripping the YAML frontmatter) for use as a system prompt. */
|
|
90
|
+
function loadAgentDefinition(agent: string, workdir?: string): string | undefined {
|
|
91
|
+
if (!agent || !workdir) return undefined
|
|
92
|
+
|
|
93
|
+
const agentPath = join(workdir, '.opencode', 'agents', `${agent}.md`)
|
|
94
|
+
if (!existsSync(agentPath)) return undefined
|
|
95
|
+
|
|
96
|
+
const content = readFileSync(agentPath, 'utf8')
|
|
97
|
+
|
|
98
|
+
// Strip YAML frontmatter (--- delimited block at the start).
|
|
99
|
+
const stripped = content.replace(/^---\n[\s\S]*?\n---\n*/, '')
|
|
100
|
+
return stripped.trim() || undefined
|
|
101
|
+
}
|
|
102
|
+
|
|
88
103
|
/** Extract text from assistant messages. */
|
|
89
104
|
function getAssistantText(msg: SDKMessage): string | null {
|
|
90
105
|
if (msg.type !== 'assistant') return null
|
|
@@ -127,9 +142,11 @@ export async function runClaudeCodeAgent(
|
|
|
127
142
|
): Promise<RunAgentResult> {
|
|
128
143
|
const {
|
|
129
144
|
prompt,
|
|
145
|
+
agent,
|
|
130
146
|
model,
|
|
131
147
|
sessionId,
|
|
132
148
|
timeoutSec = 600,
|
|
149
|
+
workdir,
|
|
133
150
|
claudeCode,
|
|
134
151
|
signal,
|
|
135
152
|
} = options
|
|
@@ -146,9 +163,20 @@ export async function runClaudeCodeAgent(
|
|
|
146
163
|
|
|
147
164
|
// Build session options with configurable permission mode (default: acceptEdits)
|
|
148
165
|
const permissionMode = claudeCode?.permissionMode ?? 'acceptEdits'
|
|
166
|
+
|
|
167
|
+
// Resolve system prompt: explicit option > agent definition file > none
|
|
168
|
+
const systemPrompt = claudeCode?.systemPrompt ?? loadAgentDefinition(agent, workdir)
|
|
169
|
+
|
|
149
170
|
const sessionOptions: SDKSessionOptions = {
|
|
150
171
|
model: modelStr,
|
|
151
172
|
permissionMode,
|
|
173
|
+
...(workdir && { cwd: workdir }),
|
|
174
|
+
...(systemPrompt && { systemPrompt }),
|
|
175
|
+
// Enable session persistence so close+resume works.
|
|
176
|
+
// The v2 SDK defaults persistSession to false, unlike v1 which defaults to true.
|
|
177
|
+
// Without this, session.close() destroys the session and resumeSession() fails
|
|
178
|
+
// with "No conversation found with session ID".
|
|
179
|
+
...({ persistSession: true }),
|
|
152
180
|
hooks: {
|
|
153
181
|
PreToolUse: [{ hooks: [logToolCall] }],
|
|
154
182
|
},
|
package/src/types.ts
CHANGED
|
@@ -26,6 +26,11 @@ export interface ClaudeCodeOptions {
|
|
|
26
26
|
dangerouslySkipPermissions?: boolean
|
|
27
27
|
/** Path to Claude Code executable (default: auto-detected). */
|
|
28
28
|
pathToClaudeCodeExecutable?: string
|
|
29
|
+
/**
|
|
30
|
+
* System prompt for the Claude Code session.
|
|
31
|
+
* Can be a full string or use the preset format with append.
|
|
32
|
+
*/
|
|
33
|
+
systemPrompt?: string | { type: 'preset'; preset: 'claude_code'; append: string }
|
|
29
34
|
}
|
|
30
35
|
|
|
31
36
|
/** Model configuration for LLM backends. */
|