ocpipe 0.4.1 → 0.4.3
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 +1 -1
- package/src/agent.ts +29 -1
package/package.json
CHANGED
package/src/agent.ts
CHANGED
|
@@ -124,14 +124,35 @@ async function runOpencodeAgent(
|
|
|
124
124
|
// Clean up prompt file
|
|
125
125
|
await unlink(promptFile).catch(() => {})
|
|
126
126
|
|
|
127
|
+
const stderr = stderrChunks.join('').trim()
|
|
128
|
+
|
|
127
129
|
if (code !== 0) {
|
|
128
|
-
const stderr = stderrChunks.join('').trim()
|
|
129
130
|
const lastLines = stderr.split('\n').slice(-5).join('\n')
|
|
130
131
|
const detail = lastLines ? `\n${lastLines}` : ''
|
|
131
132
|
reject(new Error(`OpenCode exited with code ${code}${detail}`))
|
|
132
133
|
return
|
|
133
134
|
}
|
|
134
135
|
|
|
136
|
+
// Check for OpenCode errors that exit with code 0 but produce no output
|
|
137
|
+
const knownErrors = [
|
|
138
|
+
{ pattern: /ProviderModelNotFoundError/, message: 'Provider/model not found' },
|
|
139
|
+
{ pattern: /ModelNotFoundError/, message: 'Model not found' },
|
|
140
|
+
{ pattern: /ProviderNotFoundError/, message: 'Provider not found' },
|
|
141
|
+
{ pattern: /API key.*not.*found/i, message: 'API key not configured' },
|
|
142
|
+
{ pattern: /authentication.*failed/i, message: 'Authentication failed' },
|
|
143
|
+
]
|
|
144
|
+
|
|
145
|
+
for (const { pattern, message } of knownErrors) {
|
|
146
|
+
if (pattern.test(stderr)) {
|
|
147
|
+
// Extract the relevant error lines
|
|
148
|
+
const errorLines = stderr.split('\n').filter(line =>
|
|
149
|
+
pattern.test(line) || line.includes('Error') || line.includes('error:')
|
|
150
|
+
).slice(0, 5).join('\n')
|
|
151
|
+
reject(new Error(`OpenCode ${message}:\n${errorLines}`))
|
|
152
|
+
return
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
135
156
|
// Export session to get structured response
|
|
136
157
|
let response = stdoutChunks.join('').trim()
|
|
137
158
|
|
|
@@ -142,6 +163,13 @@ async function runOpencodeAgent(
|
|
|
142
163
|
}
|
|
143
164
|
}
|
|
144
165
|
|
|
166
|
+
// Check for empty response with errors in stderr (likely a silent failure)
|
|
167
|
+
if (response.length === 0 && stderr.includes('Error')) {
|
|
168
|
+
const lastLines = stderr.split('\n').slice(-10).join('\n')
|
|
169
|
+
reject(new Error(`OpenCode returned empty response with errors:\n${lastLines}`))
|
|
170
|
+
return
|
|
171
|
+
}
|
|
172
|
+
|
|
145
173
|
const sessionStr = newSessionId || 'none'
|
|
146
174
|
console.error(
|
|
147
175
|
`<<< OpenCode done (${response.length} chars) [session:${sessionStr}]`,
|