ocpipe 0.6.4 → 0.6.5
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/codex.ts +63 -4
- package/src/types.ts +2 -0
package/package.json
CHANGED
package/src/codex.ts
CHANGED
|
@@ -10,6 +10,45 @@ import { join } from 'path'
|
|
|
10
10
|
import { PROJECT_ROOT, TMP_DIR } from './paths.js'
|
|
11
11
|
import type { RunAgentOptions, RunAgentResult } from './types.js'
|
|
12
12
|
|
|
13
|
+
class CodexLogFilter {
|
|
14
|
+
private buf = ''
|
|
15
|
+
|
|
16
|
+
write(text: string): string {
|
|
17
|
+
this.buf += text
|
|
18
|
+
let out = ''
|
|
19
|
+
for (;;) {
|
|
20
|
+
const idx = this.buf.indexOf('\n')
|
|
21
|
+
if (idx < 0) {
|
|
22
|
+
return out
|
|
23
|
+
}
|
|
24
|
+
const line = this.buf.slice(0, idx + 1)
|
|
25
|
+
this.buf = this.buf.slice(idx + 1)
|
|
26
|
+
if (suppressCodexLogLine(line)) {
|
|
27
|
+
continue
|
|
28
|
+
}
|
|
29
|
+
out += line
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
flush(): string {
|
|
34
|
+
const line = this.buf
|
|
35
|
+
this.buf = ''
|
|
36
|
+
if (suppressCodexLogLine(line)) {
|
|
37
|
+
return ''
|
|
38
|
+
}
|
|
39
|
+
return line
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function filterCodexLogText(text: string): string {
|
|
44
|
+
const filter = new CodexLogFilter()
|
|
45
|
+
return filter.write(text) + filter.flush()
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function suppressCodexLogLine(line: string): boolean {
|
|
49
|
+
return /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d+Z\s+WARN\s+codex_/.test(line)
|
|
50
|
+
}
|
|
51
|
+
|
|
13
52
|
/** runCodexAgent executes a Codex agent with a prompt. */
|
|
14
53
|
export async function runCodexAgent(
|
|
15
54
|
options: RunAgentOptions,
|
|
@@ -60,6 +99,9 @@ export async function runCodexAgent(
|
|
|
60
99
|
if (codex?.ignoreRules) {
|
|
61
100
|
args.push('--ignore-rules')
|
|
62
101
|
}
|
|
102
|
+
if (codex?.reasoningEffort) {
|
|
103
|
+
args.push('-c', `model_reasoning_effort="${codex.reasoningEffort}"`)
|
|
104
|
+
}
|
|
63
105
|
for (const dir of codex?.addDirs ?? []) {
|
|
64
106
|
args.push('--add-dir', dir)
|
|
65
107
|
}
|
|
@@ -80,6 +122,8 @@ export async function runCodexAgent(
|
|
|
80
122
|
})
|
|
81
123
|
|
|
82
124
|
const stderrChunks: string[] = []
|
|
125
|
+
const stdoutFilter = new CodexLogFilter()
|
|
126
|
+
const stderrFilter = new CodexLogFilter()
|
|
83
127
|
let aborted = false
|
|
84
128
|
|
|
85
129
|
const cleanup = async () => {
|
|
@@ -100,12 +144,17 @@ export async function runCodexAgent(
|
|
|
100
144
|
signal?.addEventListener('abort', abortHandler, { once: true })
|
|
101
145
|
|
|
102
146
|
proc.stdout.on('data', (data: Buffer) => {
|
|
103
|
-
|
|
147
|
+
const text = stdoutFilter.write(data.toString())
|
|
148
|
+
if (text) {
|
|
149
|
+
process.stderr.write(text)
|
|
150
|
+
}
|
|
104
151
|
})
|
|
105
152
|
proc.stderr.on('data', (data: Buffer) => {
|
|
106
|
-
const text = data.toString()
|
|
153
|
+
const text = stderrFilter.write(data.toString())
|
|
107
154
|
stderrChunks.push(text)
|
|
108
|
-
|
|
155
|
+
if (text) {
|
|
156
|
+
process.stderr.write(text)
|
|
157
|
+
}
|
|
109
158
|
})
|
|
110
159
|
|
|
111
160
|
const timeout =
|
|
@@ -124,10 +173,20 @@ export async function runCodexAgent(
|
|
|
124
173
|
signal?.removeEventListener('abort', abortHandler)
|
|
125
174
|
if (aborted) return
|
|
126
175
|
|
|
176
|
+
const stdoutTail = stdoutFilter.flush()
|
|
177
|
+
if (stdoutTail) {
|
|
178
|
+
process.stderr.write(stdoutTail)
|
|
179
|
+
}
|
|
180
|
+
const stderrTail = stderrFilter.flush()
|
|
181
|
+
if (stderrTail) {
|
|
182
|
+
stderrChunks.push(stderrTail)
|
|
183
|
+
process.stderr.write(stderrTail)
|
|
184
|
+
}
|
|
127
185
|
const stderr = stderrChunks.join('').trim()
|
|
128
186
|
if (code !== 0) {
|
|
129
187
|
await cleanup()
|
|
130
|
-
const detail =
|
|
188
|
+
const detail =
|
|
189
|
+
stderr ? `\n${stderr.split('\n').slice(-10).join('\n')}` : ''
|
|
131
190
|
reject(new Error(`Codex exited with code ${code}${detail}`))
|
|
132
191
|
return
|
|
133
192
|
}
|
package/src/types.ts
CHANGED
|
@@ -65,6 +65,8 @@ export interface CodexOptions {
|
|
|
65
65
|
sandbox?: 'read-only' | 'workspace-write' | 'danger-full-access'
|
|
66
66
|
/** Extra config overrides passed as repeated `-c key=value` flags. */
|
|
67
67
|
config?: Record<string, string>
|
|
68
|
+
/** Reasoning effort passed to Codex (for example: `low`, `medium`, `high`, `xhigh`). */
|
|
69
|
+
reasoningEffort?: string
|
|
68
70
|
/** Run without persisting Codex session files (default: true). */
|
|
69
71
|
ephemeral?: boolean
|
|
70
72
|
/** Ignore user config for deterministic automation (default: false). */
|