@cogitator-ai/bridge 0.2.0 → 0.3.0
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/README.md +156 -8
- package/dist/adapter.d.ts +123 -0
- package/dist/adapter.d.ts.map +1 -0
- package/dist/adapter.js +2 -0
- package/dist/adapter.js.map +1 -0
- package/dist/adapters/claude.d.ts +90 -0
- package/dist/adapters/claude.d.ts.map +1 -0
- package/dist/adapters/claude.js +359 -0
- package/dist/adapters/claude.js.map +1 -0
- package/dist/adapters/codex.d.ts +58 -0
- package/dist/adapters/codex.d.ts.map +1 -0
- package/dist/adapters/codex.js +330 -0
- package/dist/adapters/codex.js.map +1 -0
- package/dist/adapters/exec.d.ts +57 -0
- package/dist/adapters/exec.d.ts.map +1 -0
- package/dist/adapters/exec.js +149 -0
- package/dist/adapters/exec.js.map +1 -0
- package/dist/adapters/hosted.d.ts +168 -0
- package/dist/adapters/hosted.d.ts.map +1 -0
- package/dist/adapters/hosted.js +361 -0
- package/dist/adapters/hosted.js.map +1 -0
- package/dist/client.d.ts +9 -2
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +17 -3
- package/dist/client.js.map +1 -1
- package/dist/dispatcher.d.ts +67 -17
- package/dist/dispatcher.d.ts.map +1 -1
- package/dist/dispatcher.js +240 -17
- package/dist/dispatcher.js.map +1 -1
- package/dist/host.d.ts +1 -1
- package/dist/host.d.ts.map +1 -1
- package/dist/index.d.ts +13 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -1
- package/dist/inputs.d.ts +40 -1
- package/dist/inputs.d.ts.map +1 -1
- package/dist/inputs.js +25 -2
- package/dist/inputs.js.map +1 -1
- package/dist/paths.d.ts +6 -0
- package/dist/paths.d.ts.map +1 -1
- package/dist/paths.js +19 -0
- package/dist/paths.js.map +1 -1
- package/dist/protocol.d.ts +5 -0
- package/dist/protocol.d.ts.map +1 -1
- package/dist/protocol.js +5 -0
- package/dist/protocol.js.map +1 -1
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +6 -1
- package/dist/server.js.map +1 -1
- package/dist/testing/conformance.d.ts +65 -0
- package/dist/testing/conformance.d.ts.map +1 -0
- package/dist/testing/conformance.js +217 -0
- package/dist/testing/conformance.js.map +1 -0
- package/dist/testing/fake-harnesses.d.ts +101 -0
- package/dist/testing/fake-harnesses.d.ts.map +1 -0
- package/dist/testing/fake-harnesses.js +291 -0
- package/dist/testing/fake-harnesses.js.map +1 -0
- package/dist/testing/index.d.ts +5 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +3 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/types.d.ts +3 -39
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -1
- package/dist/waiter.d.ts +36 -0
- package/dist/waiter.d.ts.map +1 -0
- package/dist/waiter.js +92 -0
- package/dist/waiter.js.map +1 -0
- package/fakes/claude.mjs +450 -0
- package/fakes/codex.mjs +391 -0
- package/fakes/lib.mjs +507 -0
- package/package.json +7 -1
package/fakes/codex.mjs
ADDED
|
@@ -0,0 +1,391 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* A stand-in for the Codex command line as far as the bridge adapters use it: `exec` with JSON
|
|
4
|
+
* events, `queue`, the app-server daemon and `delete`. The commands `__open` and `__app` exist
|
|
5
|
+
* only here and play the desktop app with its threads. The behaviour was measured on codex-cli
|
|
6
|
+
* 0.167.0-alpha.4.1.
|
|
7
|
+
*/
|
|
8
|
+
import { randomUUID } from 'node:crypto';
|
|
9
|
+
import { rmSync, statSync } from 'node:fs';
|
|
10
|
+
import { join } from 'node:path';
|
|
11
|
+
import { text } from 'node:stream/consumers';
|
|
12
|
+
import { fileURLToPath } from 'node:url';
|
|
13
|
+
import {
|
|
14
|
+
CliError,
|
|
15
|
+
POLL_MS,
|
|
16
|
+
Unsupported,
|
|
17
|
+
abandonWork,
|
|
18
|
+
awaitJson,
|
|
19
|
+
boundLife,
|
|
20
|
+
canonical,
|
|
21
|
+
enqueue,
|
|
22
|
+
flag,
|
|
23
|
+
isAlive,
|
|
24
|
+
isStateName,
|
|
25
|
+
listRecords,
|
|
26
|
+
listedIn,
|
|
27
|
+
lock,
|
|
28
|
+
onStopSignal,
|
|
29
|
+
option,
|
|
30
|
+
parseArgs,
|
|
31
|
+
pending,
|
|
32
|
+
performTurn,
|
|
33
|
+
print,
|
|
34
|
+
readJson,
|
|
35
|
+
recordTurn,
|
|
36
|
+
renderHelp,
|
|
37
|
+
runCli,
|
|
38
|
+
sleep,
|
|
39
|
+
spawnDetached,
|
|
40
|
+
stateRoot,
|
|
41
|
+
takeNext,
|
|
42
|
+
terminate,
|
|
43
|
+
tryLock,
|
|
44
|
+
unlock,
|
|
45
|
+
writeJson,
|
|
46
|
+
} from './lib.mjs';
|
|
47
|
+
|
|
48
|
+
const SELF = fileURLToPath(import.meta.url);
|
|
49
|
+
const VERSION = '0.167.0-alpha.4.1';
|
|
50
|
+
const OWNER_KINDS = ['daemon', 'app'];
|
|
51
|
+
const THREAD_OWNERS = ['app', 'none'];
|
|
52
|
+
const TURN_STARTED = { type: 'turn.started' };
|
|
53
|
+
const TURN_COMPLETED = {
|
|
54
|
+
type: 'turn.completed',
|
|
55
|
+
usage: { input_tokens: 1, cached_input_tokens: 0, output_tokens: 1 },
|
|
56
|
+
};
|
|
57
|
+
const EXIT_ON_STOP_SIGNAL = 143;
|
|
58
|
+
|
|
59
|
+
const HELP_FLAGS = { '--help': flag('help'), '-h': flag('help') };
|
|
60
|
+
const FOLDER_FLAGS = { '-C': option('cd'), '--cd': option('cd') };
|
|
61
|
+
const EXEC_FLAGS = {
|
|
62
|
+
...HELP_FLAGS,
|
|
63
|
+
...FOLDER_FLAGS,
|
|
64
|
+
'--json': flag('json'),
|
|
65
|
+
'-s': option('sandbox'),
|
|
66
|
+
'--sandbox': option('sandbox'),
|
|
67
|
+
'--skip-git-repo-check': flag('skipGitRepoCheck'),
|
|
68
|
+
'-m': option('model'),
|
|
69
|
+
'--model': option('model'),
|
|
70
|
+
'-c': option('config'),
|
|
71
|
+
'--config': option('config'),
|
|
72
|
+
};
|
|
73
|
+
const QUEUE_FLAGS = {
|
|
74
|
+
...HELP_FLAGS,
|
|
75
|
+
...FOLDER_FLAGS,
|
|
76
|
+
'--thread': option('thread'),
|
|
77
|
+
'--message': option('message'),
|
|
78
|
+
'--resume': flag('resume'),
|
|
79
|
+
};
|
|
80
|
+
const OPEN_FLAGS = { ...FOLDER_FLAGS, '--owner': option('owner') };
|
|
81
|
+
const DELETE_FLAGS = { '--force': flag('force') };
|
|
82
|
+
|
|
83
|
+
const HELP = [
|
|
84
|
+
'Codex CLI',
|
|
85
|
+
'',
|
|
86
|
+
'Usage: codex [OPTIONS] [PROMPT]',
|
|
87
|
+
' codex [OPTIONS] <COMMAND> [ARGS]',
|
|
88
|
+
'',
|
|
89
|
+
'Commands:',
|
|
90
|
+
' exec Run Codex non-interactively',
|
|
91
|
+
['queue', ' queue Queue a message for a thread'],
|
|
92
|
+
' app-server Run the app server or its daemon',
|
|
93
|
+
' delete Delete a thread',
|
|
94
|
+
'',
|
|
95
|
+
'Options:',
|
|
96
|
+
' -h, --help Print help',
|
|
97
|
+
' -V, --version Print version',
|
|
98
|
+
];
|
|
99
|
+
|
|
100
|
+
const EXEC_HELP = [
|
|
101
|
+
'Run Codex non-interactively',
|
|
102
|
+
'',
|
|
103
|
+
'Usage: codex exec [OPTIONS] [PROMPT]',
|
|
104
|
+
' codex exec resume <THREAD> [PROMPT]',
|
|
105
|
+
'',
|
|
106
|
+
'Options:',
|
|
107
|
+
['exec-json', ' --json Print events to stdout as JSONL'],
|
|
108
|
+
' -C, --cd <DIR> The folder the agent works in',
|
|
109
|
+
' -s, --sandbox <SANDBOX_MODE> The sandbox policy for the commands the model runs',
|
|
110
|
+
' --skip-git-repo-check Allow running outside a Git repository',
|
|
111
|
+
' -m, --model <MODEL> The model the agent uses',
|
|
112
|
+
' -c, --config <key=value> Override a configuration value',
|
|
113
|
+
' -h, --help Print help',
|
|
114
|
+
];
|
|
115
|
+
|
|
116
|
+
const QUEUE_HELP = [
|
|
117
|
+
'Queue a message for a thread',
|
|
118
|
+
'',
|
|
119
|
+
'Usage: codex queue [OPTIONS] --thread <THREAD> --message <TEXT>',
|
|
120
|
+
'',
|
|
121
|
+
'Options:',
|
|
122
|
+
' --thread <THREAD> The thread that gets the message',
|
|
123
|
+
' --message <TEXT> The text of the message',
|
|
124
|
+
' --resume After queueing, try to resume the thread on the local daemon',
|
|
125
|
+
' -C, --cd <DIR> The folder to look the thread up from',
|
|
126
|
+
' -h, --help Print help',
|
|
127
|
+
];
|
|
128
|
+
|
|
129
|
+
const missing = () => listedIn('FAKE_CODEX_MISSING');
|
|
130
|
+
const version = () => process.env.FAKE_CODEX_VERSION || VERSION;
|
|
131
|
+
const threadsDir = () => join(stateRoot('codex'), 'threads');
|
|
132
|
+
const ownerFile = (kind) => join(stateRoot('codex'), `${kind}.json`);
|
|
133
|
+
|
|
134
|
+
function threadFiles(threadId) {
|
|
135
|
+
const base = join(threadsDir(), threadId);
|
|
136
|
+
return {
|
|
137
|
+
record: `${base}.json`,
|
|
138
|
+
transcript: `${base}.jsonl`,
|
|
139
|
+
queue: `${base}.queue`,
|
|
140
|
+
lock: `${base}.lock`,
|
|
141
|
+
running: `${base}.pid`,
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
async function main(argv) {
|
|
146
|
+
const [command, ...rest] = argv;
|
|
147
|
+
switch (command) {
|
|
148
|
+
case '--version':
|
|
149
|
+
case '-V':
|
|
150
|
+
return print(`codex-cli ${version()}`);
|
|
151
|
+
case '--help':
|
|
152
|
+
case '-h':
|
|
153
|
+
return print(renderHelp(HELP, missing()));
|
|
154
|
+
case 'exec':
|
|
155
|
+
return exec(rest);
|
|
156
|
+
case 'queue':
|
|
157
|
+
return queue(rest);
|
|
158
|
+
case 'app-server':
|
|
159
|
+
return appServer(rest);
|
|
160
|
+
case 'delete':
|
|
161
|
+
return remove(rest);
|
|
162
|
+
case '__open':
|
|
163
|
+
return open(rest);
|
|
164
|
+
case '__app':
|
|
165
|
+
return ownerCommand('app', rest);
|
|
166
|
+
case '__owner':
|
|
167
|
+
return serve(rest);
|
|
168
|
+
default:
|
|
169
|
+
throw new Unsupported();
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
async function exec(argv) {
|
|
174
|
+
const { values, positionals } = parseArgs(argv, EXEC_FLAGS);
|
|
175
|
+
if (values.help) return print(renderHelp(EXEC_HELP, missing()));
|
|
176
|
+
if (values.json && missing().has('exec-json')) {
|
|
177
|
+
throw new CliError("error: unexpected argument '--json' found", 2);
|
|
178
|
+
}
|
|
179
|
+
if (process.env.FAKE_CODEX_EXEC_FAIL) throw new CliError(process.env.FAKE_CODEX_EXEC_FAIL);
|
|
180
|
+
const { resumed, promptArgument } = execTarget(positionals);
|
|
181
|
+
const cwd = resumed ? undefined : workFolder(values.cd);
|
|
182
|
+
const prompt = await promptText(promptArgument);
|
|
183
|
+
const thread = resumed ?? createThread({ cwd, sandbox: values.sandbox, owner: 'none' });
|
|
184
|
+
await foregroundTurn(thread, prompt, values.json === true);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/** Tells `exec <prompt>` from `exec resume <threadId> <prompt>` */
|
|
188
|
+
function execTarget(positionals) {
|
|
189
|
+
const [first, ...rest] = positionals;
|
|
190
|
+
if (first !== 'resume') {
|
|
191
|
+
if (rest.length > 0) throw new Unsupported();
|
|
192
|
+
return { promptArgument: first };
|
|
193
|
+
}
|
|
194
|
+
if (rest.length < 1 || rest.length > 2) throw new Unsupported();
|
|
195
|
+
return { resumed: findThread(rest[0]), promptArgument: rest[1] };
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
function workFolder(dir) {
|
|
199
|
+
const folder = canonical(dir ?? process.cwd());
|
|
200
|
+
if (!statSync(folder, { throwIfNoEntry: false })?.isDirectory()) {
|
|
201
|
+
throw new CliError(`Error: ${folder} is not a directory`);
|
|
202
|
+
}
|
|
203
|
+
return folder;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/** The prompt of `exec`: its argument, or stdin when the argument is `-` or absent */
|
|
207
|
+
async function promptText(argument) {
|
|
208
|
+
const piped = argument === undefined || argument === '-';
|
|
209
|
+
const prompt = piped ? (await text(process.stdin)).trimEnd() : argument;
|
|
210
|
+
if (prompt.trim() === '') throw new CliError('No prompt provided');
|
|
211
|
+
return prompt;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
function createThread({ cwd, sandbox, owner }) {
|
|
215
|
+
const thread = { threadId: randomUUID(), cwd, sandbox, owner, createdAt: Date.now() };
|
|
216
|
+
writeJson(threadFiles(thread.threadId).record, thread);
|
|
217
|
+
return thread;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
function findThread(threadId) {
|
|
221
|
+
const thread = isStateName(threadId) ? readJson(threadFiles(threadId).record) : undefined;
|
|
222
|
+
if (thread === undefined) throw new CliError(`Error: no session found for '${threadId}'`);
|
|
223
|
+
return thread;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/** Runs one turn of `exec` to its end. The first event leaves before the turn starts */
|
|
227
|
+
async function foregroundTurn(thread, prompt, asJson) {
|
|
228
|
+
const { lock: lockFile, running } = threadFiles(thread.threadId);
|
|
229
|
+
onStopSignal(() => {
|
|
230
|
+
rmSync(running, { force: true });
|
|
231
|
+
abandonWork();
|
|
232
|
+
process.exit(EXIT_ON_STOP_SIGNAL);
|
|
233
|
+
});
|
|
234
|
+
await lock(lockFile);
|
|
235
|
+
writeJson(running, { pid: process.pid });
|
|
236
|
+
try {
|
|
237
|
+
if (asJson) {
|
|
238
|
+
await printEvents({ type: 'thread.started', thread_id: thread.threadId }, TURN_STARTED);
|
|
239
|
+
}
|
|
240
|
+
if (process.env.FAKE_CODEX_TURN_FAIL) throw new CliError(process.env.FAKE_CODEX_TURN_FAIL);
|
|
241
|
+
const answer = await threadTurn(thread, prompt, 'exec');
|
|
242
|
+
if (!asJson) return await print(answer);
|
|
243
|
+
const item = { id: 'item_0', type: 'agent_message', text: answer };
|
|
244
|
+
await printEvents({ type: 'item.completed', item }, TURN_COMPLETED);
|
|
245
|
+
} finally {
|
|
246
|
+
rmSync(running, { force: true });
|
|
247
|
+
unlock(lockFile);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
async function printEvents(...events) {
|
|
252
|
+
for (const event of events) await print(JSON.stringify(event));
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/** One turn of a thread. The caller holds the lock of the thread */
|
|
256
|
+
async function threadTurn(thread, input, wokenBy) {
|
|
257
|
+
const env = {
|
|
258
|
+
...process.env,
|
|
259
|
+
CODEX_THREAD_ID: thread.threadId,
|
|
260
|
+
...(thread.sandbox !== undefined && { FAKE_CODEX_SANDBOX: thread.sandbox }),
|
|
261
|
+
};
|
|
262
|
+
const outcome = await performTurn({ input, cwd: thread.cwd, env });
|
|
263
|
+
recordTurn(threadFiles(thread.threadId).transcript, outcome, wokenBy);
|
|
264
|
+
return outcome.answer;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
async function open(argv) {
|
|
268
|
+
const { values, positionals } = parseArgs(argv, OPEN_FLAGS);
|
|
269
|
+
const owner = values.owner ?? 'app';
|
|
270
|
+
if (positionals.length > 0 || !THREAD_OWNERS.includes(owner)) throw new Unsupported();
|
|
271
|
+
const thread = createThread({ cwd: workFolder(values.cd), owner });
|
|
272
|
+
await print(thread.threadId);
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
async function queue(argv) {
|
|
276
|
+
if (missing().has('queue')) throw new CliError("error: unrecognized subcommand 'queue'", 2);
|
|
277
|
+
const { values, positionals } = parseArgs(argv, QUEUE_FLAGS);
|
|
278
|
+
if (values.help) return print(renderHelp(QUEUE_HELP, missing()));
|
|
279
|
+
const { thread: threadId, message } = values;
|
|
280
|
+
if (threadId === undefined || message === undefined || positionals.length > 0) {
|
|
281
|
+
throw new Unsupported();
|
|
282
|
+
}
|
|
283
|
+
findThread(threadId);
|
|
284
|
+
const messageId = randomUUID();
|
|
285
|
+
enqueue(threadFiles(threadId).queue, { text: message });
|
|
286
|
+
await print(`Queued message ${messageId} for thread ${threadId}.`);
|
|
287
|
+
if (values.resume && !isOwnerAlive('daemon')) {
|
|
288
|
+
process.stderr.write(
|
|
289
|
+
`Warning: message was queued, but could not resume thread ${threadId}: ` +
|
|
290
|
+
'start a local daemon or specify a server with --remote\n'
|
|
291
|
+
);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
function isOwnerAlive(kind) {
|
|
296
|
+
const pid = readJson(ownerFile(kind))?.pid;
|
|
297
|
+
return pid !== undefined && isAlive(pid);
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
|
|
301
|
+
async function appServer(argv) {
|
|
302
|
+
const [group, ...rest] = argv;
|
|
303
|
+
if (group !== 'daemon') throw new Unsupported();
|
|
304
|
+
if (rest.length === 1 && rest[0] === 'version') return daemonVersion();
|
|
305
|
+
return ownerCommand('daemon', rest);
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
async function daemonVersion() {
|
|
309
|
+
if (!isOwnerAlive('daemon')) {
|
|
310
|
+
const socket = join(stateRoot('codex'), 'app-server-control', 'app-server-control.sock');
|
|
311
|
+
throw new CliError(`Error: failed to connect to ${socket}`);
|
|
312
|
+
}
|
|
313
|
+
await print(JSON.stringify({ cliVersion: version(), appServerVersion: version() }));
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
/** `start` or `stop` of the daemon, or of the stand-in of the desktop app */
|
|
317
|
+
async function ownerCommand(kind, argv) {
|
|
318
|
+
const [action] = argv;
|
|
319
|
+
if (argv.length !== 1 || !['start', 'stop'].includes(action)) throw new Unsupported();
|
|
320
|
+
await print(action === 'start' ? startOwner(kind) : await stopOwner(kind));
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
function startOwner(kind) {
|
|
324
|
+
if (isOwnerAlive(kind)) return 'already running';
|
|
325
|
+
writeJson(ownerFile(kind), { pid: spawnDetached(SELF, ['__owner', kind]) });
|
|
326
|
+
return 'started';
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
async function stopOwner(kind) {
|
|
330
|
+
const running = isOwnerAlive(kind);
|
|
331
|
+
if (running) await terminate(readJson(ownerFile(kind)).pid);
|
|
332
|
+
rmSync(ownerFile(kind), { force: true });
|
|
333
|
+
return running ? 'stopped' : 'not running';
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
* An owner process: runs the queued messages of the threads it serves, each message as one
|
|
338
|
+
* turn. The daemon serves every thread, the app only the threads it owns.
|
|
339
|
+
*/
|
|
340
|
+
async function serve(argv) {
|
|
341
|
+
const [kind] = argv;
|
|
342
|
+
if (argv.length !== 1 || !OWNER_KINDS.includes(kind)) throw new Unsupported();
|
|
343
|
+
if ((await awaitJson(ownerFile(kind))) === undefined) return;
|
|
344
|
+
boundLife(ownerFile(kind), () => {
|
|
345
|
+
abandonWork();
|
|
346
|
+
process.exit(0);
|
|
347
|
+
});
|
|
348
|
+
const draining = new Set();
|
|
349
|
+
for (;;) {
|
|
350
|
+
for (const thread of listRecords(threadsDir())) {
|
|
351
|
+
const { threadId, owner } = thread;
|
|
352
|
+
if ((kind === 'app' && owner !== 'app') || draining.has(threadId)) continue;
|
|
353
|
+
draining.add(threadId);
|
|
354
|
+
void drain(thread).finally(() => draining.delete(threadId));
|
|
355
|
+
}
|
|
356
|
+
await sleep(POLL_MS);
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
/**
|
|
361
|
+
* Runs what waits in the queue of a thread, in order. The lock keeps it to one turn at a time
|
|
362
|
+
* per thread when the daemon, the app and `exec resume` meet on it.
|
|
363
|
+
*/
|
|
364
|
+
async function drain(thread) {
|
|
365
|
+
const files = threadFiles(thread.threadId);
|
|
366
|
+
if (pending(files.queue).length === 0 || !tryLock(files.lock)) return;
|
|
367
|
+
try {
|
|
368
|
+
for (let message = takeNext(files.queue); message; message = takeNext(files.queue)) {
|
|
369
|
+
await threadTurn(thread, message.text, 'queue');
|
|
370
|
+
}
|
|
371
|
+
} finally {
|
|
372
|
+
unlock(files.lock);
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
async function remove(argv) {
|
|
377
|
+
const { values, positionals } = parseArgs(argv, DELETE_FLAGS);
|
|
378
|
+
const [threadId] = positionals;
|
|
379
|
+
if (positionals.length !== 1) throw new Unsupported();
|
|
380
|
+
if (!values.force) throw new CliError(`error: deleting thread ${threadId} needs --force`, 2);
|
|
381
|
+
findThread(threadId);
|
|
382
|
+
const files = threadFiles(threadId);
|
|
383
|
+
await lock(files.lock);
|
|
384
|
+
rmSync(files.record, { force: true });
|
|
385
|
+
rmSync(files.transcript, { force: true });
|
|
386
|
+
rmSync(files.queue, { recursive: true, force: true });
|
|
387
|
+
rmSync(files.running, { force: true });
|
|
388
|
+
unlock(files.lock);
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
await runCli('codex', main);
|