ocpipe 0.3.2 → 0.3.4
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 +7 -6
- package/src/agent.ts +18 -12
- package/src/pipeline.ts +1 -0
- package/src/predict.ts +3 -0
- package/src/types.ts +6 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ocpipe",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.4",
|
|
4
4
|
"description": "SDK for LLM pipelines with OpenCode and Zod",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.ts",
|
|
@@ -29,26 +29,27 @@
|
|
|
29
29
|
"bun": ">=1.0.0"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"opencode-ai": "
|
|
32
|
+
"opencode-ai": "1.1.8"
|
|
33
33
|
},
|
|
34
34
|
"peerDependencies": {
|
|
35
|
-
"zod": "
|
|
35
|
+
"zod": "4.3.5"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@eslint/js": "^9.39.2",
|
|
39
39
|
"bun-types": "^1.3.5",
|
|
40
40
|
"eslint": "^9.39.2",
|
|
41
|
-
"globals": "^
|
|
41
|
+
"globals": "^17.0.0",
|
|
42
42
|
"jiti": "^2.6.1",
|
|
43
43
|
"prettier": "^3.7.4",
|
|
44
44
|
"typescript": "^5.0.0",
|
|
45
|
-
"typescript-eslint": "^8.
|
|
45
|
+
"typescript-eslint": "^8.52.0",
|
|
46
|
+
"@typescript/native-preview": "^7.0.0-dev.20251226.1",
|
|
46
47
|
"vitest": "^4.0.0"
|
|
47
48
|
},
|
|
48
49
|
"scripts": {
|
|
49
50
|
"lint": "eslint .",
|
|
50
51
|
"format": "bun run prettier --write .",
|
|
51
|
-
"typecheck": "
|
|
52
|
+
"typecheck": "tsgo --noEmit",
|
|
52
53
|
"test": "vitest run",
|
|
53
54
|
"test:watch": "vitest",
|
|
54
55
|
"release": "npm run release:version && npm run release:commit",
|
package/src/agent.ts
CHANGED
|
@@ -32,7 +32,7 @@ function getOpencodeCommand(args: string[]): { cmd: string; args: string[] } {
|
|
|
32
32
|
export async function runAgent(
|
|
33
33
|
options: RunAgentOptions,
|
|
34
34
|
): Promise<RunAgentResult> {
|
|
35
|
-
const { prompt, agent, model, sessionId, timeoutSec = 300 } = options
|
|
35
|
+
const { prompt, agent, model, sessionId, timeoutSec = 300, workdir } = options
|
|
36
36
|
|
|
37
37
|
const modelStr = `${model.providerID}/${model.modelID}`
|
|
38
38
|
const sessionInfo = sessionId ? `[session:${sessionId}]` : '[new session]'
|
|
@@ -59,7 +59,7 @@ export async function runAgent(
|
|
|
59
59
|
return new Promise((resolve, reject) => {
|
|
60
60
|
const opencodeCmd = getOpencodeCommand(args)
|
|
61
61
|
const proc = spawn(opencodeCmd.cmd, opencodeCmd.args, {
|
|
62
|
-
cwd: PROJECT_ROOT,
|
|
62
|
+
cwd: workdir ?? PROJECT_ROOT,
|
|
63
63
|
stdio: ['pipe', 'pipe', 'pipe'],
|
|
64
64
|
})
|
|
65
65
|
|
|
@@ -96,14 +96,17 @@ export async function runAgent(
|
|
|
96
96
|
proc.stdin.write(prompt)
|
|
97
97
|
proc.stdin.end()
|
|
98
98
|
|
|
99
|
-
// Timeout handling
|
|
100
|
-
const timeout =
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
99
|
+
// Timeout handling (0 = no timeout)
|
|
100
|
+
const timeout =
|
|
101
|
+
timeoutSec > 0 ?
|
|
102
|
+
setTimeout(() => {
|
|
103
|
+
proc.kill()
|
|
104
|
+
reject(new Error(`Timeout after ${timeoutSec}s`))
|
|
105
|
+
}, timeoutSec * 1000)
|
|
106
|
+
: null
|
|
104
107
|
|
|
105
108
|
proc.on('close', async (code) => {
|
|
106
|
-
clearTimeout(timeout)
|
|
109
|
+
if (timeout) clearTimeout(timeout)
|
|
107
110
|
|
|
108
111
|
if (code !== 0) {
|
|
109
112
|
reject(new Error(`OpenCode exited with code ${code}`))
|
|
@@ -114,7 +117,7 @@ export async function runAgent(
|
|
|
114
117
|
let response = stdoutChunks.join('').trim()
|
|
115
118
|
|
|
116
119
|
if (newSessionId) {
|
|
117
|
-
const exported = await exportSession(newSessionId)
|
|
120
|
+
const exported = await exportSession(newSessionId, workdir)
|
|
118
121
|
if (exported) {
|
|
119
122
|
response = exported
|
|
120
123
|
}
|
|
@@ -132,14 +135,17 @@ export async function runAgent(
|
|
|
132
135
|
})
|
|
133
136
|
|
|
134
137
|
proc.on('error', (err) => {
|
|
135
|
-
clearTimeout(timeout)
|
|
138
|
+
if (timeout) clearTimeout(timeout)
|
|
136
139
|
reject(err)
|
|
137
140
|
})
|
|
138
141
|
})
|
|
139
142
|
}
|
|
140
143
|
|
|
141
144
|
/** exportSession exports a session and extracts assistant text responses. */
|
|
142
|
-
async function exportSession(
|
|
145
|
+
async function exportSession(
|
|
146
|
+
sessionId: string,
|
|
147
|
+
workdir?: string,
|
|
148
|
+
): Promise<string | null> {
|
|
143
149
|
const tmpPath = `${TMP_DIR}/opencode_export_${Date.now()}.json`
|
|
144
150
|
|
|
145
151
|
try {
|
|
@@ -154,7 +160,7 @@ async function exportSession(sessionId: string): Promise<string | null> {
|
|
|
154
160
|
tmpPath,
|
|
155
161
|
])
|
|
156
162
|
const proc = Bun.spawn([opencodeCmd.cmd, ...opencodeCmd.args], {
|
|
157
|
-
cwd: PROJECT_ROOT,
|
|
163
|
+
cwd: workdir ?? PROJECT_ROOT,
|
|
158
164
|
stdout: 'pipe',
|
|
159
165
|
stderr: 'pipe',
|
|
160
166
|
})
|
package/src/pipeline.ts
CHANGED
package/src/predict.ts
CHANGED
|
@@ -75,6 +75,7 @@ export class Predict<S extends AnySignature> {
|
|
|
75
75
|
model: this.config.model ?? ctx.defaultModel,
|
|
76
76
|
sessionId: this.config.newSession ? undefined : ctx.sessionId,
|
|
77
77
|
timeoutSec: ctx.timeoutSec,
|
|
78
|
+
workdir: ctx.workdir,
|
|
78
79
|
})
|
|
79
80
|
|
|
80
81
|
// Update context with new session ID for continuity
|
|
@@ -202,6 +203,7 @@ export class Predict<S extends AnySignature> {
|
|
|
202
203
|
sessionId: correctionModel ? undefined : sessionId,
|
|
203
204
|
agent: ctx.defaultAgent,
|
|
204
205
|
timeoutSec: 60,
|
|
206
|
+
workdir: ctx.workdir,
|
|
205
207
|
})
|
|
206
208
|
|
|
207
209
|
// Try to parse the repaired JSON
|
|
@@ -276,6 +278,7 @@ export class Predict<S extends AnySignature> {
|
|
|
276
278
|
sessionId: correctionModel ? undefined : sessionId,
|
|
277
279
|
agent: ctx.defaultAgent,
|
|
278
280
|
timeoutSec: 60, // Short timeout for simple patches
|
|
281
|
+
workdir: ctx.workdir,
|
|
279
282
|
})
|
|
280
283
|
|
|
281
284
|
// Extract and apply the patch based on method
|
package/src/types.ts
CHANGED
|
@@ -28,6 +28,8 @@ export interface ExecutionContext {
|
|
|
28
28
|
defaultAgent: string
|
|
29
29
|
/** Timeout in seconds for agent calls. */
|
|
30
30
|
timeoutSec: number
|
|
31
|
+
/** Working directory for opencode (where .opencode/agents/ lives). */
|
|
32
|
+
workdir?: string
|
|
31
33
|
}
|
|
32
34
|
|
|
33
35
|
// ============================================================================
|
|
@@ -240,6 +242,8 @@ export interface PipelineConfig {
|
|
|
240
242
|
retry?: RetryConfig
|
|
241
243
|
/** Default timeout in seconds. */
|
|
242
244
|
timeoutSec?: number
|
|
245
|
+
/** Working directory for opencode (where .opencode/agents/ lives). */
|
|
246
|
+
workdir?: string
|
|
243
247
|
}
|
|
244
248
|
|
|
245
249
|
/** Options for running a pipeline step. */
|
|
@@ -270,6 +274,8 @@ export interface RunAgentOptions {
|
|
|
270
274
|
sessionId?: string
|
|
271
275
|
/** Timeout in seconds. */
|
|
272
276
|
timeoutSec?: number
|
|
277
|
+
/** Working directory for opencode (where .opencode/agents/ lives). */
|
|
278
|
+
workdir?: string
|
|
273
279
|
}
|
|
274
280
|
|
|
275
281
|
/** Result from running an OpenCode agent. */
|